Add some janky handling of users clicking the close button several times
This commit is contained in:
parent
84ad8cbca4
commit
7d70cde3b4
1 changed files with 169 additions and 139 deletions
|
@ -15,6 +15,7 @@ public class CloseCommand
|
||||||
{
|
{
|
||||||
// TODO: Refactor this class a whole lot
|
// TODO: Refactor this class a whole lot
|
||||||
private static Dictionary<ulong, string> closeReasons = new Dictionary<ulong, string>();
|
private static Dictionary<ulong, string> closeReasons = new Dictionary<ulong, string>();
|
||||||
|
private static List<ulong> currentlyClosingTickets = new List<ulong>();
|
||||||
|
|
||||||
[RequireGuild]
|
[RequireGuild]
|
||||||
[Command("close")]
|
[Command("close")]
|
||||||
|
@ -47,11 +48,26 @@ public class CloseCommand
|
||||||
|
|
||||||
public static async Task OnConfirmed(DiscordInteraction interaction)
|
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);
|
await interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate);
|
||||||
|
|
||||||
// Check if ticket exists in the database
|
// Check if ticket exists in the database
|
||||||
if (!Database.TryGetOpenTicket(interaction.Channel.Id, out Database.Ticket ticket))
|
if (!Database.TryGetOpenTicket(interaction.Channel.Id, out Database.Ticket ticket))
|
||||||
{
|
{
|
||||||
|
currentlyClosingTickets.Remove(interaction.Channel.Id);
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
|
@ -67,6 +83,7 @@ public class CloseCommand
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
currentlyClosingTickets.Remove(interaction.Channel.Id);
|
||||||
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
|
Logger.Error("Exception occured when trying to save transcript while closing ticket: " + e);
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
|
@ -99,6 +116,7 @@ public class CloseCommand
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
currentlyClosingTickets.Remove(interaction.Channel.Id);
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
|
@ -111,6 +129,7 @@ public class CloseCommand
|
||||||
// Check if the chosen file path works.
|
// Check if the chosen file path works.
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
|
currentlyClosingTickets.Remove(interaction.Channel.Id);
|
||||||
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder
|
||||||
{
|
{
|
||||||
Color = DiscordColor.Red,
|
Color = DiscordColor.Red,
|
||||||
|
@ -199,7 +218,6 @@ public class CloseCommand
|
||||||
Description = "Channel will be deleted in 3 seconds..."
|
Description = "Channel will be deleted in 3 seconds..."
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000);
|
||||||
|
|
||||||
// Delete the channel and database entry
|
// Delete the channel and database entry
|
||||||
|
@ -208,5 +226,17 @@ public class CloseCommand
|
||||||
Database.DeleteOpenTicket(ticket.id);
|
Database.DeleteOpenTicket(ticket.id);
|
||||||
|
|
||||||
closeReasons.Remove(interaction.Channel.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue