2022-01-18 20:38:15 +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;
|
|
|
|
|
|
|
|
|
|
public class KickCommand : Command {
|
2022-06-06 18:39:47 +03:00
|
|
|
|
public override string[] Aliases { get; } = { "kick", "кик", "выгнать" };
|
2022-05-14 16:12:24 +03:00
|
|
|
|
|
2022-08-30 18:15:01 +03:00
|
|
|
|
public override async Task Run(CommandProcessor cmd, string[] args) {
|
|
|
|
|
var toKick = cmd.GetMember(args, 0, "ToKick");
|
|
|
|
|
if (toKick == null || !cmd.HasPermission(GuildPermission.KickMembers)) return;
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-08-30 18:15:01 +03:00
|
|
|
|
if (!cmd.CanInteractWith(toKick, "Kick")) return;
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-08-30 18:15:01 +03:00
|
|
|
|
await KickMember(cmd, toKick, cmd.GetRemaining(args, 1, "KickReason"));
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-30 18:15:01 +03:00
|
|
|
|
private static async Task KickMember(CommandProcessor cmd, SocketGuildUser toKick, string? reason) {
|
|
|
|
|
if (reason == null) return;
|
|
|
|
|
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));
|
|
|
|
|
cmd.Reply(format, ":police_car: ");
|
|
|
|
|
cmd.Audit(format);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
2022-05-14 16:12:24 +03:00
|
|
|
|
}
|