From c9180130f95ff9181ee55515a00604b4024001ea Mon Sep 17 00:00:00 2001 From: EmotionChild Date: Wed, 18 May 2022 01:11:57 +1200 Subject: [PATCH] More stuff updated --- SupportChild.sln | 19 +- SupportChild/Config.cs | 232 ++++++++++++------------ SupportChild/Properties/Resources.resx | 242 ++++++++++++------------- SupportChild/SupportChild.cs | 24 +-- SupportChild/SupportChild.csproj | 130 ++++++------- SupportChild/Transcriber.cs | 2 +- SupportChild/Utilities.cs | 10 +- 7 files changed, 325 insertions(+), 334 deletions(-) diff --git a/SupportChild.sln b/SupportChild.sln index cc9d1b4..098a159 100644 --- a/SupportChild.sln +++ b/SupportChild.sln @@ -1,9 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.32126.317 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SupportChild", "SupportChild\SupportChild.csproj", "{9124DF58-D261-4906-8ECA-D853DEBE07D4}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SupportChild", "SupportChild\SupportChild.csproj", "{B043AACB-D763-4C61-9524-C8B7C58DA3EF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,15 +8,9 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9124DF58-D261-4906-8ECA-D853DEBE07D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9124DF58-D261-4906-8ECA-D853DEBE07D4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9124DF58-D261-4906-8ECA-D853DEBE07D4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9124DF58-D261-4906-8ECA-D853DEBE07D4}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B2CD3447-A8BA-4B02-9E08-A75CBBD2BDCB} + {B043AACB-D763-4C61-9524-C8B7C58DA3EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B043AACB-D763-4C61-9524-C8B7C58DA3EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B043AACB-D763-4C61-9524-C8B7C58DA3EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B043AACB-D763-4C61-9524-C8B7C58DA3EF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/SupportChild/Config.cs b/SupportChild/Config.cs index 7682597..858e17b 100644 --- a/SupportChild/Config.cs +++ b/SupportChild/Config.cs @@ -10,134 +10,134 @@ using YamlDotNet.Serialization; namespace SupportChild { - internal static class Config - { - internal static string token = ""; - internal static string prefix = ""; - internal static ulong logChannel; - internal static ulong ticketCategory; - internal static ulong reactionMessage; - internal static string welcomeMessage = ""; - internal static string logLevel = "Information"; - internal static string timestampFormat = "yyyy-MMM-dd HH:mm"; - internal static bool randomAssignment = false; - internal static bool randomAssignRoleOverride = false; // TODO: Implement - internal static string presenceType = "Playing"; - internal static string presenceText = ""; + internal static class Config + { + internal static string token = ""; + internal static string prefix = ""; + internal static ulong logChannel; + internal static ulong ticketCategory; + internal static ulong reactionMessage; + internal static string welcomeMessage = ""; + internal static string logLevel = "Information"; + internal static string timestampFormat = "yyyy-MMM-dd HH:mm"; + internal static bool randomAssignment = false; + internal static bool randomAssignRoleOverride = false; + internal static string presenceType = "Playing"; + internal static string presenceText = ""; - internal static bool ticketUpdatedNotifications = false; - internal static double ticketUpdatedNotificationDelay = 0.0; - internal static bool assignmentNotifications = false; - internal static bool closingNotifications = false; + internal static bool ticketUpdatedNotifications = false; + internal static double ticketUpdatedNotificationDelay = 0.0; + internal static bool assignmentNotifications = false; + internal static bool closingNotifications = false; - internal static string hostName = "127.0.0.1"; - internal static int port = 3306; - internal static string database = "supportbot"; - internal static string username = "supportbot"; - internal static string password = ""; + internal static string hostName = "127.0.0.1"; + internal static int port = 3306; + internal static string database = "supportbot"; + internal static string username = "supportbot"; + internal static string password = ""; - private static readonly Dictionary permissions = new Dictionary - { + private static readonly Dictionary permissions = new Dictionary + { // Public commands - { "close", new ulong[]{ } }, - { "list", new ulong[]{ } }, - { "new", new ulong[]{ } }, - { "say", new ulong[]{ } }, - { "status", new ulong[]{ } }, - { "summary", new ulong[]{ } }, - { "transcript", new ulong[]{ } }, + { "close", new ulong[]{ } }, + { "list", new ulong[]{ } }, + { "new", new ulong[]{ } }, + { "say", new ulong[]{ } }, + { "status", new ulong[]{ } }, + { "summary", new ulong[]{ } }, + { "transcript", new ulong[]{ } }, // Moderator commands - { "add", new ulong[]{ } }, - { "addmessage", new ulong[]{ } }, - { "assign", new ulong[]{ } }, - { "blacklist", new ulong[]{ } }, - { "listassigned", new ulong[]{ } }, - { "listoldest", new ulong[]{ } }, - { "listunassigned", new ulong[]{ } }, - { "move", new ulong[]{ } }, - { "rassign", new ulong[]{ } }, - { "removemessage", new ulong[]{ } }, - { "setsummary", new ulong[]{ } }, - { "toggleactive", new ulong[]{ } }, - { "unassign", new ulong[]{ } }, - { "unblacklist", new ulong[]{ } }, + { "add", new ulong[]{ } }, + { "addmessage", new ulong[]{ } }, + { "assign", new ulong[]{ } }, + { "blacklist", new ulong[]{ } }, + { "listassigned", new ulong[]{ } }, + { "listoldest", new ulong[]{ } }, + { "listunassigned", new ulong[]{ } }, + { "move", new ulong[]{ } }, + { "rassign", new ulong[]{ } }, + { "removemessage", new ulong[]{ } }, + { "setsummary", new ulong[]{ } }, + { "toggleactive", new ulong[]{ } }, + { "unassign", new ulong[]{ } }, + { "unblacklist", new ulong[]{ } }, // Admin commands - { "addstaff", new ulong[]{ } }, - { "reload", new ulong[]{ } }, - { "removestaff", new ulong[]{ } }, - { "setticket", new ulong[]{ } }, - { "unsetticket", new ulong[]{ } }, - }; + { "addstaff", new ulong[]{ } }, + { "reload", new ulong[]{ } }, + { "removestaff", new ulong[]{ } }, + { "setticket", new ulong[]{ } }, + { "unsetticket", new ulong[]{ } }, + }; + + public static void LoadConfig() + { + // Writes default config to file if it does not already exist + if (!File.Exists("./config.yml")) + { + File.WriteAllText("./config.yml", Encoding.UTF8.GetString(Resources.default_config)); + } - public static void LoadConfig() - { - // Writes default config to file if it does not already exist - if (!File.Exists("./config.yml")) - { - File.WriteAllText("./config.yml", Encoding.UTF8.GetString(Resources.default_config)); - } + // Reads config contents into FileStream + FileStream stream = File.OpenRead("./config.yml"); - // Reads config contents into FileStream - FileStream stream = File.OpenRead("./config.yml"); + // Converts the FileStream into a YAML object + IDeserializer deserializer = new DeserializerBuilder().Build(); + object yamlObject = deserializer.Deserialize(new StreamReader(stream)); - // Converts the FileStream into a YAML object - IDeserializer deserializer = new DeserializerBuilder().Build(); - object yamlObject = deserializer.Deserialize(new StreamReader(stream)); + // Converts the YAML object into a JSON object as the YAML ones do not support traversal or selection of nodes by name + ISerializer serializer = new SerializerBuilder().JsonCompatible().Build(); + JObject json = JObject.Parse(serializer.Serialize(yamlObject)); - // Converts the YAML object into a JSON object as the YAML ones do not support traversal or selection of nodes by name - ISerializer serializer = new SerializerBuilder().JsonCompatible().Build(); - JObject json = JObject.Parse(serializer.Serialize(yamlObject)); + // Sets up the bot + token = json.SelectToken("bot.token").Value() ?? ""; + prefix = json.SelectToken("bot.prefix").Value() ?? ""; + logChannel = json.SelectToken("bot.log-channel").Value(); + ticketCategory = json.SelectToken("bot.ticket-category")?.Value() ?? 0; + reactionMessage = json.SelectToken("bot.reaction-message")?.Value() ?? 0; + welcomeMessage = json.SelectToken("bot.welcome-message").Value() ?? ""; + logLevel = json.SelectToken("bot.console-log-level").Value() ?? ""; + timestampFormat = json.SelectToken("bot.timestamp-format").Value() ?? "yyyy-MM-dd HH:mm"; + randomAssignment = json.SelectToken("bot.random-assignment")?.Value() ?? false; + randomAssignRoleOverride = json.SelectToken("bot.random-assign-role-override")?.Value() ?? false; + presenceType = json.SelectToken("bot.presence-type")?.Value() ?? "Playing"; + presenceText = json.SelectToken("bot.presence-text")?.Value() ?? ""; - // Sets up the bot - token = json.SelectToken("bot.token").Value() ?? ""; - prefix = json.SelectToken("bot.prefix").Value() ?? ""; - logChannel = json.SelectToken("bot.log-channel").Value(); - ticketCategory = json.SelectToken("bot.ticket-category")?.Value() ?? 0; - reactionMessage = json.SelectToken("bot.reaction-message")?.Value() ?? 0; - welcomeMessage = json.SelectToken("bot.welcome-message").Value() ?? ""; - logLevel = json.SelectToken("bot.console-log-level").Value() ?? ""; - timestampFormat = json.SelectToken("bot.timestamp-format").Value() ?? "yyyy-MM-dd HH:mm"; - randomAssignment = json.SelectToken("bot.random-assignment")?.Value() ?? false; - randomAssignRoleOverride = json.SelectToken("bot.random-assign-role-override")?.Value() ?? false; - presenceType = json.SelectToken("bot.presence-type")?.Value() ?? "Playing"; - presenceText = json.SelectToken("bot.presence-text")?.Value() ?? ""; + ticketUpdatedNotifications = json.SelectToken("notifications.ticket-updated")?.Value() ?? false; + ticketUpdatedNotificationDelay = json.SelectToken("notifications.ticket-updated-delay")?.Value() ?? 0.0; + assignmentNotifications = json.SelectToken("notifications.assignment")?.Value() ?? false; + closingNotifications = json.SelectToken("notifications.closing")?.Value() ?? false; - ticketUpdatedNotifications = json.SelectToken("notifications.ticket-updated")?.Value() ?? false; - ticketUpdatedNotificationDelay = json.SelectToken("notifications.ticket-updated-delay")?.Value() ?? 0.0; - assignmentNotifications = json.SelectToken("notifications.assignment")?.Value() ?? false; - closingNotifications = json.SelectToken("notifications.closing")?.Value() ?? false; + // Reads database info + hostName = json.SelectToken("database.address")?.Value() ?? ""; + port = json.SelectToken("database.port")?.Value() ?? 3306; + database = json.SelectToken("database.name")?.Value() ?? "supportchild"; + username = json.SelectToken("database.user")?.Value() ?? "supportchild"; + password = json.SelectToken("database.password")?.Value() ?? ""; - // Reads database info - hostName = json.SelectToken("database.address")?.Value() ?? ""; - port = json.SelectToken("database.port")?.Value() ?? 3306; - database = json.SelectToken("database.name")?.Value() ?? "supportbot"; - username = json.SelectToken("database.user")?.Value() ?? "supportbot"; - password = json.SelectToken("database.password")?.Value() ?? ""; + timestampFormat = timestampFormat.Trim(); - timestampFormat = timestampFormat.Trim(); + foreach (KeyValuePair node in permissions.ToList()) + { + try + { + permissions[node.Key] = json.SelectToken("permissions." + node.Key).Value().Values().ToArray(); + } + catch (ArgumentNullException) + { + Console.WriteLine("Permission node '" + node.Key + "' was not found in the config, using default value: []"); + } + } + } - foreach (KeyValuePair node in permissions.ToList()) - { - try - { - permissions[node.Key] = json.SelectToken("permissions." + node.Key).Value().Values().ToArray(); - } - catch (ArgumentNullException) - { - Console.WriteLine("Permission node '" + node.Key + "' was not found in the config, using default value: []"); - } - } - } - - /// - /// Checks whether a user has a specific permission. - /// - /// The Discord user to check. - /// The permission name to check. - /// - public static bool HasPermission(DiscordMember member, string permission) - { - return member.Roles.Any(role => permissions[permission].Contains(role.Id)) || permissions[permission].Contains(member.Guild.Id); - } - } -} + /// + /// Checks whether a user has a specific permission. + /// + /// The Discord user to check. + /// The permission name to check. + /// + public static bool HasPermission(DiscordMember member, string permission) + { + return member.Roles.Any(role => permissions[permission].Contains(role.Id)) || permissions[permission].Contains(member.Guild.Id); + } + } +} \ No newline at end of file diff --git a/SupportChild/Properties/Resources.resx b/SupportChild/Properties/Resources.resx index 2beadd9..8edc7ae 100644 --- a/SupportChild/Properties/Resources.resx +++ b/SupportChild/Properties/Resources.resx @@ -1,124 +1,124 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\default_config.yml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - [base64 mime encoded string representing a byte array form of the .NET Framework object] - This is a comment - - - There are any number of "resheader" rows that contain simple - name/value pairs. - - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the - mimetype set. - - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not - extensible. For a given mimetype the value must be set accordingly: - - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can - read any of the formats listed below. - - mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Soap.SoapFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array - : using a System.ComponentModel.TypeConverter - : and then encoded with base64 encoding. - --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - ..\default_config.yml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/SupportChild/SupportChild.cs b/SupportChild/SupportChild.cs index 9a75aad..3f3c1b2 100644 --- a/SupportChild/SupportChild.cs +++ b/SupportChild/SupportChild.cs @@ -25,7 +25,7 @@ namespace SupportChild private async Task MainAsync() { instance = this; - + Console.WriteLine("Starting SupportChild version " + GetVersion() + "..."); try { @@ -61,10 +61,10 @@ namespace SupportChild this.discordClient.Dispose(); Console.WriteLine("Discord client disconnected."); } - + Console.WriteLine("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\""); Config.LoadConfig(); - + // Check if token is unset if (Config.token == "" || Config.token == "") { @@ -84,16 +84,16 @@ namespace SupportChild Console.WriteLine("Could not set up database tables, please confirm connection settings, status of the server and permissions of MySQL user. Error: " + e); throw; } - + Console.WriteLine("Setting up Discord client..."); - + // Checking log level if (!Enum.TryParse(Config.logLevel, true, out LogLevel logLevel)) { Console.WriteLine("Log level '" + Config.logLevel + "' invalid, using 'Information' instead."); logLevel = LogLevel.Information; } - + // Setting up client configuration DiscordConfiguration cfg = new DiscordConfiguration { @@ -103,11 +103,11 @@ namespace SupportChild AutoReconnect = true, Intents = DiscordIntents.All }; - + this.discordClient = new DiscordClient(cfg); - + this.eventHandler = new EventHandler(this.discordClient); - + Console.WriteLine("Hooking events..."); this.discordClient.Ready += this.eventHandler.OnReady; this.discordClient.GuildAvailable += this.eventHandler.OnGuildAvailable; @@ -119,11 +119,11 @@ namespace SupportChild { this.discordClient.MessageReactionAdded += this.eventHandler.OnReactionAdded; } - + Console.WriteLine("Registering commands..."); commands = discordClient.UseCommandsNext(new CommandsNextConfiguration { - StringPrefixes = new[] { Config.prefix } + StringPrefixes = new []{ Config.prefix } }); this.commands.RegisterCommands(); @@ -160,4 +160,4 @@ namespace SupportChild await this.discordClient.ConnectAsync(); } } -} +} \ No newline at end of file diff --git a/SupportChild/SupportChild.csproj b/SupportChild/SupportChild.csproj index 3702a8a..5b31187 100644 --- a/SupportChild/SupportChild.csproj +++ b/SupportChild/SupportChild.csproj @@ -1,70 +1,70 @@ - - - - Exe - ellie_icon.ico - net6.0 - win-x64;linux-x64 - 1.2.0 - SupportChild.SupportChild - EmotionChild - - https://github.com/EmotionChild/SupportChild - https://github.com/EmotionChild/SupportChild - Git - LICENSE - https://cdn.emotionchild.com/Ellie.png - A Discord support bot build for the Ellie's Home Discord server - 2.6.1.1 - 2.6.1.1 - en - 1.2.0 - - - - - - - - - - - - - - - - - - - True - True - Resources.resx - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - + - - - True - - - + + Exe + ellie_icon.ico + net6.0 + win-x64;linux-x64 + 1.2.0 + SupportChild.SupportChild + EmotionChild + + https://github.com/EmotionChild/SupportChild + https://github.com/EmotionChild/SupportChild + Git + LICENSE + https://cdn.emotionchild.com/Ellie.png + A Discord support bot build for the Ellie's Home Discord server + 2.6.1.1 + 2.6.1.1 + en + 1.2.0 + - - - + + + + + + + + + + + + + - - - lib\DiscordChatExporter.Core.dll - - + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + True + + + + + + + + + + + lib\DiscordChatExporter.Core.dll + + diff --git a/SupportChild/Transcriber.cs b/SupportChild/Transcriber.cs index 8ab68af..9b10e62 100644 --- a/SupportChild/Transcriber.cs +++ b/SupportChild/Transcriber.cs @@ -59,4 +59,4 @@ namespace SupportChild return "ticket-" + ticketNumber.ToString("00000") + ".html"; } } -} +} \ No newline at end of file diff --git a/SupportChild/Utilities.cs b/SupportChild/Utilities.cs index dce74be..06099d1 100644 --- a/SupportChild/Utilities.cs +++ b/SupportChild/Utilities.cs @@ -15,8 +15,8 @@ namespace SupportChild { byte[] box = new byte[1]; do provider.GetBytes(box); - while (!(box[0] < n * (byte.MaxValue / n))); - int k = box[0] % n; + while (!(box[0] < n * (Byte.MaxValue / n))); + int k = (box[0] % n); n--; T value = list[k]; list[k] = list[n]; @@ -32,11 +32,11 @@ namespace SupportChild { return new string[0]; } - return args.Trim().Replace("<@!", "").Replace("<@", "").Replace(">", "").Split(); + return args.Trim().Replace("<@!", "").Replace("<@", "").Replace(">", "").Split(); } public static LinkedList ParseListIntoMessages(List listItems) - { + { LinkedList messages = new LinkedList(); foreach (string listItem in listItems) @@ -68,4 +68,4 @@ namespace SupportChild return null; } } -} +} \ No newline at end of file