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 KickCommand : Command {
|
2022-06-06 18:39:47 +03:00
|
|
|
|
public override string[] Aliases { get; } = { "kick", "кик", "выгнать" };
|
2022-05-14 16:12:24 +03:00
|
|
|
|
public override int ArgsLengthRequired => 2;
|
|
|
|
|
|
2022-01-18 20:38:15 +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.KickMembers);
|
2022-07-15 19:23:45 +03:00
|
|
|
|
if (permissionCheckResponse is not "") {
|
2022-05-14 16:12:24 +03:00
|
|
|
|
Error(permissionCheckResponse, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var toKick = Utils.ParseMember(context.Guild, args[0]);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
if (toKick == null) {
|
|
|
|
|
Error(Messages.UserNotInGuild, false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
var interactionCheckResponse = CommandHandler.CanInteract(ref author, ref toKick);
|
2022-07-15 19:23:45 +03:00
|
|
|
|
if (interactionCheckResponse is not "") {
|
2022-05-14 16:12:24 +03:00
|
|
|
|
Error(interactionCheckResponse, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
await KickMember(context.Guild, author, toKick, Utils.JoinString(ref args, 1));
|
2022-02-02 16:14:26 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
Success(
|
|
|
|
|
string.Format(Messages.FeedbackMemberKicked, toKick.Mention,
|
2022-06-06 18:39:47 +03:00
|
|
|
|
Utils.Wrap(Utils.JoinString(ref args, 1))), author.Mention);
|
2022-01-18 20:38:15 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
private static async Task KickMember(IGuild guild, SocketUser author, SocketGuildUser toKick, string reason) {
|
|
|
|
|
var authorMention = author.Mention;
|
|
|
|
|
var guildKickMessage = $"({author}) {reason}";
|
2022-01-18 20:38:15 +03:00
|
|
|
|
|
2022-05-14 16:12:24 +03:00
|
|
|
|
await Utils.SendDirectMessage(toKick,
|
2022-06-06 18:39:47 +03:00
|
|
|
|
string.Format(Messages.YouWereKicked, authorMention, 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-01-18 20:38:15 +03:00
|
|
|
|
}
|
2022-05-14 16:12:24 +03:00
|
|
|
|
}
|