1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-05 13:36:30 +03:00

another two or three refactors

This commit is contained in:
l1ttleO 2022-05-14 18:12:24 +05:00
parent 868b6bcaa7
commit 790f77aa49
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
21 changed files with 1447 additions and 944 deletions

View file

@ -1,50 +1,49 @@
using Discord;
using Discord.Commands;
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable ClassNeverInstantiated.Global
using Discord.WebSocket;
namespace Boyfriend.Commands;
public class KickCommand : Command {
public override string[] Aliases { get; } = {"kick", "кик", "выгнать"};
public override int ArgsLengthRequired => 2;
public override async Task Run(SocketCommandContext context, string[] args) {
var author = context.Guild.GetUser(context.User.Id);
var toKick = await Utils.ParseMember(context.Guild, args[0]);
var author = (SocketGuildUser) context.User;
await CommandHandler.CheckPermissions(author, GuildPermission.KickMembers);
await CommandHandler.CheckInteractions(author, toKick);
var permissionCheckResponse = CommandHandler.HasPermission(ref author, GuildPermission.KickMembers);
if (permissionCheckResponse != "") {
Error(permissionCheckResponse, true);
return;
}
await KickMember(context.Guild, context.Channel as ITextChannel, author, toKick, Utils.JoinString(args, 1));
var toKick = Utils.ParseMember(context.Guild, args[0]);
if (toKick == null) {
Error(Messages.UserNotInGuild, false);
return;
}
var interactionCheckResponse = CommandHandler.CanInteract(ref author, ref toKick);
if (interactionCheckResponse != "") {
Error(interactionCheckResponse, true);
return;
}
await KickMember(context.Guild, author, toKick, Utils.JoinString(ref args, 1));
Success(
string.Format(Messages.FeedbackMemberKicked, toKick.Mention,
Utils.WrapInline(Utils.JoinString(ref args, 1))), author.Mention);
}
private static async Task KickMember(IGuild guild, ITextChannel? channel, IUser author, IGuildUser toKick,
string reason) {
private static async Task KickMember(IGuild guild, SocketUser author, SocketGuildUser toKick, string reason) {
var authorMention = author.Mention;
var guildKickMessage = $"({Utils.GetNameAndDiscrim(author)}) {reason}";
var notification = string.Format(Messages.MemberKicked, authorMention, toKick.Mention,
Utils.WrapInline(reason));
var guildKickMessage = $"({author}) {reason}";
await Utils.SendDirectMessage(toKick, string.Format(Messages.YouWereKicked, authorMention, guild.Name,
Utils.WrapInline(reason)));
await Utils.SendDirectMessage(toKick,
string.Format(Messages.YouWereKicked, authorMention, guild.Name, Utils.WrapInline(reason)));
await toKick.KickAsync(guildKickMessage);
await Utils.SilentSendAsync(channel, string.Format(Messages.KickResponse, toKick.Mention,
Utils.WrapInline(reason)));
await Utils.SilentSendAsync(await guild.GetSystemChannelAsync(), notification);
await Utils.SilentSendAsync(await Utils.GetAdminLogChannel(guild), notification);
}
public override List<string> GetAliases() {
return new List<string> {"kick", "кик"};
}
public override int GetArgumentsAmountRequired() {
return 2;
}
public override string GetSummary() {
return "Выгоняет участника";
}
}
}