2022-01-18 20:38:15 +03:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2022-05-14 16:12:24 +03:00
|
|
|
|
using Discord.WebSocket;
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
|
|
|
|
namespace Boyfriend.Commands;
|
|
|
|
|
|
|
|
|
|
public class UnbanCommand : Command {
|
2022-06-06 18:39:47 +03:00
|
|
|
|
public override string[] Aliases { get; } = { "unban", "разбан" };
|
2022-05-14 16:12:24 +03:00
|
|
|
|
public override int ArgsLengthRequired => 2;
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
public override async Task Run(SocketCommandContext context, string[] args) {
|
2022-06-06 18:39:47 +03:00
|
|
|
|
var author = (SocketGuildUser)context.User;
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.BanMembers);
|
|
|
|
|
if (permissionCheckResponse != "") {
|
|
|
|
|
Error(permissionCheckResponse, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var toUnban = Utils.ParseUser(args[0]);
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
if (toUnban == null) {
|
|
|
|
|
Error(Messages.UserDoesntExist, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var reason = Utils.JoinString(ref args, 1);
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
await UnbanUser(context.Guild, author, toUnban, reason);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
public static async Task UnbanUser(SocketGuild guild, SocketGuildUser author, SocketUser toUnban, string reason) {
|
|
|
|
|
if (guild.GetBanAsync(toUnban.Id) == null) {
|
|
|
|
|
Error(Messages.UserNotBanned, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var requestOptions = Utils.GetRequestOptions($"({author}) {reason}");
|
|
|
|
|
await guild.RemoveBanAsync(toUnban, requestOptions);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
2022-06-06 18:39:47 +03:00
|
|
|
|
var feedback = string.Format(Messages.FeedbackUserUnbanned, toUnban.Mention, Utils.Wrap(reason));
|
2022-05-14 16:12:24 +03:00
|
|
|
|
Success(feedback, author.Mention, false, false);
|
|
|
|
|
await Utils.SendFeedback(feedback, guild.Id, author.Mention, true);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
2022-06-06 18:39:47 +03:00
|
|
|
|
}
|