Add command to delete all switches

This commit is contained in:
Ske 2019-11-02 22:46:51 +01:00
parent 1e1f2acdc3
commit 7c3b4b9af9
4 changed files with 25 additions and 0 deletions

View File

@ -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();

View File

@ -303,6 +303,11 @@ namespace PluralKit {
/// </summary>
Task DeleteSwitch(PKSwitch sw);
/// <summary>
/// Deletes all switches in a given system from the data store.
/// </summary>
Task DeleteAllSwitches(PKSystem system);
/// <summary>
/// Gets the total amount of systems in the data store.
/// </summary>
@ -416,6 +421,12 @@ namespace PluralKit {
return await conn.QueryAsync<ulong>("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<ulong> GetTotalSystems()
{
using (var conn = await _conn.Obtain())

View File

@ -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:

View File

@ -44,6 +44,7 @@ Words in \<angle brackets> are *required parameters*. Words in [square brackets]
- `pk;switch [member...]` - Registers a switch with the given members.
- `pk;switch move <time>` - Moves the latest switch backwards in time.
- `pk;switch delete` - Deletes the latest switch.
- `pk;switch delete all` - Deletes every logged switch.
- `pk;switch out` - Registers a 'switch-out' - a switch with no associated members.
## Utility
- `pk;log <channel>` - Sets the channel to log all proxied messages.