diff --git a/Commands/CreateButtonPanelCommand.cs b/Commands/CreateButtonPanelCommand.cs index d0ffe53..794b4c7 100644 --- a/Commands/CreateButtonPanelCommand.cs +++ b/Commands/CreateButtonPanelCommand.cs @@ -50,34 +50,4 @@ public class CreateButtonPanelCommand 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(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); - - if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""), out ulong categoryID) || categoryID == 0) - { - Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("supportchild_newticketbutton ", "")); - return; - } - - (bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID); - - if (success) - { - await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder - { - Color = DiscordColor.Green, - Description = message - })); - } - else - { - await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder - { - Color = DiscordColor.Red, - Description = message - })); - } - } } \ No newline at end of file diff --git a/Commands/NewCommand.cs b/Commands/NewCommand.cs index 616985d..ed5bfa8 100644 --- a/Commands/NewCommand.cs +++ b/Commands/NewCommand.cs @@ -101,55 +101,6 @@ public class NewCommand await command.RespondAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral()); } - public static async Task OnCategorySelection(DiscordInteraction interaction) - { - string stringID; - switch (interaction.Data.ComponentType) - { - case DiscordComponentType.Button: - stringID = interaction.Data.CustomId.Replace("supportchild_newcommandbutton ", ""); - break; - case DiscordComponentType.StringSelect: - if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) - { - return; - } - stringID = interaction.Data.Values[0]; - break; - - case DiscordComponentType.ActionRow: - case DiscordComponentType.FormInput: - default: - return; - } - - if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) - { - return; - } - - await interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral()); - - (bool success, string message) = await OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID); - - if (success) - { - await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder - { - Color = DiscordColor.Green, - Description = message - })); - } - else - { - await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder - { - Color = DiscordColor.Red, - Description = message - })); - } - } - public static async Task<(bool, string)> OpenNewTicket(ulong userID, ulong commandChannelID, ulong categoryID) { // Check if user is blacklisted diff --git a/EventHandler.cs b/EventHandler.cs index 14db8cb..5d0c882 100644 --- a/EventHandler.cs +++ b/EventHandler.cs @@ -183,10 +183,10 @@ public static class EventHandler await CloseCommand.OnConfirmed(e.Interaction); return; case not null when e.Id.StartsWith("supportchild_newcommandbutton"): - await NewCommand.OnCategorySelection(e.Interaction); + await OnCategorySelection(e.Interaction); return; case not null when e.Id.StartsWith("supportchild_newticketbutton"): - await CreateButtonPanelCommand.OnButtonUsed(e.Interaction); + await OnButtonUsed(e.Interaction); return; case "right": return; @@ -206,7 +206,7 @@ public static class EventHandler switch (e.Id) { case not null when e.Id.StartsWith("supportchild_newcommandselector"): - await NewCommand.OnCategorySelection(e.Interaction); + await OnCategorySelection(e.Interaction); return; case not null when e.Id.StartsWith("supportchild_newticketselector"): await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction); @@ -221,6 +221,10 @@ public static class EventHandler case DiscordComponentType.FormInput: Logger.Warn("Unknown form input received! '" + e.Id + "'"); return; + case DiscordComponentType.UserSelect: + case DiscordComponentType.RoleSelect: + case DiscordComponentType.MentionableSelect: + case DiscordComponentType.ChannelSelect: default: Logger.Warn("Unknown interaction type received! '" + e.Interaction.Data.ComponentType + "'"); break; @@ -236,6 +240,86 @@ public static class EventHandler Logger.Error("Interaction Exception occured: " + ex.GetType() + ": " + ex); } } + + private static async Task OnButtonUsed(DiscordInteraction interaction) + { + await interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); + + if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""), out ulong categoryID) || categoryID == 0) + { + Logger.Warn("Invalid ID: " + interaction.Data.CustomId.Replace("supportchild_newticketbutton ", "")); + return; + } + + (bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID); + + if (success) + { + await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder + { + Color = DiscordColor.Green, + Description = message + })); + } + else + { + await interaction.CreateFollowupMessageAsync(new DiscordFollowupMessageBuilder().AddEmbed(new DiscordEmbedBuilder + { + Color = DiscordColor.Red, + Description = message + })); + } + } + + private static async Task OnCategorySelection(DiscordInteraction interaction) + { + string stringID; + switch (interaction.Data.ComponentType) + { + case DiscordComponentType.Button: + stringID = interaction.Data.CustomId.Replace("supportchild_newcommandbutton ", ""); + break; + case DiscordComponentType.StringSelect: + if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) + { + return; + } + stringID = interaction.Data.Values[0]; + break; + + case DiscordComponentType.ActionRow: + case DiscordComponentType.FormInput: + default: + return; + } + + if (!ulong.TryParse(stringID, out ulong categoryID) || categoryID == 0) + { + return; + } + + await interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredMessageUpdate, new DiscordInteractionResponseBuilder().AsEphemeral()); + + (bool success, string message) = await NewCommand.OpenNewTicket(interaction.User.Id, interaction.ChannelId, categoryID); + + if (success) + { + await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder + { + Color = DiscordColor.Green, + Description = message + })); + } + else + { + await interaction.EditOriginalResponseAsync(new DiscordWebhookBuilder().AddEmbed(new DiscordEmbedBuilder + { + Color = DiscordColor.Red, + Description = message + })); + } + } + public static async Task OnCommandError(CommandsExtension commandSystem, CommandErroredEventArgs e) { switch (e.Exception) @@ -270,4 +354,5 @@ public static class EventHandler } } } + } \ No newline at end of file