From f2a02bb8a2fe413f3a4e8f2fc704d5d91a71faae Mon Sep 17 00:00:00 2001 From: Karl Essinger Date: Sun, 29 Sep 2024 17:28:12 +0200 Subject: [PATCH] Added reason to close command --- Commands/CloseCommand.cs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Commands/CloseCommand.cs b/Commands/CloseCommand.cs index b16d1b7..857ff81 100644 --- a/Commands/CloseCommand.cs +++ b/Commands/CloseCommand.cs @@ -12,9 +12,11 @@ namespace SupportBoi.Commands; public class CloseCommand : ApplicationCommandModule { + private static Dictionary closeReasons = new Dictionary(); + [SlashRequireGuild] [SlashCommand("close", "Closes a ticket.")] - public async Task OnExecute(InteractionContext command) + public async Task OnExecute(InteractionContext command, [Option("Reason", "Reason for closing the ticket.")] string reason = "") { // Check if ticket exists in the database if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket _)) @@ -35,8 +37,8 @@ await command.CreateResponseAsync(new DiscordEmbedBuilder }) .AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "supportboi_closeconfirm", "Confirm")); - await command.CreateResponseAsync(confirmation); + closeReasons.Add(command.Channel.Id, reason); } public static async Task OnConfirmed(DiscordInteraction interaction) @@ -72,6 +74,12 @@ await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed return; } + string closeReason = ""; + if (closeReasons.TryGetValue(channelID, out string cachedReason)) + { + closeReason = "\nReason: " + cachedReason + "\n"; + } + // Log it if the log channel exists DiscordChannel logChannel = interaction.Guild.GetChannel(Config.logChannel); if (logChannel != null) @@ -79,7 +87,8 @@ await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed DiscordEmbed embed = new DiscordEmbedBuilder { Color = DiscordColor.Green, - Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + interaction.User.Mention + ".\n", + Description = "Ticket " + ticket.id.ToString("00000") + " closed by " + + interaction.User.Mention + ".\n" + closeReason, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName } }; @@ -96,7 +105,8 @@ await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed DiscordEmbed embed = new DiscordEmbedBuilder { Color = DiscordColor.Green, - Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, check the transcript for more info.\n", + Description = "Ticket " + ticket.id.ToString("00000") + " which you opened has now been closed, " + + "check the transcript for more info.\n" + closeReason, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + channelName } }; @@ -124,11 +134,13 @@ await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed })); - await Task.Delay(3000); + await Task.Delay(3000); // Delete the channel and database entry await interaction.Channel.DeleteAsync("Ticket closed."); Database.DeleteOpenTicket(ticket.id); + + closeReasons.Remove(channelID); } } \ No newline at end of file