From 7c3b4b9af9901a3932820e78e5d81135030f8d11 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 2 Nov 2019 22:46:51 +0100 Subject: [PATCH] Add command to delete all switches --- PluralKit.Bot/Commands/SwitchCommands.cs | 11 +++++++++++ PluralKit.Core/Stores.cs | 11 +++++++++++ docs/1-user-guide.md | 2 ++ docs/2-command-list.md | 1 + 4 files changed, 25 insertions(+) diff --git a/PluralKit.Bot/Commands/SwitchCommands.cs b/PluralKit.Bot/Commands/SwitchCommands.cs index 49c5b4bf..5bb91ea5 100644 --- a/PluralKit.Bot/Commands/SwitchCommands.cs +++ b/PluralKit.Bot/Commands/SwitchCommands.cs @@ -119,6 +119,17 @@ namespace PluralKit.Bot.Commands public async Task SwitchDelete(Context ctx) { ctx.CheckSystem(); + + if (ctx.Match("all", "clear")) + { + // Subcommand: "delete all" + var purgeMsg = await ctx.Reply($"{Emojis.Warn} This will delete *all registered switches* in your system. Are you sure you want to proceed?"); + if (!await ctx.PromptYesNo(purgeMsg)) + throw Errors.GenericCancelled(); + await _data.DeleteAllSwitches(ctx.System); + await ctx.Reply($"{Emojis.Success} Cleared system switches!"); + return; + } // Fetch the last two switches for the system to do bounds checking on var lastTwoSwitches = (await _data.GetSwitches(ctx.System, 2)).ToArray(); diff --git a/PluralKit.Core/Stores.cs b/PluralKit.Core/Stores.cs index 320a8730..ebfa79c8 100644 --- a/PluralKit.Core/Stores.cs +++ b/PluralKit.Core/Stores.cs @@ -303,6 +303,11 @@ namespace PluralKit { /// Task DeleteSwitch(PKSwitch sw); + /// + /// Deletes all switches in a given system from the data store. + /// + Task DeleteAllSwitches(PKSystem system); + /// /// Gets the total amount of systems in the data store. /// @@ -416,6 +421,12 @@ namespace PluralKit { return await conn.QueryAsync("select uid from accounts where system = @Id", new { Id = system.Id }); } + public async Task DeleteAllSwitches(PKSystem system) + { + using (var conn = await _conn.Obtain()) + await conn.ExecuteAsync("delete from switches where system = @Id", system); + } + public async Task GetTotalSystems() { using (var conn = await _conn.Obtain()) diff --git a/docs/1-user-guide.md b/docs/1-user-guide.md index 47950f30..02109466 100644 --- a/docs/1-user-guide.md +++ b/docs/1-user-guide.md @@ -334,6 +334,8 @@ Note that you can't move a switch *before* the *previous switch*, to avoid break If you'd like to delete the most recent switch, use the `pk;switch delete` command. You'll need to confirm the deletion by clicking a reaction. +If you'd like to clear your system's entire switch history, use the `pk;switch delete all` command. This isn't reversible! + ### Querying fronter To see the current fronter in a system, use the `pk;system fronter` command. You can use this on your current system, or on other systems. For example: diff --git a/docs/2-command-list.md b/docs/2-command-list.md index a7f46175..8f03ada2 100644 --- a/docs/2-command-list.md +++ b/docs/2-command-list.md @@ -44,6 +44,7 @@ Words in \ are *required parameters*. Words in [square brackets] - `pk;switch [member...]` - Registers a switch with the given members. - `pk;switch move