2022-02-21 08:40:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-10-29 10:05:16 +00:00
|
|
|
|
using System.Linq;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
using DiscordChatExporter.Core.Utils.Extensions;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using DSharpPlus;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
using DSharpPlus.Commands;
|
|
|
|
|
using DSharpPlus.Commands.ContextChecks;
|
|
|
|
|
using DSharpPlus.Commands.EventArgs;
|
|
|
|
|
using DSharpPlus.Commands.Exceptions;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
using DSharpPlus.Entities;
|
|
|
|
|
using DSharpPlus.EventArgs;
|
|
|
|
|
using DSharpPlus.Exceptions;
|
2022-08-21 07:33:27 +00:00
|
|
|
|
using SupportChild.Commands;
|
2022-02-21 08:40:09 +00:00
|
|
|
|
|
2022-08-21 07:33:27 +00:00
|
|
|
|
namespace SupportChild;
|
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static class EventHandler
|
2022-02-21 08:40:09 +00:00
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static Task OnReady(DiscordClient client, GuildDownloadCompletedEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
Logger.Log("Connected to Discord.");
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2023-03-23 12:21:20 +00:00
|
|
|
|
// Checking activity type
|
2024-12-26 05:36:20 +00:00
|
|
|
|
if (!Enum.TryParse(Config.presenceType, true, out DiscordActivityType activityType))
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
Logger.Log("Presence type '" + Config.presenceType + "' invalid, using 'Playing' instead.");
|
2024-12-26 05:36:20 +00:00
|
|
|
|
activityType = DiscordActivityType.Playing;
|
2023-03-23 12:21:20 +00:00
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
client.UpdateStatusAsync(new DiscordActivity(Config.presenceText, activityType), DiscordUserStatus.Online);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static async Task OnGuildAvailable(DiscordClient discordClient, GuildAvailableEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
2024-10-29 10:05:16 +00:00
|
|
|
|
Logger.Log("Found Discord server: " + e.Guild.Name + " (" + e.Guild.Id + ")");
|
|
|
|
|
|
|
|
|
|
if (SupportChild.commandLineArgs.serversToLeave.Contains(e.Guild.Id))
|
|
|
|
|
{
|
|
|
|
|
Logger.Warn("LEAVING DISCORD SERVER AS REQUESTED: " + e.Guild.Name + " (" + e.Guild.Id + ")");
|
|
|
|
|
await e.Guild.LeaveAsync();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2023-03-23 12:21:20 +00:00
|
|
|
|
IReadOnlyDictionary<ulong, DiscordRole> roles = e.Guild.Roles;
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2023-03-23 12:21:20 +00:00
|
|
|
|
foreach ((ulong roleID, DiscordRole role) in roles)
|
|
|
|
|
{
|
2024-10-29 10:05:16 +00:00
|
|
|
|
Logger.Debug(role.Name.PadRight(40, '.') + roleID);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static async Task OnMessageCreated(DiscordClient client, MessageCreatedEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (e.Author.IsBot)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 07:12:50 +00:00
|
|
|
|
// Ignore messages outside of tickets.
|
|
|
|
|
if (!Database.TryGetOpenTicket(e.Channel.Id, out Database.Ticket ticket))
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 07:12:50 +00:00
|
|
|
|
// Send staff notification if applicable.
|
|
|
|
|
if (Config.ticketUpdatedNotifications)
|
|
|
|
|
{
|
|
|
|
|
await SendTicketUpdatedMessage(e, ticket);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Try to process the message as an interview response if the ticket owner replied to this bot.
|
|
|
|
|
if (ticket.creatorID == e.Author.Id && e.Message.ReferencedMessage?.Author == client.CurrentUser)
|
|
|
|
|
{
|
|
|
|
|
await Interviewer.ProcessResponseMessage(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static async Task SendTicketUpdatedMessage(MessageCreatedEventArgs e, Database.Ticket ticket)
|
|
|
|
|
{
|
2024-12-26 06:37:56 +00:00
|
|
|
|
// Ignore staff messages
|
|
|
|
|
if (Database.IsStaff(e.Author.Id))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sends a DM to the assigned staff member if at least a day has gone by since the last message
|
2023-03-23 12:21:20 +00:00
|
|
|
|
IReadOnlyList<DiscordMessage> messages = await e.Channel.GetMessagesAsync(2);
|
2024-12-26 06:37:56 +00:00
|
|
|
|
if (messages.Count > 1 && messages[1].Timestamp < DateTimeOffset.UtcNow.AddDays(Config.ticketUpdatedNotificationDelay * -1))
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
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) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static async Task OnMemberAdded(DiscordClient client, GuildMemberAddedEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Database.TryGetOpenTickets(e.Member.Id, out List<Database.Ticket> ownTickets))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2023-03-23 12:21:20 +00:00
|
|
|
|
foreach (Database.Ticket ticket in ownTickets)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
|
|
|
|
|
if (channel?.GuildId == e.Guild.Id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
await channel.AddOverwriteAsync(e.Member, DiscordPermissions.AccessChannels);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
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);
|
2024-12-26 07:12:50 +00:00
|
|
|
|
Logger.Error("JsonMessage: " + ex.JsonMessage);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2023-03-23 12:21:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception) { /* ignored */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static async Task OnMemberRemoved(DiscordClient client, GuildMemberRemovedEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (Database.TryGetOpenTickets(e.Member.Id, out List<Database.Ticket> 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 */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-17 13:09:25 +00:00
|
|
|
|
|
2023-03-23 12:21:20 +00:00
|
|
|
|
if (Database.TryGetAssignedTickets(e.Member.Id, out List<Database.Ticket> 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 */ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-21 07:33:27 +00:00
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static async Task OnComponentInteractionCreated(DiscordClient client, ComponentInteractionCreatedEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
switch (e.Interaction.Data.ComponentType)
|
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case DiscordComponentType.Button:
|
2023-03-23 12:21:20 +00:00
|
|
|
|
switch (e.Id)
|
|
|
|
|
{
|
|
|
|
|
case "supportchild_closeconfirm":
|
|
|
|
|
await CloseCommand.OnConfirmed(e.Interaction);
|
|
|
|
|
return;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case not null when e.Id.StartsWith("supportchild_newcommandbutton"):
|
2024-12-26 07:12:50 +00:00
|
|
|
|
await OnNewTicketSelectorUsed(e.Interaction);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
return;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case not null when e.Id.StartsWith("supportchild_newticketbutton"):
|
2024-12-26 07:12:50 +00:00
|
|
|
|
await OnNewTicketButtonUsed(e.Interaction);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
return;
|
2024-12-26 07:12:50 +00:00
|
|
|
|
case not null when e.Id.StartsWith("supportchild_interviewbutton"):
|
2024-12-26 07:16:18 +00:00
|
|
|
|
await Interviewer.ProcessButtonOrSelectorResponse(e.Interaction);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
return;
|
2024-12-26 07:12:50 +00:00
|
|
|
|
case "right":
|
2023-03-23 12:21:20 +00:00
|
|
|
|
case "left":
|
|
|
|
|
case "rightskip":
|
|
|
|
|
case "leftskip":
|
|
|
|
|
case "stop":
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
Logger.Warn("Unknown button press received! '" + e.Id + "'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case DiscordComponentType.StringSelect:
|
2023-03-23 12:21:20 +00:00
|
|
|
|
switch (e.Id)
|
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case not null when e.Id.StartsWith("supportchild_newcommandselector"):
|
2024-12-26 07:12:50 +00:00
|
|
|
|
await OnNewTicketSelectorUsed(e.Interaction);
|
2023-03-23 12:21:20 +00:00
|
|
|
|
return;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case not null when e.Id.StartsWith("supportchild_newticketselector"):
|
2023-03-23 12:21:20 +00:00
|
|
|
|
await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction);
|
|
|
|
|
return;
|
2024-12-26 07:16:18 +00:00
|
|
|
|
case not null when e.Id.StartsWith("supportchild_interviewselector"):
|
|
|
|
|
await Interviewer.ProcessButtonOrSelectorResponse(e.Interaction);
|
|
|
|
|
return;
|
2023-03-23 12:21:20 +00:00
|
|
|
|
default:
|
|
|
|
|
Logger.Warn("Unknown selection box option received! '" + e.Id + "'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case DiscordComponentType.ActionRow:
|
2023-03-23 12:21:20 +00:00
|
|
|
|
Logger.Warn("Unknown action row received! '" + e.Id + "'");
|
|
|
|
|
return;
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case DiscordComponentType.FormInput:
|
2023-03-23 12:21:20 +00:00
|
|
|
|
Logger.Warn("Unknown form input received! '" + e.Id + "'");
|
|
|
|
|
return;
|
2024-12-26 07:04:47 +00:00
|
|
|
|
case DiscordComponentType.UserSelect:
|
2024-12-26 07:51:41 +00:00
|
|
|
|
switch (e.Id)
|
|
|
|
|
{
|
|
|
|
|
case not null when e.Id.StartsWith("supportchild_interviewuserselector"):
|
|
|
|
|
await Interviewer.ProcessButtonOrSelectorResponse(e.Interaction);
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
Logger.Warn("Unknown selection box option received! '" + e.Id + "'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 07:04:47 +00:00
|
|
|
|
case DiscordComponentType.RoleSelect:
|
2024-12-26 07:51:41 +00:00
|
|
|
|
switch (e.Id)
|
|
|
|
|
{
|
|
|
|
|
case not null when e.Id.StartsWith("supportchild_interviewroleselector"):
|
|
|
|
|
await Interviewer.ProcessButtonOrSelectorResponse(e.Interaction);
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
Logger.Warn("Unknown selection box option received! '" + e.Id + "'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 07:04:47 +00:00
|
|
|
|
case DiscordComponentType.MentionableSelect:
|
2024-12-26 07:51:41 +00:00
|
|
|
|
switch (e.Id)
|
|
|
|
|
{
|
|
|
|
|
case not null when e.Id.StartsWith("supportchild_interviewmentionableselector"):
|
|
|
|
|
await Interviewer.ProcessButtonOrSelectorResponse(e.Interaction);
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
Logger.Warn("Unknown selection box option received! '" + e.Id + "'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 07:04:47 +00:00
|
|
|
|
case DiscordComponentType.ChannelSelect:
|
2024-12-26 07:51:41 +00:00
|
|
|
|
switch (e.Id)
|
|
|
|
|
{
|
|
|
|
|
case not null when e.Id.StartsWith("supportchild_interviewchannelselector"):
|
|
|
|
|
await Interviewer.ProcessButtonOrSelectorResponse(e.Interaction);
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
Logger.Warn("Unknown selection box option received! '" + e.Id + "'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-23 12:21:20 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-26 07:04:47 +00:00
|
|
|
|
|
2024-12-26 07:12:50 +00:00
|
|
|
|
private static async Task OnNewTicketButtonUsed(DiscordInteraction interaction)
|
2024-12-26 07:04:47 +00:00
|
|
|
|
{
|
|
|
|
|
await interaction.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
|
|
|
|
|
|
|
|
|
|
if (!ulong.TryParse(interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""), out ulong categoryID) || categoryID == 0)
|
|
|
|
|
{
|
2024-12-26 07:12:50 +00:00
|
|
|
|
Logger.Warn("Invalid ticket button ID: " + interaction.Data.CustomId.Replace("supportchild_newticketbutton ", ""));
|
2024-12-26 07:04:47 +00:00
|
|
|
|
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
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 07:12:50 +00:00
|
|
|
|
private static async Task OnNewTicketSelectorUsed(DiscordInteraction interaction)
|
2024-12-26 07:04:47 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 05:36:20 +00:00
|
|
|
|
public static async Task OnCommandError(CommandsExtension commandSystem, CommandErroredEventArgs e)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
switch (e.Exception)
|
2023-03-23 12:21:20 +00:00
|
|
|
|
{
|
2024-12-26 05:36:20 +00:00
|
|
|
|
case ChecksFailedException checksFailedException:
|
|
|
|
|
{
|
|
|
|
|
foreach (ContextCheckFailedData error in checksFailedException.Errors)
|
|
|
|
|
{
|
|
|
|
|
await e.Context.Channel.SendMessageAsync(new DiscordEmbedBuilder
|
|
|
|
|
{
|
|
|
|
|
Color = DiscordColor.Red,
|
|
|
|
|
Description = error.ErrorMessage
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case BadRequestException ex:
|
|
|
|
|
Logger.Error("Command exception occured:\n" + e.Exception);
|
|
|
|
|
Logger.Error("JSON Message: " + ex.JsonMessage);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-23 12:21:20 +00:00
|
|
|
|
}
|
2024-12-26 07:04:47 +00:00
|
|
|
|
|
2022-05-17 13:09:25 +00:00
|
|
|
|
}
|