Moved button and selector logic for new tickets to event handler
This commit is contained in:
parent
d212f13b12
commit
327f4d6de6
3 changed files with 88 additions and 82 deletions
|
@ -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."
|
Description = "Successfully created message, make sure to run this command again if you add new categories to the bot."
|
||||||
}, true);
|
}, 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
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -101,55 +101,6 @@ public class NewCommand
|
||||||
await command.RespondAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral());
|
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)
|
public static async Task<(bool, string)> OpenNewTicket(ulong userID, ulong commandChannelID, ulong categoryID)
|
||||||
{
|
{
|
||||||
// Check if user is blacklisted
|
// Check if user is blacklisted
|
||||||
|
|
|
@ -183,10 +183,10 @@ public static class EventHandler
|
||||||
await CloseCommand.OnConfirmed(e.Interaction);
|
await CloseCommand.OnConfirmed(e.Interaction);
|
||||||
return;
|
return;
|
||||||
case not null when e.Id.StartsWith("supportchild_newcommandbutton"):
|
case not null when e.Id.StartsWith("supportchild_newcommandbutton"):
|
||||||
await NewCommand.OnCategorySelection(e.Interaction);
|
await OnCategorySelection(e.Interaction);
|
||||||
return;
|
return;
|
||||||
case not null when e.Id.StartsWith("supportchild_newticketbutton"):
|
case not null when e.Id.StartsWith("supportchild_newticketbutton"):
|
||||||
await CreateButtonPanelCommand.OnButtonUsed(e.Interaction);
|
await OnButtonUsed(e.Interaction);
|
||||||
return;
|
return;
|
||||||
case "right":
|
case "right":
|
||||||
return;
|
return;
|
||||||
|
@ -206,7 +206,7 @@ public static class EventHandler
|
||||||
switch (e.Id)
|
switch (e.Id)
|
||||||
{
|
{
|
||||||
case not null when e.Id.StartsWith("supportchild_newcommandselector"):
|
case not null when e.Id.StartsWith("supportchild_newcommandselector"):
|
||||||
await NewCommand.OnCategorySelection(e.Interaction);
|
await OnCategorySelection(e.Interaction);
|
||||||
return;
|
return;
|
||||||
case not null when e.Id.StartsWith("supportchild_newticketselector"):
|
case not null when e.Id.StartsWith("supportchild_newticketselector"):
|
||||||
await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction);
|
await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction);
|
||||||
|
@ -221,6 +221,10 @@ public static class EventHandler
|
||||||
case DiscordComponentType.FormInput:
|
case DiscordComponentType.FormInput:
|
||||||
Logger.Warn("Unknown form input received! '" + e.Id + "'");
|
Logger.Warn("Unknown form input received! '" + e.Id + "'");
|
||||||
return;
|
return;
|
||||||
|
case DiscordComponentType.UserSelect:
|
||||||
|
case DiscordComponentType.RoleSelect:
|
||||||
|
case DiscordComponentType.MentionableSelect:
|
||||||
|
case DiscordComponentType.ChannelSelect:
|
||||||
default:
|
default:
|
||||||
Logger.Warn("Unknown interaction type received! '" + e.Interaction.Data.ComponentType + "'");
|
Logger.Warn("Unknown interaction type received! '" + e.Interaction.Data.ComponentType + "'");
|
||||||
break;
|
break;
|
||||||
|
@ -236,6 +240,86 @@ public static class EventHandler
|
||||||
Logger.Error("Interaction Exception occured: " + ex.GetType() + ": " + ex);
|
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)
|
public static async Task OnCommandError(CommandsExtension commandSystem, CommandErroredEventArgs e)
|
||||||
{
|
{
|
||||||
switch (e.Exception)
|
switch (e.Exception)
|
||||||
|
@ -270,4 +354,5 @@ public static class EventHandler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue