Skip to content

Commit 313490b

Browse files
committed
Add new confirmation before resetting the guild
1 parent 94bddfa commit 313490b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
### Improvements
1616
- Server info embed for admins was slightly improved and fixed
17+
- `config reset-settings` now shows a confirmation message before resetting the settings
1718

1819
## 2.1.1 - 2024-11-23
1920
### Improvements

src/AzzyBot.Bot/Commands/ConfigCommands.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
using DSharpPlus.Commands.Processors.SlashCommands;
2626
using DSharpPlus.Commands.Processors.SlashCommands.ArgumentModifiers;
2727
using DSharpPlus.Entities;
28+
using DSharpPlus.EventArgs;
29+
using DSharpPlus.Interactivity;
30+
using DSharpPlus.Interactivity.Extensions;
2831
using Microsoft.Extensions.Logging;
2932

3033
namespace AzzyBot.Bot.Commands;
@@ -632,6 +635,19 @@ public async ValueTask ResetSettingsAsync(SlashCommandContext context)
632635

633636
await context.DeferResponseAsync();
634637

638+
DiscordButtonComponent button = new(DiscordButtonStyle.Danger, $"reset_settings_{context.User.Id}_{DateTimeOffset.Now:yyyy-MM-dd_HH-mm-ss-fffffff}", "Confirm reset.");
639+
await using DiscordMessageBuilder messageBuilder = new();
640+
messageBuilder.AddComponents(button);
641+
messageBuilder.WithContent("Are you sure you want to reset all of your settings?");
642+
643+
DiscordMessage message = await context.EditResponseAsync(messageBuilder);
644+
InteractivityResult<ComponentInteractionCreatedEventArgs> result = await message.WaitForButtonAsync(context.User, TimeSpan.FromMinutes(1));
645+
if (result.TimedOut)
646+
{
647+
await context.EditResponseAsync("You haven't confirmed the reset within the timespan. Settings remain unchanged.");
648+
return;
649+
}
650+
635651
await _dbActions.DeleteGuildAsync(context.Guild.Id);
636652
await _dbActions.AddGuildAsync(context.Guild.Id);
637653

0 commit comments

Comments
 (0)