Add some janky handling of users clicking the close button several times

This commit is contained in:
Toastie 2024-12-27 17:00:24 +13:00
parent 84ad8cbca4
commit 7d70cde3b4
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4

View file

@ -15,6 +15,7 @@ public class CloseCommand
{
// TODO: Refactor this class a whole lot
private static Dictionary<ulong, string> closeReasons = new Dictionary<ulong, string>();
private static List<ulong> currentlyClosingTickets = new List<ulong>();
[RequireGuild]
[Command("close")]
@ -47,11 +48,26 @@ public class CloseCommand
public static async Task OnConfirmed(DiscordInteraction interaction)
{
if (currentlyClosingTickets.Contains(interaction.Channel.Id))
{
await interaction.CreateResponseAsync(DiscordInteractionResponseType.ChannelMessageWithSource,
new DiscordInteractionResponseBuilder().AddEmbed(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "This ticket is already closing."
}).AsEphemeral());
return;
}
try
{
currentlyClosingTickets.Add(interaction.Channel.Id);
await interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate);
// Check if ticket exists in the database
if (!Database.TryGetOpenTicket(interaction.Channel.Id, out Database.Ticket ticket))
{
currentlyClosingTickets.Remove(interaction.Channel.Id);
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
@ -67,6 +83,7 @@ public class CloseCommand
}
catch (Exception e)
{
currentlyClosingTickets.Remove(interaction.Channel.Id);
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
{
@ -99,6 +116,7 @@ public class CloseCommand
}
catch (Exception e)
{
currentlyClosingTickets.Remove(interaction.Channel.Id);
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
@ -111,6 +129,7 @@ public class CloseCommand
// Check if the chosen file path works.
if (!File.Exists(filePath))
{
currentlyClosingTickets.Remove(interaction.Channel.Id);
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
@ -199,7 +218,6 @@ public class CloseCommand
Description = "Channel will be deleted in 3 seconds..."
}));
await Task.Delay(3000);
// Delete the channel and database entry
@ -208,5 +226,17 @@ public class CloseCommand
Database.DeleteOpenTicket(ticket.id);
closeReasons.Remove(interaction.Channel.Id);
currentlyClosingTickets.Remove(interaction.Channel.Id);
}
catch (Exception e)
{
currentlyClosingTickets.Remove(interaction.Channel.Id);
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
{
Color = DiscordColor.Red,
Description = "An unexpected error occurred when trying to close ticket. Aborting..."
}));
Logger.Error("An unexpected error occurred when trying to close ticket:", e);
}
}
}