2022-01-18 20:38:15 +03:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
|
|
|
|
|
// ReSharper disable UnusedType.Global
|
|
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
// ReSharper disable ClassNeverInstantiated.Global
|
|
|
|
|
|
|
|
|
|
namespace Boyfriend.Commands;
|
|
|
|
|
|
|
|
|
|
public class UnbanCommand : Command {
|
|
|
|
|
public override async Task Run(SocketCommandContext context, string[] args) {
|
2022-02-02 16:14:26 +03:00
|
|
|
|
await UnbanUser(context.Guild, context.Channel as ITextChannel, context.Guild.GetUser(context.User.Id),
|
|
|
|
|
await Utils.ParseUser(args[0]), Utils.JoinString(args, 1));
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 16:14:26 +03:00
|
|
|
|
public static async Task UnbanUser(IGuild guild, ITextChannel? channel, IGuildUser author, IUser toUnban,
|
2022-01-18 20:38:15 +03:00
|
|
|
|
string reason) {
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-01-18 20:38:15 +03:00
|
|
|
|
var authorMention = author.Mention;
|
|
|
|
|
var notification = string.Format(Messages.UserUnbanned, authorMention, toUnban.Mention,
|
|
|
|
|
Utils.WrapInline(reason));
|
2022-02-02 16:14:26 +03:00
|
|
|
|
var requestOptions = Utils.GetRequestOptions($"({Utils.GetNameAndDiscrim(author)}) {reason}");
|
|
|
|
|
|
|
|
|
|
await CommandHandler.CheckPermissions(author, GuildPermission.BanMembers);
|
|
|
|
|
|
|
|
|
|
if (guild.GetBanAsync(toUnban.Id) == null)
|
|
|
|
|
throw new ApplicationException(Messages.UserNotBanned);
|
|
|
|
|
|
|
|
|
|
await guild.RemoveBanAsync(toUnban, requestOptions);
|
|
|
|
|
|
2022-01-18 20:38:15 +03:00
|
|
|
|
await Utils.SilentSendAsync(channel, string.Format(Messages.UnbanResponse, toUnban.Mention,
|
|
|
|
|
Utils.WrapInline(reason)));
|
|
|
|
|
await Utils.SilentSendAsync(await guild.GetSystemChannelAsync(), notification);
|
|
|
|
|
await Utils.SilentSendAsync(await Utils.GetAdminLogChannel(guild), notification);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override List<string> GetAliases() {
|
|
|
|
|
return new List<string> {"unban", "разбан"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetArgumentsAmountRequired() {
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetSummary() {
|
|
|
|
|
return "Возвращает пользователя из бана";
|
|
|
|
|
}
|
2022-01-30 11:43:15 +03:00
|
|
|
|
}
|