Skip to content

Commit

Permalink
Added reason to close command
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Sep 29, 2024
1 parent 52c48f1 commit f2a02bb
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Commands/CloseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ namespace SupportBoi.Commands;

public class CloseCommand : ApplicationCommandModule
{
private static Dictionary<ulong, string> closeReasons = new Dictionary<ulong, string>();

[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 _))
Expand All @@ -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)
Expand Down Expand Up @@ -72,14 +74,21 @@ 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)
{
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 }
};

Expand All @@ -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 }
};

Expand Down Expand Up @@ -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);
}
}

0 comments on commit f2a02bb

Please sign in to comment.