Updated stuff to be the right version and fixed some commands

This commit is contained in:
Emotion 2023-05-26 23:27:27 +12:00
parent c299c869f1
commit 04134e9fb2
No known key found for this signature in database
GPG key ID: 15EBDFF858B9A65A
26 changed files with 359 additions and 348 deletions

View file

@ -27,13 +27,13 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.2.0" /> <PackageReference Include="DSharpPlus" Version="4.4.0-nightly-01249" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0" /> <PackageReference Include="DSharpPlus.Interactivity" Version="4.4.0-nightly-01249" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0" /> <PackageReference Include="DSharpPlus.SlashCommands" Version="4.4.0-nightly-01249" />
<PackageReference Include="Gress" Version="2.0.1" /> <PackageReference Include="Gress" Version="2.0.1" />
<PackageReference Include="JsonExtensions" Version="1.2.0" /> <PackageReference Include="JsonExtensions" Version="1.2.0" />
<PackageReference Include="MiniRazor.CodeGen" Version="2.2.1" /> <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="Newtonsoft.Json.Bson" Version="1.0.1" />
<PackageReference Include="Polly" Version="7.2.3" /> <PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="Superpower" Version="3.0.0" /> <PackageReference Include="Superpower" Version="3.0.0" />

View file

@ -1,4 +1,4 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes; using DSharpPlus.SlashCommands.Attributes;

View file

@ -3,7 +3,7 @@ using System.Threading.Tasks;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes; using DSharpPlus.SlashCommands.Attributes;
using MySql.Data.MySqlClient; using MySqlConnector;
namespace Breadcraft.Commands; namespace Breadcraft.Commands;

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;

View file

@ -33,7 +33,7 @@ public class CloseCommand : ApplicationCommandModule
Color = DiscordColor.Cyan, Color = DiscordColor.Cyan,
Description = "Are you sure you wish to close this ticket? You cannot re-open it again later." 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); 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); await using FileStream file = new FileStream(Transcriber.GetPath(ticket.id), FileMode.Open, FileAccess.Read);
DiscordMessageBuilder message = new DiscordMessageBuilder(); DiscordMessageBuilder message = new DiscordMessageBuilder();
message.WithEmbed(embed); 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); await logChannel.SendMessageAsync(message);
} }
@ -107,7 +107,7 @@ public class CloseCommand : ApplicationCommandModule
DiscordMessageBuilder message = new DiscordMessageBuilder(); DiscordMessageBuilder message = new DiscordMessageBuilder();
message.WithEmbed(embed); 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); await staffMember.SendMessageAsync(message);
} }

View file

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus; using DSharpPlus;
@ -36,7 +36,7 @@ public class CreateButtonPanelCommand : ApplicationCommandModule
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++) 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); builder.AddComponents(buttonRow);
} }
@ -53,9 +53,9 @@ public class CreateButtonPanelCommand : ApplicationCommandModule
{ {
await interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral()); 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; return;
} }

View file

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus; using DSharpPlus;
@ -43,7 +43,7 @@ public class CreateSelectionBoxPanelCommand : ApplicationCommandModule
{ {
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString())); 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; return selectionComponents;

View file

@ -9,6 +9,7 @@ using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes; using DSharpPlus.SlashCommands.Attributes;
namespace Breadcraft.Commands; namespace Breadcraft.Commands;
public class NewCommand : ApplicationCommandModule public class NewCommand : ApplicationCommandModule
{ {
[SlashRequireGuild] [SlashRequireGuild]
@ -69,7 +70,7 @@ public class NewCommand : ApplicationCommandModule
for (; nrOfButtons < 5 * (nrOfButtonRows + 1) && nrOfButtons < verifiedCategories.Count; nrOfButtons++) 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); builder.AddComponents(buttonRow);
} }
@ -90,7 +91,7 @@ public class NewCommand : ApplicationCommandModule
{ {
categoryOptions.Add(new DiscordSelectComponentOption(verifiedCategories[selectionOptions].name, verifiedCategories[selectionOptions].id.ToString())); 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()); await command.CreateResponseAsync(new DiscordInteractionResponseBuilder().AddComponents(selectionComponents).AsEphemeral());
@ -102,9 +103,9 @@ public class NewCommand : ApplicationCommandModule
switch (interaction.Data.ComponentType) switch (interaction.Data.ComponentType)
{ {
case ComponentType.Button: case ComponentType.Button:
stringID = interaction.Data.CustomId.Replace("breadcraft_newcommandbutton ", ""); stringID = interaction.Data.CustomId.Replace("bcsupport_newcommandbutton ", "");
break; break;
case ComponentType.Select: case ComponentType.StringSelect:
if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return; if (interaction.Data.Values == null || interaction.Data.Values.Length <= 0) return;
stringID = interaction.Data.Values[0]; stringID = interaction.Data.Values[0];
break; break;

View file

@ -1,4 +1,4 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes; using DSharpPlus.SlashCommands.Attributes;

View file

@ -2,7 +2,7 @@
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes; using DSharpPlus.SlashCommands.Attributes;
using MySql.Data.MySqlClient; using MySqlConnector;
namespace Breadcraft.Commands; namespace Breadcraft.Commands;

View file

@ -2,7 +2,7 @@
using DSharpPlus.Entities; using DSharpPlus.Entities;
using DSharpPlus.SlashCommands; using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes; using DSharpPlus.SlashCommands.Attributes;
using MySql.Data.MySqlClient; using MySqlConnector;
namespace Breadcraft.Commands; namespace Breadcraft.Commands;

View file

@ -90,7 +90,7 @@ public class TranscriptCommand : ApplicationCommandModule
Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n", Description = "Ticket " + ticket.id.ToString("00000") + " transcript generated by " + command.Member.Mention + ".\n",
Footer = new DiscordEmbedBuilder.EmbedFooter { Text = '#' + command.Channel.Name } 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); await logChannel.SendMessageAsync(message);
} }
@ -106,7 +106,7 @@ public class TranscriptCommand : ApplicationCommandModule
Color = DiscordColor.Green, Color = DiscordColor.Green,
Description = "Transcript generated!\n" 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); await command.Member.SendMessageAsync(directMessage);
} }

