diff --git a/Breadcraft/Breadcraft.csproj b/Breadcraft/Breadcraft.csproj index 1df9a1f..1134d0c 100644 --- a/Breadcraft/Breadcraft.csproj +++ b/Breadcraft/Breadcraft.csproj @@ -27,13 +27,13 @@ - - - + + + - + diff --git a/Breadcraft/Commands/AddCategoryCommand.cs b/Breadcraft/Commands/AddCategoryCommand.cs index 71245bf..bc06582 100644 --- a/Breadcraft/Commands/AddCategoryCommand.cs +++ b/Breadcraft/Commands/AddCategoryCommand.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; @@ -20,7 +20,7 @@ public class AddCategoryCommand : ApplicationCommandModule }, true); return; } - + if (string.IsNullOrWhiteSpace(title)) { await command.CreateResponseAsync(new DiscordEmbedBuilder @@ -40,7 +40,7 @@ public class AddCategoryCommand : ApplicationCommandModule }, true); return; } - + if (Database.TryGetCategory(title, out Database.Category _)) { await command.CreateResponseAsync(new DiscordEmbedBuilder @@ -51,7 +51,7 @@ public class AddCategoryCommand : ApplicationCommandModule return; } - if(Database.AddCategory(title, category.Id)) + if (Database.AddCategory(title, category.Id)) { await command.CreateResponseAsync(new DiscordEmbedBuilder { diff --git a/Breadcraft/Commands/AddCommand.cs b/Breadcraft/Commands/AddCommand.cs index 7512e22..163285f 100644 --- a/Breadcraft/Commands/AddCommand.cs +++ b/Breadcraft/Commands/AddCommand.cs @@ -48,7 +48,7 @@ public class AddCommand : ApplicationCommandModule }, true); return; } - + try { await command.Channel.AddOverwriteAsync(member, Permissions.AccessChannels); diff --git a/Breadcraft/Commands/AddMessageCommand.cs b/Breadcraft/Commands/AddMessageCommand.cs index 3e7b393..c562123 100644 --- a/Breadcraft/Commands/AddMessageCommand.cs +++ b/Breadcraft/Commands/AddMessageCommand.cs @@ -9,8 +9,8 @@ public class AddMessageCommand : ApplicationCommandModule { [SlashRequireGuild] [SlashCommand("addmessage", "Adds a new message for the 'say' command.")] - public async Task OnExecute(InteractionContext command, - [Option("Identifier", "The identifier word used in the /say command.")] string identifier, + public async Task OnExecute(InteractionContext command, + [Option("Identifier", "The identifier word used in the /say command.")] string identifier, [Option("Message", "The message the /say command will return.")] string message) { if (string.IsNullOrEmpty(message)) @@ -33,7 +33,7 @@ public class AddMessageCommand : ApplicationCommandModule return; } - if(Database.AddMessage(identifier, command.Member.Id, message)) + if (Database.AddMessage(identifier, command.Member.Id, message)) { await command.CreateResponseAsync(new DiscordEmbedBuilder { diff --git a/Breadcraft/Commands/AddStaffCommand.cs b/Breadcraft/Commands/AddStaffCommand.cs index a586c85..8aec33d 100644 --- a/Breadcraft/Commands/AddStaffCommand.cs +++ b/Breadcraft/Commands/AddStaffCommand.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; -using MySql.Data.MySqlClient; +using MySqlConnector; namespace Breadcraft.Commands; diff --git a/Breadcraft/Commands/AdminCommands.cs b/Breadcraft/Commands/AdminCommands.cs index 87e21b0..bd37c19 100644 --- a/Breadcraft/Commands/AdminCommands.cs +++ b/Breadcraft/Commands/AdminCommands.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -28,7 +28,7 @@ public class AdminCommands : ApplicationCommandModule // Get all channels in all guilds the bot is part of List allChannels = new List(); - foreach (KeyValuePair guild in Breadcraft.discordClient.Guilds) + foreach (KeyValuePair guild in Breadcraft.discordClient.Guilds) { try { @@ -56,7 +56,7 @@ public class AdminCommands : ApplicationCommandModule }, true); return; } - + List embeds = new List(); foreach (string message in Utilities.ParseListIntoMessages(listItems)) { @@ -67,7 +67,7 @@ public class AdminCommands : ApplicationCommandModule Description = message }); } - + // Add the footers for (int i = 0; i < embeds.Count; i++) { @@ -76,7 +76,7 @@ public class AdminCommands : ApplicationCommandModule Text = $"Page {i + 1} / {embeds.Count}" }; } - + List listPages = new List(); foreach (DiscordEmbedBuilder embed in embeds) { @@ -85,7 +85,7 @@ public class AdminCommands : ApplicationCommandModule await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages); } - + [SlashRequireGuild] [SlashCommand("setticket", "Turns a channel into a ticket WARNING: Anyone will be able to delete the channel using /close.")] public async Task SetTicket(InteractionContext command, [Option("User", "(Optional) The owner of the ticket.")] DiscordUser user = null) @@ -122,7 +122,7 @@ public class AdminCommands : ApplicationCommandModule }); } } - + [SlashRequireGuild] [SlashCommand("unsetticket", "Deletes a ticket from the ticket system without deleting the channel.")] public async Task UnsetTicket(InteractionContext command, [Option("TicketID", "(Optional) Ticket to unset. Uses the channel you are in by default.")] long ticketID = 0) @@ -140,7 +140,7 @@ public class AdminCommands : ApplicationCommandModule Description = "This channel is not a ticket!" }, true); return; - } + } } else { @@ -164,7 +164,7 @@ public class AdminCommands : ApplicationCommandModule Color = DiscordColor.Green, Description = "Channel has been undesignated as a ticket." }); - + // Log it if the log channel exists DiscordChannel logChannel = command.Guild.GetChannel(Config.logChannel); if (logChannel != null) @@ -185,7 +185,7 @@ public class AdminCommands : ApplicationCommandModule }, true); } } - + [SlashCommand("reload", "Reloads the bot config.")] public async Task Reload(InteractionContext command) { diff --git a/Breadcraft/Commands/AssignCommand.cs b/Breadcraft/Commands/AssignCommand.cs index caf33d9..0d724af 100644 --- a/Breadcraft/Commands/AssignCommand.cs +++ b/Breadcraft/Commands/AssignCommand.cs @@ -37,7 +37,7 @@ public class AssignCommand : ApplicationCommandModule }, true); return; } - + // Check if ticket exists in the database if (!Database.TryGetOpenTicket(command.Channel.Id, out Database.Ticket ticket)) { @@ -85,7 +85,7 @@ public class AssignCommand : ApplicationCommandModule Description = "You have been assigned to a support ticket: " + command.Channel.Mention }); } - catch (UnauthorizedException) {} + catch (UnauthorizedException) { } } // Log it if the log channel exists diff --git a/Breadcraft/Commands/CloseCommand.cs b/Breadcraft/Commands/CloseCommand.cs index e09ca54..d36e08a 100644 --- a/Breadcraft/Commands/CloseCommand.cs +++ b/Breadcraft/Commands/CloseCommand.cs @@ -33,8 +33,8 @@ public class CloseCommand : ApplicationCommandModule Color = DiscordColor.Cyan, Description = "Are you sure you wish to close this ticket? You cannot re-open it again later." }) - .AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "breadcraft_closeconfirm", "Confirm")); - + .AddComponents(new DiscordButtonComponent(ButtonStyle.Danger, "bcsupport_closeconfirm", "Confirm")); + await command.CreateResponseAsync(confirmation); } @@ -44,7 +44,7 @@ public class CloseCommand : ApplicationCommandModule await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate); ulong channelID = interaction.Channel.Id; string channelName = interaction.Channel.Name; - + // Check if ticket exists in the database if (!Database.TryGetOpenTicket(channelID, out Database.Ticket ticket)) { @@ -55,7 +55,7 @@ public class CloseCommand : ApplicationCommandModule })); return; } - + // Build transcript try { @@ -86,7 +86,7 @@ public class CloseCommand : ApplicationCommandModule await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read); DiscordMessageBuilder message = new DiscordMessageBuilder(); message.WithEmbed(embed); - message.WithFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); + message.AddFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); await logChannel.SendMessageAsync(message); } @@ -104,17 +104,17 @@ public class CloseCommand : ApplicationCommandModule { DiscordMember staffMember = await interaction.Guild.GetMemberAsync(ticket.creatorID); await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read); - + DiscordMessageBuilder message = new DiscordMessageBuilder(); message.WithEmbed(embed); - message.WithFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); + message.AddFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); await staffMember.SendMessageAsync(message); } catch (NotFoundException) { } catch (UnauthorizedException) { } } - + Database.ArchiveTicket(ticket); await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder @@ -124,7 +124,7 @@ public class CloseCommand : ApplicationCommandModule })); - await Task.Delay(3000); + await Task.Delay(3000); // Delete the channel and database entry await interaction.Channel.DeleteAsync("Ticket closed."); diff --git a/Breadcraft/Commands/CreateButtonPanelCommand.cs b/Breadcraft/Commands/CreateButtonPanelCommand.cs index b45ae83..4d99bdc 100644 --- a/Breadcraft/Commands/CreateButtonPanelCommand.cs +++ b/Breadcraft/Commands/CreateButtonPanelCommand.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using DSharpPlus; @@ -26,21 +26,21 @@ public class CreateButtonPanelCommand : ApplicationCommandModule }, true); return; } - + verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList(); - + int nrOfButtons = 0; for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++) { List buttonRow = new List(); - + for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++) { - buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "breadcraft_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name)); + buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "bcsupport_newticketbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name)); } builder.AddComponents(buttonRow); } - + await command.Channel.SendMessageAsync(builder); await command.CreateResponseAsync(new DiscordEmbedBuilder { @@ -48,17 +48,17 @@ public class CreateButtonPanelCommand : ApplicationCommandModule Description = "Successfully created message, make sure to run this command again if you add new categories to the bot." }, true); } - + public static async Task OnButtonUsed(DiscordInteraction interaction) { await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); - - if (!ulong.TryParse(interaction.Data.CustomId.Replace("breadcraft_newticketbutton ", ""), out ulong categoryID) || categoryID == 0) + + if (!ulong.TryParse(interaction.Data.CustomId.Replace("bcsupport_newticketbutton ", ""), out ulong categoryID) || categoryID == 0) { - Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("breadcraft_newticketbutton ", "")); + Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("bcsupport_newticketbutton ", "")); return; } - + (bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID); if (success) diff --git a/Breadcraft/Commands/CreateSelectionBoxPanelCommand.cs b/Breadcraft/Commands/CreateSelectionBoxPanelCommand.cs index 2489fd7..40d67b2 100644 --- a/Breadcraft/Commands/CreateSelectionBoxPanelCommand.cs +++ b/Breadcraft/Commands/CreateSelectionBoxPanelCommand.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using DSharpPlus; @@ -17,7 +17,7 @@ public class CreateSelectionBoxPanelCommand : ApplicationCommandModule DiscordMessageBuilder builder = new DiscordMessageBuilder() .WithContent(" ") .AddComponents(await GetSelectComponents(command, message ?? "Open new ticket...")); - + await command.Channel.SendMessageAsync(builder); await command.CreateResponseAsync(new DiscordEmbedBuilder { @@ -25,25 +25,25 @@ public class CreateSelectionBoxPanelCommand : ApplicationCommandModule Description = "Successfully created message, make sure to run this command again if you add new categories to the bot." }, true); } - + public static async Task> GetSelectComponents(InteractionContext command, string placeholder) { List verifiedCategories = await Utilities.GetVerifiedChannels(); if (verifiedCategories.Count == 0) return new List(); - + verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList(); List selectionComponents = new List(); int selectionOptions = 0; for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++) { List categoryOptions = new List(); - + for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++) { categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString())); } - selectionComponents.Add(new DiscordSelectComponent("breadcraft_newticketselector" + selectionBoxes, placeholder, categoryOptions, false, 0, 1)); + selectionComponents.Add(new DiscordSelectComponent("bcsupport_newticketselector" + selectionBoxes, placeholder, categoryOptions, false, 0, 1)); } return selectionComponents; @@ -52,7 +52,7 @@ public class CreateSelectionBoxPanelCommand : ApplicationCommandModule public static async Task OnSelectionMenuUsed(DiscordInteraction interaction) { if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return; - + if (!ulong.TryParse(interaction.Data.Values[0], out ulong categoryID) || categoryID == 0) return; await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); diff --git a/Breadcraft/Commands/ListAssignedCommand.cs b/Breadcraft/Commands/ListAssignedCommand.cs index c8fbb1c..8eac898 100644 --- a/Breadcraft/Commands/ListAssignedCommand.cs +++ b/Breadcraft/Commands/ListAssignedCommand.cs @@ -15,7 +15,7 @@ public class ListAssignedCommand : ApplicationCommandModule public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) User to list tickets for.")] DiscordUser user = null) { DiscordUser listUser = user == null ? command.User : user; - + if (!Database.TryGetAssignedTickets(listUser.Id, out List assignedTickets)) { await command.CreateResponseAsync(new DiscordEmbedBuilder @@ -42,7 +42,7 @@ public class ListAssignedCommand : ApplicationCommandModule Description = message }); } - + // Add the footers for (int i = 0; i < embeds.Count; i++) { @@ -51,7 +51,7 @@ public class ListAssignedCommand : ApplicationCommandModule Text = $"Page {i + 1} / {embeds.Count}" }; } - + List listPages = new List(); foreach (DiscordEmbedBuilder embed in embeds) { diff --git a/Breadcraft/Commands/ListCommand.cs b/Breadcraft/Commands/ListCommand.cs index d2b4421..5393607 100644 --- a/Breadcraft/Commands/ListCommand.cs +++ b/Breadcraft/Commands/ListCommand.cs @@ -24,7 +24,7 @@ public class ListCommand : ApplicationCommandModule { listItems.Add("**" + ticket.DiscordRelativeTime() + ":** <#" + ticket.channelID + ">\n"); } - + foreach (string message in Utilities.ParseListIntoMessages(listItems)) { openEmbeds.Add(new DiscordEmbedBuilder @@ -33,11 +33,11 @@ public class ListCommand : ApplicationCommandModule Description = message }); } - + // Add the titles for (int i = 0; i < openEmbeds.Count; i++) { - openEmbeds[i].Title = $"Open tickets ({i+1}/{openEmbeds.Count})"; + openEmbeds[i].Title = $"Open tickets ({i + 1}/{openEmbeds.Count})"; } } @@ -49,7 +49,7 @@ public class ListCommand : ApplicationCommandModule { listItems.Add("**" + ticket.DiscordRelativeTime() + ":** Ticket " + ticket.id.ToString("00000") + "\n"); } - + foreach (string message in Utilities.ParseListIntoMessages(listItems)) { closedEmbeds.Add(new DiscordEmbedBuilder @@ -62,7 +62,7 @@ public class ListCommand : ApplicationCommandModule // Add the titles for (int i = 0; i < closedEmbeds.Count; i++) { - closedEmbeds[i].Title = $"Closed tickets ({i+1}/{closedEmbeds.Count})"; + closedEmbeds[i].Title = $"Closed tickets ({i + 1}/{closedEmbeds.Count})"; } } @@ -77,7 +77,7 @@ public class ListCommand : ApplicationCommandModule Text = $"Page {i + 1} / {embeds.Count}" }; } - + if (embeds.Count == 0) { await command.CreateResponseAsync(new DiscordEmbedBuilder @@ -87,7 +87,7 @@ public class ListCommand : ApplicationCommandModule }); return; } - + List listPages = new List(); foreach (DiscordEmbedBuilder embed in embeds) { diff --git a/Breadcraft/Commands/ListOpen.cs b/Breadcraft/Commands/ListOpen.cs index 12882ef..d53a29a 100644 --- a/Breadcraft/Commands/ListOpen.cs +++ b/Breadcraft/Commands/ListOpen.cs @@ -39,7 +39,7 @@ public class ListOpen : ApplicationCommandModule Description = message }); } - + // Add the footers for (int i = 0; i < embeds.Count; i++) { @@ -48,13 +48,13 @@ public class ListOpen : ApplicationCommandModule Text = $"Page {i + 1} / {embeds.Count}" }; } - + List listPages = new List(); foreach (DiscordEmbedBuilder embed in embeds) { listPages.Add(new Page("", embed)); } - + await command.Interaction.SendPaginatedResponseAsync(true, command.User, listPages); } } \ No newline at end of file diff --git a/Breadcraft/Commands/ListUnassignedCommand.cs b/Breadcraft/Commands/ListUnassignedCommand.cs index ed57cf3..6310676 100644 --- a/Breadcraft/Commands/ListUnassignedCommand.cs +++ b/Breadcraft/Commands/ListUnassignedCommand.cs @@ -40,7 +40,7 @@ public class ListUnassignedCommand : ApplicationCommandModule Description = message }); } - + // Add the footers for (int i = 0; i < embeds.Count; i++) { @@ -49,7 +49,7 @@ public class ListUnassignedCommand : ApplicationCommandModule Text = $"Page {i + 1} / {embeds.Count}" }; } - + List listPages = new List(); foreach (DiscordEmbedBuilder embed in embeds) { diff --git a/Breadcraft/Commands/NewCommand.cs b/Breadcraft/Commands/NewCommand.cs index 3c174d2..b7b38e5 100644 --- a/Breadcraft/Commands/NewCommand.cs +++ b/Breadcraft/Commands/NewCommand.cs @@ -9,6 +9,7 @@ using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; namespace Breadcraft.Commands; + public class NewCommand : ApplicationCommandModule { [SlashRequireGuild] @@ -28,7 +29,7 @@ public class NewCommand : ApplicationCommandModule case 1: await command.DeferAsync(true); (bool success, string message) = await OpenNewTicket(command.User.Id, command.Channel.Id, verifiedCategories[0].id); - + if (success) { await command.FollowUpAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder @@ -66,17 +67,17 @@ public class NewCommand : ApplicationCommandModule for (int nrOfButtonRows = 0; nrOfButtonRows < 5 && nrOfButtons < verifiedCategories.Count; nrOfButtonRows++) { List buttonRow = new List(); - + for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++) { - buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "breadcraft_newcommandbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name)); + buttonRow.Add(new DiscordButtonComponent(ButtonStyle.Primary, "bcsupport_newcommandbutton " + verifiedCategories[nrOfButtons].id, verifiedCategories[nrOfButtons].name)); } builder.AddComponents(buttonRow); } - + await command.CreateResponseAsync(builder.AsEphemeral()); } - + public static async Task CreateSelector(InteractionContext command, List verifiedCategories) { verifiedCategories = verifiedCategories.OrderBy(x => x.name).ToList(); @@ -85,26 +86,26 @@ public class NewCommand : ApplicationCommandModule for (int selectionBoxes = 0; selectionBoxes < 5 && selectionOptions < verifiedCategories.Count; selectionBoxes++) { List categoryOptions = new List(); - + for (; selectionOptions < 25 * (selectionBoxes + 1) && selectionOptions < verifiedCategories.Count; selectionOptions++) { categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString())); } - selectionComponents.Add(new DiscordSelectComponent("breadcraft_newcommandselector" + selectionBoxes, "Open new ticket...", categoryOptions, false, 0, 1)); + selectionComponents.Add(new DiscordSelectComponent("bcsupport_newcommandselector" + selectionBoxes, "Open new ticket...", categoryOptions, false, 0, 1)); } - + await command.CreateResponseAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral()); } - + public static async Task OnCategorySelection(DiscordInteraction interaction) { string stringID; switch (interaction.Data.ComponentType) { case ComponentType.Button: - stringID = interaction.Data.CustomId.Replace("breadcraft_newcommandbutton ", ""); + stringID = interaction.Data.CustomId.Replace("bcsupport_newcommandbutton ", ""); break; - case ComponentType.Select: + case ComponentType.StringSelect: if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return; stringID = interaction.Data.Values[0]; break; @@ -114,9 +115,9 @@ public class NewCommand : ApplicationCommandModule default: return; } - + if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) return; - + await interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral()); (bool success, string message) = await OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID); @@ -138,7 +139,7 @@ public class NewCommand : ApplicationCommandModule })); } } - + public static async Task<(bool, string)> OpenNewTicket(ulong userID, ulong commandChannelID, ulong categoryID) { // Check if user is blacklisted @@ -180,7 +181,7 @@ public class NewCommand : ApplicationCommandModule { return (false, "Error: Could not find you on the Discord server."); } - + DiscordChannel ticketChannel = null; try @@ -213,7 +214,7 @@ public class NewCommand : ApplicationCommandModule Logger.Error("Exception occurred trying to modify channel: " + e); Logger.Error("JsomMessage: " + e.JsonMessage); } - + try { await ticketChannel.AddOverwriteAsync(member, Permissions.AccessChannels); @@ -256,7 +257,7 @@ public class NewCommand : ApplicationCommandModule } } } - + // Log it if the log channel exists DiscordChannel logChannel = category.Guild.GetChannel(Config.logChannel); if (logChannel != null) @@ -265,11 +266,11 @@ public class NewCommand : ApplicationCommandModule { Color = DiscordColor.Green, Description = "Ticket " + ticketChannel.Mention + " opened by " + member.Mention + ".\n", - Footer = new DiscordEmbedBuilder.EmbedFooter {Text = "Ticket " + ticketID} + Footer = new DiscordEmbedBuilder.EmbedFooter { Text = "Ticket " + ticketID } }; await logChannel.SendMessageAsync(logMessage); } - + return (true, "Ticket opened, " + member.Mention + "!\n" + ticketChannel.Mention); } -} +} \ No newline at end of file diff --git a/Breadcraft/Commands/RandomAssignCommand.cs b/Breadcraft/Commands/RandomAssignCommand.cs index 8d59124..b54ec16 100644 --- a/Breadcraft/Commands/RandomAssignCommand.cs +++ b/Breadcraft/Commands/RandomAssignCommand.cs @@ -63,7 +63,7 @@ public class RandomAssignCommand : ApplicationCommandModule Description = "You have been randomly assigned to a support ticket: " + command.Channel.Mention }); } - catch (UnauthorizedException) {} + catch (UnauthorizedException) { } } // Log it if the log channel exists diff --git a/Breadcraft/Commands/RemoveCategoryCommand.cs b/Breadcraft/Commands/RemoveCategoryCommand.cs index aef302d..fe48eb3 100644 --- a/Breadcraft/Commands/RemoveCategoryCommand.cs +++ b/Breadcraft/Commands/RemoveCategoryCommand.cs @@ -1,4 +1,4 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; diff --git a/Breadcraft/Commands/RemoveStaffCommand.cs b/Breadcraft/Commands/RemoveStaffCommand.cs index 279fb61..5849138 100644 --- a/Breadcraft/Commands/RemoveStaffCommand.cs +++ b/Breadcraft/Commands/RemoveStaffCommand.cs @@ -2,7 +2,7 @@ using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; -using MySql.Data.MySqlClient; +using MySqlConnector; namespace Breadcraft.Commands; diff --git a/Breadcraft/Commands/SayCommand.cs b/Breadcraft/Commands/SayCommand.cs index fc85345..54f69e2 100644 --- a/Breadcraft/Commands/SayCommand.cs +++ b/Breadcraft/Commands/SayCommand.cs @@ -56,12 +56,12 @@ public class SayCommand : ApplicationCommandModule }, true); return; } - + await command.CreateResponseAsync(new DiscordEmbedBuilder { Color = DiscordColor.Cyan, Description = message.message.Replace("\\n", "\n") - }); + }); } } } \ No newline at end of file diff --git a/Breadcraft/Commands/SetSummaryCommand.cs b/Breadcraft/Commands/SetSummaryCommand.cs index 981c287..c12a12b 100644 --- a/Breadcraft/Commands/SetSummaryCommand.cs +++ b/Breadcraft/Commands/SetSummaryCommand.cs @@ -2,7 +2,7 @@ using DSharpPlus.Entities; using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands.Attributes; -using MySql.Data.MySqlClient; +using MySqlConnector; namespace Breadcraft.Commands; @@ -32,7 +32,7 @@ public class SetSummaryCommand : ApplicationCommandModule update.Prepare(); update.ExecuteNonQuery(); update.Dispose(); - + await command.CreateResponseAsync(new DiscordEmbedBuilder { Color = DiscordColor.Green, diff --git a/Breadcraft/Commands/StatusCommand.cs b/Breadcraft/Commands/StatusCommand.cs index 5659755..04ce634 100644 --- a/Breadcraft/Commands/StatusCommand.cs +++ b/Breadcraft/Commands/StatusCommand.cs @@ -15,12 +15,12 @@ public class StatusCommand : ApplicationCommandModule long closedTickets = Database.GetNumberOfClosedTickets(); DiscordEmbed botInfo = new DiscordEmbedBuilder() - .WithAuthor("BreadCraft-staff/Breadcraft-Support @ GitHub", "https://github.com/BreadCraft-staff/Breadcraft-Support", "https://cdn.discordapp.com/attachments/765441543100170271/905694651573489674/german_breadcraft.png") - .WithTitle("Bot information") + .WithAuthor("BreadCraft-staff/Breadcraft-Support @ GitHub", "https://github.com/BreadCraft-staff/Breadcraft-Support", "https://cdn.discordapp.com/attachments/765441543100170271/905694651573489674/german_breadcraft.png") + .WithTitle("Bot information") .WithColor(DiscordColor.Cyan) .AddField("Version:", Breadcraft.GetVersion()) .AddField("Open tickets:", openTickets + "", true) .AddField("Closed tickets:", closedTickets + " ", true); await command.CreateResponseAsync(botInfo); } -} \ No newline at end of file +} diff --git a/Breadcraft/Commands/ToggleActiveCommand.cs b/Breadcraft/Commands/ToggleActiveCommand.cs index cb18bf6..9c55de4 100644 --- a/Breadcraft/Commands/ToggleActiveCommand.cs +++ b/Breadcraft/Commands/ToggleActiveCommand.cs @@ -12,7 +12,7 @@ public class ToggleActiveCommand : ApplicationCommandModule public async Task OnExecute(InteractionContext command, [Option("User", "(Optional) Staff member to toggle activity for.")] DiscordUser user = null) { DiscordUser staffUser = user == null ? command.User : user; - + // Check if ticket exists in the database if (!Database.TryGetStaff(staffUser.Id, out Database.StaffMember staffMember)) { diff --git a/Breadcraft/Commands/TranscriptCommand.cs b/Breadcraft/Commands/TranscriptCommand.cs index 086bea9..c4ff57e 100644 --- a/Breadcraft/Commands/TranscriptCommand.cs +++ b/Breadcraft/Commands/TranscriptCommand.cs @@ -45,7 +45,7 @@ public class TranscriptCommand : ApplicationCommandModule return; } } - else + else { // If the ticket is still open, generate a new fresh transcript if (Database.TryGetOpenTicketByID((uint)ticketID, out ticket) && ticket?.creatorID == command.Member.Id) @@ -82,7 +82,7 @@ public class TranscriptCommand : ApplicationCommandModule if (logChannel != null) { await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read); - + DiscordMessageBuilder message = new DiscordMessageBuilder(); message.WithEmbed(new DiscordEmbedBuilder { @@ -90,7 +90,7 @@ public class TranscriptCommand : ApplicationCommandModule Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n", Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + command.Channel.Name } }); - message.WithFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); + message.AddFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); await logChannel.SendMessageAsync(message); } @@ -99,14 +99,14 @@ public class TranscriptCommand : ApplicationCommandModule { // Send transcript in a direct message await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read); - + DiscordMessageBuilder directMessage = new DiscordMessageBuilder(); directMessage.WithEmbed(new DiscordEmbedBuilder { Color = DiscordColor.Green, Description = "Transcript generated!\n" }); - directMessage.WithFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); + directMessage.AddFiles(new Dictionary { { Transcriber.GetFilename(ticket.id), file } }); await command.Member.SendMessageAsync(directMessage); } @@ -119,7 +119,7 @@ public class TranscriptCommand : ApplicationCommandModule })); return; } - + await command.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder { Color = DiscordColor.Green, diff --git a/Breadcraft/Config.cs b/Breadcraft/Config.cs index 4162245..3275f37 100644 --- a/Breadcraft/Config.cs +++ b/Breadcraft/Config.cs @@ -89,7 +89,7 @@ internal static class Config hostName = json.SelectToken("database.address")?.Value() ?? ""; port = json.SelectToken("database.port")?.Value() ?? 3306; database = json.SelectToken("database.name")?.Value() ?? "breadcraftsupport"; - username = json.SelectToken("database.user")?.Value() ?? "breadcraftsupport"; + username = json.SelectToken("database.user")?.Value() ?? "bcstaff"; password = json.SelectToken("database.password")?.Value() ?? ""; } } \ No newline at end of file diff --git a/Breadcraft/Database.cs b/Breadcraft/Database.cs index fbd0207..b43635d 100644 --- a/Breadcraft/Database.cs +++ b/Breadcraft/Database.cs @@ -2,7 +2,7 @@ using System.Linq; using System.Collections.Generic; using DSharpPlus; -using MySql.Data.MySqlClient; +using MySqlConnector; namespace Breadcraft; diff --git a/Breadcraft/EventHandler.cs b/Breadcraft/EventHandler.cs index c2c2fd7..80ff242 100644 --- a/Breadcraft/EventHandler.cs +++ b/Breadcraft/EventHandler.cs @@ -14,262 +14,272 @@ namespace Breadcraft; internal static class EventHandler { - internal static Task OnReady(DiscordClient client, ReadyEventArgs e) - { - Logger.Log("Client is ready to process events."); + internal static Task OnReady(DiscordClient client, ReadyEventArgs e) + { + Logger.Log("Client is ready to process events."); - // Checking activity type - if (!Enum.TryParse(Config.presenceType, true, out ActivityType activityType)) - { - Logger.Log("Presence type '" + Config.presenceType + "' invalid, using 'Playing' instead."); - activityType = ActivityType.Playing; - } + // Checking activity type + if (!Enum.TryParse(Config.presenceType, true, out ActivityType activityType)) + { + Logger.Log("Presence type '" + Config.presenceType + "' invalid, using 'Playing' instead."); + activityType = ActivityType.Playing; + } - client.UpdateStatusAsync(new DiscordActivity(Config.presenceText, activityType), UserStatus.Online); - return Task.CompletedTask; - } + client.UpdateStatusAsync(new DiscordActivity(Config.presenceText, activityType), UserStatus.Online); + return Task.CompletedTask; + } - internal static Task OnGuildAvailable(DiscordClient _, GuildCreateEventArgs e) - { - Logger.Log("Guild available: " + e.Guild.Name); + internal static Task OnGuildAvailable(DiscordClient _, GuildCreateEventArgs e) + { + Logger.Log("Guild available: " + e.Guild.Name); - IReadOnlyDictionary roles = e.Guild.Roles; + IReadOnlyDictionary roles = e.Guild.Roles; - foreach ((ulong roleID, DiscordRole role) in roles) - { - Logger.Log(role.Name.PadRight(40, '.') + roleID); - } - return Task.CompletedTask; - } + foreach ((ulong roleID, DiscordRole role) in roles) + { + Logger.Log(role.Name.PadRight(40, '.') + roleID); + } + return Task.CompletedTask; + } - internal static Task OnClientError(DiscordClient _, ClientErrorEventArgs e) - { - Logger.Error("Client exception occured:\n" + e.Exception); - switch (e.Exception) - { - case BadRequestException ex: - Logger.Error("JSON Message: " + ex.JsonMessage); - break; - } - return Task.CompletedTask; - } + internal static Task OnClientError(DiscordClient _, ClientErrorEventArgs e) + { + Logger.Error("Client exception occured:\n" + e.Exception); + switch (e.Exception) + { + case BadRequestException ex: + Logger.Error("JSON Message: " + ex.JsonMessage); + break; + } + return Task.CompletedTask; + } - internal static async Task OnMessageCreated(DiscordClient client, MessageCreateEventArgs e) - { - if (e.Author.IsBot) - { - return; - } + internal static async Task OnMessageCreated(DiscordClient client, MessageCreateEventArgs e) + { + if (e.Author.IsBot) + { + return; + } - // Check if ticket exists in the database and ticket notifications are enabled - if (!Database.TryGetOpenTicket(e.Channel.Id, out Database.Ticket ticket) || !Config.ticketUpdatedNotifications) - { - return; - } + // Check if ticket exists in the database and ticket notifications are enabled + if (!Database.TryGetOpenTicket(e.Channel.Id, out Database.Ticket ticket) || !Config.ticketUpdatedNotifications) + { + return; + } - // Sends a DM to the assigned staff member if at least a day has gone by since the last message and the user sending the message isn't staff - IReadOnlyList messages = await e.Channel.GetMessagesAsync(2); - if (messages.Count > 1 && messages[1].Timestamp < DateTimeOffset.UtcNow.AddDays(Config.ticketUpdatedNotificationDelay * -1) && !Database.IsStaff(e.Author.Id)) - { - try - { - DiscordMember staffMember = await e.Guild.GetMemberAsync(ticket.assignedStaffID); - await staffMember.SendMessageAsync(new DiscordEmbedBuilder - { - Color = DiscordColor.Green, - Description = "A ticket you are assigned to has been updated: " + e.Channel.Mention - }); - } - catch (NotFoundException) { } - catch (UnauthorizedException) { } - } - } + // Sends a DM to the assigned staff member if at least a day has gone by since the last message and the user sending the message isn't staff + IReadOnlyList messages = await e.Channel.GetMessagesAsync(2); + if (messages.Count > 1 && messages[1].Timestamp < DateTimeOffset.UtcNow.AddDays(Config.ticketUpdatedNotificationDelay * -1) && !Database.IsStaff(e.Author.Id)) + { + try + { + DiscordMember staffMember = await e.Guild.GetMemberAsync(ticket.assignedStaffID); + await staffMember.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Green, + Description = "A ticket you are assigned to has been updated: " + e.Channel.Mention + }); + } + catch (NotFoundException) { } + catch (UnauthorizedException) { } + } + } - internal static async Task OnCommandError(SlashCommandsExtension commandSystem, SlashCommandErrorEventArgs e) - { - switch (e.Exception) - { - case SlashExecutionChecksFailedException checksFailedException: - { - foreach (SlashCheckBaseAttribute attr in checksFailedException.FailedChecks) - { - await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder - { - Color = DiscordColor.Red, - Description = ParseFailedCheck(attr) - }); - } - return; - } - - case BadRequestException ex: - Logger.Error("Command exception occured:\n" + e.Exception); - Logger.Error("JSON Message: " + ex.JsonMessage); - return; + internal static async Task OnCommandError(SlashCommandsExtension commandSystem, SlashCommandErrorEventArgs e) + { + switch (e.Exception) + { + case SlashExecutionChecksFailedException checksFailedException: + { + foreach (SlashCheckBaseAttribute attr in checksFailedException.FailedChecks) + { + await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Red, + Description = ParseFailedCheck(attr) + }); + } + return; + } - default: - { - Logger.Error("Exception occured: " + e.Exception.GetType() + ": " + e.Exception); - await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder - { - Color = DiscordColor.Red, - Description = "Internal error occured, please report this to the developer." - }); - return; - } - } - } + case BadRequestException ex: + Logger.Error("Command exception occured:\n" + e.Exception); + Logger.Error("JSON Message: " + ex.JsonMessage); + return; - internal static async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs e) - { - if (!Database.TryGetOpenTickets(e.Member.Id, out List ownTickets)) - { - return; - } + default: + { + Logger.Error("Exception occured: " + e.Exception.GetType() + ": " + e.Exception); + await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Red, + Description = "Internal error occured, please report this to the developer." + }); + return; + } + } + } - foreach (Database.Ticket ticket in ownTickets) - { - try - { - DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); - if (channel?.GuildId == e.Guild.Id) - { - await channel.SendMessageAsync(new DiscordEmbedBuilder - { - Color = DiscordColor.Green, - Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket." - }); - } - } - catch (Exception) { /* ignored */ } - } - } + internal static async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs e) + { + if (!Database.TryGetOpenTickets(e.Member.Id, out List ownTickets)) + { + return; + } - internal static async Task OnMemberRemoved(DiscordClient client, GuildMemberRemoveEventArgs e) - { - if (Database.TryGetOpenTickets(e.Member.Id, out List ownTickets)) - { - foreach(Database.Ticket ticket in ownTickets) - { - try - { - DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); - if (channel?.GuildId == e.Guild.Id) - { - await channel.SendMessageAsync(new DiscordEmbedBuilder - { - Color = DiscordColor.Red, - Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server." - }); - } - } - catch (Exception) { /* ignored */ } - } - } + foreach (Database.Ticket ticket in ownTickets) + { + try + { + DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); + if (channel?.GuildId == e.Guild.Id) + { + try + { + await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels); + await channel.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Green, + Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket." + }); + } + catch (DiscordException ex) + { + Logger.Error("Exception occurred trying to add channel permissions: " + ex); + Logger.Error("JsomMessage: " + ex.JsonMessage); + } - if (Database.TryGetAssignedTickets(e.Member.Id, out List assignedTickets) && Config.logChannel != 0) - { - DiscordChannel logChannel = await client.GetChannelAsync(Config.logChannel); - if (logChannel != null) - { - foreach (Database.Ticket ticket in assignedTickets) - { - try - { - DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); - if (channel?.GuildId == e.Guild.Id) - { - await logChannel.SendMessageAsync(new DiscordEmbedBuilder - { - Color = DiscordColor.Red, - Description = "Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">" - }); - } - } - catch (Exception) { /* ignored */ } - } - } - } - } + } + } + catch (Exception) { /* ignored */ } + } + } - internal static async Task OnComponentInteractionCreated(DiscordClient client, ComponentInteractionCreateEventArgs e) - { - try - { - switch (e.Interaction.Data.ComponentType) - { - case ComponentType.Button: - switch (e.Id) - { - case "breadcraft_closeconfirm": - await CloseCommand.OnConfirmed(e.Interaction); - return; - case {} when e.Id.StartsWith("breadcraft_newcommandbutton"): - await NewCommand.OnCategorySelection(e.Interaction); - return; - case {} when e.Id.StartsWith("breadcraft_newticketbutton"): - await CreateButtonPanelCommand.OnButtonUsed(e.Interaction); - return; - case "right": - return; - case "left": - return; - case "rightskip": - return; - case "leftskip": - return; - case "stop": - return; - default: - Logger.Warn("Unknown button press received! '" + e.Id + "'"); - return; - } - case ComponentType.Select: - switch (e.Id) - { - case {} when e.Id.StartsWith("breadcraft_newcommandselector"): - await NewCommand.OnCategorySelection(e.Interaction); - return; - case {} when e.Id.StartsWith("breadcraft_newticketselector"): - await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction); - return; - default: - Logger.Warn("Unknown selection box option received! '" + e.Id + "'"); - return; - } - case ComponentType.ActionRow: - Logger.Warn("Unknown action row received! '" + e.Id + "'"); - return; - case ComponentType.FormInput: - Logger.Warn("Unknown form input received! '" + e.Id + "'"); - return; - default: - Logger.Warn("Unknown interaction type received! '" + e.Interaction.Data.ComponentType + "'"); - break; - } - } - catch (DiscordException ex) - { - Logger.Error("Interaction Exception occurred: " + ex); - Logger.Error("JsomMessage: " + ex.JsonMessage); - } - catch (Exception ex) - { - Logger.Error("Interaction Exception occured: " + ex.GetType() + ": " + ex); - } - } - - private static string ParseFailedCheck(SlashCheckBaseAttribute attr) - { - return attr switch - { - SlashRequireDirectMessageAttribute => "This command can only be used in direct messages!", - SlashRequireOwnerAttribute => "Only the server owner can use that command!", - SlashRequirePermissionsAttribute => "You don't have permission to do that!", - SlashRequireBotPermissionsAttribute => "The bot doesn't have the required permissions to do that!", - SlashRequireUserPermissionsAttribute => "You don't have permission to do that!", - SlashRequireGuildAttribute => "This command has to be used in a Discord server!", - _ => "Unknown Discord API error occured, please try again later." - }; - } + internal static async Task OnMemberRemoved(DiscordClient client, GuildMemberRemoveEventArgs e) + { + if (Database.TryGetOpenTickets(e.Member.Id, out List ownTickets)) + { + foreach (Database.Ticket ticket in ownTickets) + { + try + { + DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); + if (channel?.GuildId == e.Guild.Id) + { + await channel.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Red, + Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server." + }); + } + } + catch (Exception) { /* ignored */ } + } + } + + if (Database.TryGetAssignedTickets(e.Member.Id, out List assignedTickets) && Config.logChannel != 0) + { + DiscordChannel logChannel = await client.GetChannelAsync(Config.logChannel); + if (logChannel != null) + { + foreach (Database.Ticket ticket in assignedTickets) + { + try + { + DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); + if (channel?.GuildId == e.Guild.Id) + { + await logChannel.SendMessageAsync(new DiscordEmbedBuilder + { + Color = DiscordColor.Red, + Description = "Assigned staff member '" + e.Member.Username + "#" + e.Member.Discriminator + "' has left the server: <#" + channel.Id + ">" + }); + } + } + catch (Exception) { /* ignored */ } + } + } + } + } + + internal static async Task OnComponentInteractionCreated(DiscordClient client, ComponentInteractionCreateEventArgs e) + { + try + { + switch (e.Interaction.Data.ComponentType) + { + case ComponentType.Button: + switch (e.Id) + { + case "bcsupport_closeconfirm": + await CloseCommand.OnConfirmed(e.Interaction); + return; + case { } when e.Id.StartsWith("bcsupport_newcommandbutton"): + await NewCommand.OnCategorySelection(e.Interaction); + return; + case { } when e.Id.StartsWith("bcsupport_newticketbutton"): + await CreateButtonPanelCommand.OnButtonUsed(e.Interaction); + return; + case "right": + return; + case "left": + return; + case "rightskip": + return; + case "leftskip": + return; + case "stop": + return; + default: + Logger.Warn("Unknown button press received! '" + e.Id + "'"); + return; + } + case ComponentType.StringSelect: + switch (e.Id) + { + case { } when e.Id.StartsWith("bcsupport_newcommandselector"): + await NewCommand.OnCategorySelection(e.Interaction); + return; + case { } when e.Id.StartsWith("bcsupport_newticketselector"): + await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction); + return; + default: + Logger.Warn("Unknown selection box option received! '" + e.Id + "'"); + return; + } + case ComponentType.ActionRow: + Logger.Warn("Unknown action row received! '" + e.Id + "'"); + return; + case ComponentType.FormInput: + Logger.Warn("Unknown form input received! '" + e.Id + "'"); + return; + default: + Logger.Warn("Unknown interaction type received! '" + e.Interaction.Data.ComponentType + "'"); + break; + } + } + catch (DiscordException ex) + { + Logger.Error("Interaction Exception occurred: " + ex); + Logger.Error("JsomMessage: " + ex.JsonMessage); + } + catch (Exception ex) + { + Logger.Error("Interaction Exception occured: " + ex.GetType() + ": " + ex); + } + } + + private static string ParseFailedCheck(SlashCheckBaseAttribute attr) + { + return attr switch + { + SlashRequireDirectMessageAttribute => "This command can only be used in direct messages!", + SlashRequireOwnerAttribute => "Only the server owner can use that command!", + SlashRequirePermissionsAttribute => "You don't have permission to do that!", + SlashRequireBotPermissionsAttribute => "The bot doesn't have the required permissions to do that!", + SlashRequireUserPermissionsAttribute => "You don't have permission to do that!", + SlashRequireGuildAttribute => "This command has to be used in a Discord server!", + _ => "Unknown Discord API error occured, please try again later." + }; + } } \ No newline at end of file