This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
OctobotStealth/Boyfriend/Commands/KickCommand.cs

49 lines
1.7 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 KickCommand : Command {
public override string[] Aliases { get; } = { "kick", "кик", "выгнать" };
2022-05-14 16:12:24 +03:00
public override int ArgsLengthRequired => 2;
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.KickMembers);
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-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);
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,
Utils.Wrap(Utils.JoinString(ref args, 1))), author.Mention);
}
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-05-14 16:12:24 +03:00
await Utils.SendDirectMessage(toKick,
string.Format(Messages.YouWereKicked, authorMention, guild.Name, Utils.Wrap(reason)));
2022-05-14 16:12:24 +03:00
await toKick.KickAsync(guildKickMessage);
}
2022-05-14 16:12:24 +03:00
}