View file

@ -89,7 +89,7 @@ internal static class Config
hostName = json.SelectToken("database.address")?.Value<string>() ?? ""; hostName = json.SelectToken("database.address")?.Value<string>() ?? "";
port = json.SelectToken("database.port")?.Value<int>() ?? 3306; port = json.SelectToken("database.port")?.Value<int>() ?? 3306;
database = json.SelectToken("database.name")?.Value<string>() ?? "breadcraftsupport"; 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>() ?? ""; password = json.SelectToken("database.password")?.Value<string>() ?? "";
} }
} }

View file

@ -2,7 +2,7 @@
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using DSharpPlus; using DSharpPlus;
using MySql.Data.MySqlClient; using MySqlConnector;
namespace Breadcraft; namespace Breadcraft;

View file

@ -134,12 +134,22 @@ internal static class EventHandler
DiscordChannel channel = await client.GetChannelAsync(ticket.channelID); DiscordChannel channel = await client.GetChannelAsync(ticket.channelID);
if (channel?.GuildId == e.Guild.Id) if (channel?.GuildId == e.Guild.Id)
{ {
try
{
await channel.AddOverwriteAsync(e.Member, Permissions.AccessChannels);
await channel.SendMessageAsync(new DiscordEmbedBuilder await channel.SendMessageAsync(new DiscordEmbedBuilder
{ {
Color = DiscordColor.Green, Color = DiscordColor.Green,
Description = "User '" + e.Member.Username + "#" + e.Member.Discriminator + "' has rejoined the server, and has been re-added to the ticket." 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);
}
}
} }
catch (Exception) { /* ignored */ } catch (Exception) { /* ignored */ }
} }
@ -201,13 +211,13 @@ internal static class EventHandler
case ComponentType.Button: case ComponentType.Button:
switch (e.Id) switch (e.Id)
{ {
case "breadcraft_closeconfirm": case "bcsupport_closeconfirm":
await CloseCommand.OnConfirmed(e.Interaction); await CloseCommand.OnConfirmed(e.Interaction);
return; return;
case {} when e.Id.StartsWith("breadcraft_newcommandbutton"): case { } when e.Id.StartsWith("bcsupport_newcommandbutton"):
await NewCommand.OnCategorySelection(e.Interaction); await NewCommand.OnCategorySelection(e.Interaction);
return; return;
case {} when e.Id.StartsWith("breadcraft_newticketbutton"): case { } when e.Id.StartsWith("bcsupport_newticketbutton"):
await CreateButtonPanelCommand.OnButtonUsed(e.Interaction); await CreateButtonPanelCommand.OnButtonUsed(e.Interaction);
return; return;
case "right": case "right":
@ -224,13 +234,13 @@ internal static class EventHandler
Logger.Warn("Unknown button press received! '" + e.Id + "'"); Logger.Warn("Unknown button press received! '" + e.Id + "'");
return; return;
} }
case ComponentType.Select: case ComponentType.StringSelect:
switch (e.Id) switch (e.Id)
{ {
case {} when e.Id.StartsWith("breadcraft_newcommandselector"): case { } when e.Id.StartsWith("bcsupport_newcommandselector"):
await NewCommand.OnCategorySelection(e.Interaction); await NewCommand.OnCategorySelection(e.Interaction);
return; return;
case {} when e.Id.StartsWith("breadcraft_newticketselector"): case { } when e.Id.StartsWith("bcsupport_newticketselector"):
await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction); await CreateSelectionBoxPanelCommand.OnSelectionMenuUsed(e.Interaction);
return; return;
default: default: