From 72a2fadff8d7f1a1beec284f7f02bee3eb45fce3 Mon Sep 17 00:00:00 2001 From: Ske Date: Mon, 13 May 2019 23:08:44 +0200 Subject: [PATCH] bot: add member deletion command --- PluralKit.Bot/Commands/MemberCommands.cs | 12 ++++++++++++ PluralKit.Bot/ContextUtils.cs | 6 ++++++ PluralKit.Bot/Errors.cs | 2 ++ PluralKit.Bot/Services/ProxyService.cs | 2 +- PluralKit.Core/Utils.cs | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Commands/MemberCommands.cs b/PluralKit.Bot/Commands/MemberCommands.cs index aead0f82..200b6e95 100644 --- a/PluralKit.Bot/Commands/MemberCommands.cs +++ b/PluralKit.Bot/Commands/MemberCommands.cs @@ -167,6 +167,18 @@ namespace PluralKit.Bot.Commands await Context.Channel.SendMessageAsync($"{Emojis.Success} Member proxy tags changed to `{ContextEntity.ProxyString}`. Try proxying now!"); } + [Command("delete")] + [Alias("remove", "erase", "yeet")] + [Remarks("member delete")] + [MustPassOwnMember] + public async Task MemberDelete() + { + await Context.Channel.SendMessageAsync($"{Emojis.Warn} Are you sure you want to delete \"{ContextEntity.Name}\"? If so, reply to this message with the member's ID (`{ContextEntity.Hid}`). __***This cannot be undone!***__"); + if (!await Context.ConfirmWithReply(ContextEntity.Hid)) throw Errors.MemberDeleteCancelled; + await Members.Delete(ContextEntity); + await Context.Channel.SendMessageAsync($"{Emojis.Success} Member deleted."); + } + [Command] [Alias("view", "show", "info")] [Remarks("member")] diff --git a/PluralKit.Bot/ContextUtils.cs b/PluralKit.Bot/ContextUtils.cs index 1b8fa9f5..1c34a886 100644 --- a/PluralKit.Bot/ContextUtils.cs +++ b/PluralKit.Bot/ContextUtils.cs @@ -48,6 +48,12 @@ namespace PluralKit.Bot { (ctx.Client as BaseSocketClient).MessageReceived += Inner; return await (tcs.Task.TimeoutAfter(timeout)); } + + public static async Task ConfirmWithReply(this ICommandContext ctx, string expectedReply) + { + var msg = await ctx.AwaitMessage(ctx.Channel, ctx.User, timeout: TimeSpan.FromMinutes(1)); + return string.Equals(msg.Content, expectedReply, StringComparison.InvariantCultureIgnoreCase); + } public static async Task Paginate(this ICommandContext ctx, ICollection items, int itemsPerPage, string title, Action> renderer) { var pageCount = (items.Count / itemsPerPage) + 1; diff --git a/PluralKit.Bot/Errors.cs b/PluralKit.Bot/Errors.cs index 4653fdf3..52ec1539 100644 --- a/PluralKit.Bot/Errors.cs +++ b/PluralKit.Bot/Errors.cs @@ -18,5 +18,7 @@ namespace PluralKit.Bot { public static PKError BirthdayParseError(string birthday) => new PKError($"\"{birthday}\" could not be parsed as a valid date. Try a format like \"2016-12-24\" or \"May 3 1996\"."); public static PKError ProxyMustHaveText => new PKSyntaxError("Example proxy message must contain the string 'text'."); public static PKError ProxyMultipleText => new PKSyntaxError("Example proxy message must contain the string 'text' exactly once."); + + public static PKError MemberDeleteCancelled => new PKError($"Member deletion cancelled. Stay safe! {Emojis.ThumbsUp}"); } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/ProxyService.cs b/PluralKit.Bot/Services/ProxyService.cs index d57ee524..7dee80a6 100644 --- a/PluralKit.Bot/Services/ProxyService.cs +++ b/PluralKit.Bot/Services/ProxyService.cs @@ -24,7 +24,7 @@ namespace PluralKit.Bot public PKSystem System; public string InnerText; - public string ProxyName => Member.Name + (System.Tag.Length > 0 ? " " + System.Tag : ""); + public string ProxyName => Member.Name + (System.Tag != null ? " " + System.Tag : ""); } class ProxyService { diff --git a/PluralKit.Core/Utils.cs b/PluralKit.Core/Utils.cs index 943ec7fc..61972e54 100644 --- a/PluralKit.Core/Utils.cs +++ b/PluralKit.Core/Utils.cs @@ -101,5 +101,6 @@ namespace PluralKit public static readonly string Success = "\u2705"; public static readonly string Error = "\u274C"; public static readonly string Note = "\u2757"; + public static readonly string ThumbsUp = "\U0001f44d"; } } \ No newline at end of file