1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 17:19:00 +03:00
Octobot/Boyfriend/Commands/UnbanCommand.cs

45 lines
1.5 KiB
C#
Raw Normal View History

using Discord;
using Discord.Commands;
2022-05-14 16:12:24 +03:00
using Discord.WebSocket;
namespace Boyfriend.Commands;
public class UnbanCommand : Command {
public override string[] Aliases { get; } = { "unban", "разбан" };
2022-05-14 16:12:24 +03:00
public override int ArgsLengthRequired => 2;
2022-05-14 16:12:24 +03:00
public override async Task Run(SocketCommandContext context, string[] args) {
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-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-05-14 16:12:24 +03:00
var requestOptions = Utils.GetRequestOptions($"({author}) {reason}");
await guild.RemoveBanAsync(toUnban, requestOptions);
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);
}
}