2022-12-06 18:33:46 +03:00
|
|
|
using Discord;
|
2022-05-14 16:12:24 +03:00
|
|
|
using Discord.WebSocket;
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
|
|
namespace Boyfriend.Commands;
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
public sealed class KickCommand : ICommand {
|
|
|
|
public string[] Aliases { get; } = { "kick", "кик", "выгнать" };
|
2022-05-14 16:12:24 +03:00
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
public async Task RunAsync(CommandProcessor cmd, string[] args, string[] cleanArgs) {
|
|
|
|
var toKick = cmd.GetMember(args, cleanArgs, 0, "ToKick");
|
2022-11-11 22:59:11 +03:00
|
|
|
if (toKick is null || !cmd.HasPermission(GuildPermission.KickMembers)) return;
|
2022-02-02 16:14:26 +03:00
|
|
|
|
2022-11-11 22:59:11 +03:00
|
|
|
if (cmd.CanInteractWith(toKick, "Kick"))
|
|
|
|
await KickMemberAsync(cmd, toKick, cmd.GetRemaining(args, 1, "KickReason"));
|
2022-01-18 20:38:15 +03:00
|
|
|
}
|
|
|
|
|
2022-09-18 17:41:29 +03:00
|
|
|
private static async Task KickMemberAsync(CommandProcessor cmd, SocketGuildUser toKick, string? reason) {
|
2022-11-11 22:59:11 +03:00
|
|
|
if (reason is null) return;
|
2022-08-30 18:15:01 +03:00
|
|
|
var guildKickMessage = $"({cmd.Context.User}) {reason}";
|
2022-01-18 20:38:15 +03:00
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
await Utils.SendDirectMessage(toKick,
|
2022-08-30 18:15:01 +03:00
|
|
|
string.Format(Messages.YouWereKicked, cmd.Context.User.Mention, cmd.Context.Guild.Name,
|
|
|
|
Utils.Wrap(reason)));
|
2022-01-18 20:38:15 +03:00
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
await toKick.KickAsync(guildKickMessage);
|
2022-08-30 18:15:01 +03:00
|
|
|
var format = string.Format(Messages.FeedbackMemberKicked, toKick.Mention, Utils.Wrap(reason));
|
2022-12-06 18:33:46 +03:00
|
|
|
cmd.Reply(format, ReplyEmojis.Kicked);
|
2022-08-30 18:15:01 +03:00
|
|
|
cmd.Audit(format);
|
2022-01-18 20:38:15 +03:00
|
|
|
}
|
2022-09-18 17:41:29 +03:00
|
|
|
}
|