Updated stuff to be the right version and fixed some commands
This commit is contained in:
parent
c299c869f1
commit
04134e9fb2
26 changed files with 359 additions and 348 deletions
|
@ -27,13 +27,13 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DSharpPlus" Version="4.2.0" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0" />
|
||||
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0" />
|
||||
<PackageReference Include="DSharpPlus" Version="4.4.0-nightly-01249" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.4.0-nightly-01249" />
|
||||
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.4.0-nightly-01249" />
|
||||
<PackageReference Include="Gress" Version="2.0.1" />
|
||||
<PackageReference Include="JsonExtensions" Version="1.2.0" />
|
||||
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.1" />
|
||||
<PackageReference Include="MySql.Data" Version="8.0.30" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.2.5" />
|
||||
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.1" />
|
||||
<PackageReference Include="Polly" Version="7.2.3" />
|
||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<DiscordChannel> allChannels = new List<DiscordChannel>();
|
||||
foreach (KeyValuePair<ulong,DiscordGuild> guild in Breadcraft.discordClient.Guilds)
|
||||
foreach (KeyValuePair<ulong, DiscordGuild> guild in Breadcraft.discordClient.Guilds)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -33,7 +33,7 @@ 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);
|
||||
|
@ -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<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await logChannel.SendMessageAsync(message);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class CloseCommand : ApplicationCommandModule
|
|||
|
||||
DiscordMessageBuilder message = new DiscordMessageBuilder();
|
||||
message.WithEmbed(embed);
|
||||
message.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await staffMember.SendMessageAsync(message);
|
||||
}
|
||||
|
@ -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.");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
|
@ -36,7 +36,7 @@ public class CreateButtonPanelCommand : ApplicationCommandModule
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ public class CreateButtonPanelCommand : ApplicationCommandModule
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus;
|
||||
|
@ -43,7 +43,7 @@ public class CreateSelectionBoxPanelCommand : ApplicationCommandModule
|
|||
{
|
||||
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;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ListCommand : ApplicationCommandModule
|
|||
// 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})";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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})";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ using DSharpPlus.SlashCommands;
|
|||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
||||
namespace Breadcraft.Commands;
|
||||
|
||||
public class NewCommand : ApplicationCommandModule
|
||||
{
|
||||
[SlashRequireGuild]
|
||||
|
@ -69,7 +70,7 @@ public class NewCommand : ApplicationCommandModule
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -90,7 +91,7 @@ public class NewCommand : ApplicationCommandModule
|
|||
{
|
||||
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());
|
||||
|
@ -102,9 +103,9 @@ public class NewCommand : ApplicationCommandModule
|
|||
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;
|
||||
|
@ -265,7 +266,7 @@ 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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
using MySql.Data.MySqlClient;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace Breadcraft.Commands;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using DSharpPlus.SlashCommands.Attributes;
|
||||
using MySql.Data.MySqlClient;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace Breadcraft.Commands;
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ 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)
|
||||
|
|
|
@ -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<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
message.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await logChannel.SendMessageAsync(message);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class TranscriptCommand : ApplicationCommandModule
|
|||
Color = DiscordColor.Green,
|
||||
Description = "Transcript generated!\n"
|
||||
});
|
||||
directMessage.WithFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
directMessage.AddFiles(new Dictionary<string, Stream> { { Transcriber.GetFilename(ticket.id), file } });
|
||||
|
||||
await command.Member.SendMessageAsync(directMessage);
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ internal static class Config
|
|||
hostName = json.SelectToken("database.address")?.Value<string>() ?? "";
|
||||
port = json.SelectToken("database.port")?.Value<int>() ?? 3306;
|
||||
database = json.SelectToken("database.name")?.Value<string>() ?? "breadcraftsupport";
|
||||
username = json.SelectToken("database.user")?.Value<string>() ?? "breadcraftsupport";
|
||||
username = json.SelectToken("database.user")?.Value<string>() ?? "bcstaff";
|
||||
password = json.SelectToken("database.password")?.Value<string>() ?? "";
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using DSharpPlus;
|
||||
using MySql.Data.MySqlClient;
|
||||
using MySqlConnector;
|
||||
|
||||
namespace Breadcraft;
|
||||
|
||||
|
|
|
@ -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<ulong, DiscordRole> roles = e.Guild.Roles;
|
||||
IReadOnlyDictionary<ulong, DiscordRole> 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<DiscordMessage> 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<DiscordMessage> 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;
|
||||
}
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs e)
|
||||
{
|
||||
if (!Database.TryGetOpenTickets(e.Member.Id, out List<Database.Ticket> ownTickets))
|
||||
{
|
||||
return;
|
||||
}
|
||||
internal static async Task OnMemberAdded(DiscordClient client, GuildMemberAddEventArgs e)
|
||||
{
|
||||
if (!Database.TryGetOpenTickets(e.Member.Id, out List<Database.Ticket> ownTickets))
|
||||
{
|
||||
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 */ }
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
internal static async Task OnMemberRemoved(DiscordClient client, GuildMemberRemoveEventArgs e)
|
||||
{
|
||||
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 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) { /* ignored */ }
|
||||
}
|
||||
}
|
||||
|
||||
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 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static async Task OnMemberRemoved(DiscordClient client, GuildMemberRemoveEventArgs e)
|
||||
{
|
||||
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 */ }
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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 */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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."
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue