diff --git a/SupportChild/SupportChild.cs b/SupportChild/SupportChild.cs index 806630e..9a75aad 100644 --- a/SupportChild/SupportChild.cs +++ b/SupportChild/SupportChild.cs @@ -9,155 +9,155 @@ using SupportChild.Commands; namespace SupportChild { - internal class SupportChild - { - internal static SupportChild instance; + internal class SupportChild + { + internal static SupportChild instance; - private DiscordClient discordClient = null; - private CommandsNextExtension commands = null; - private EventHandler eventHandler; + private DiscordClient discordClient = null; + private CommandsNextExtension commands = null; + private EventHandler eventHandler; - static void Main(string[] args) - { - new SupportChild().MainAsync().GetAwaiter().GetResult(); - } + static void Main(string[] args) + { + new SupportChild().MainAsync().GetAwaiter().GetResult(); + } - private async Task MainAsync() - { - instance = this; + private async Task MainAsync() + { + instance = this; - Console.WriteLine("Starting SupportChild version " + GetVersion() + "..."); - try - { - Reload(); + Console.WriteLine("Starting SupportChild version " + GetVersion() + "..."); + try + { + this.Reload(); - // Block this task until the program is closed. - await Task.Delay(-1); - } - catch (Exception e) - { - Console.WriteLine("Fatal error:"); - Console.WriteLine(e); - Console.ReadLine(); - } - } + // Block this task until the program is closed. + await Task.Delay(-1); + } + catch (Exception e) + { + Console.WriteLine("Fatal error:"); + Console.WriteLine(e); + Console.ReadLine(); + } + } - public static DiscordClient GetClient() - { - return instance.discordClient; - } + public static DiscordClient GetClient() + { + return instance.discordClient; + } - public static string GetVersion() - { - Version version = Assembly.GetEntryAssembly()?.GetName().Version; - return version?.Major + "." + version?.Minor + "." + version?.Build + (version?.Revision == 0 ? "" : "-" + (char)(64 + version?.Revision ?? 0)); - } + public static string GetVersion() + { + Version version = Assembly.GetEntryAssembly()?.GetName().Version; + return version?.Major + "." + version?.Minor + "." + version?.Build + (version?.Revision == 0 ? "" : "-" + (char)(64 + version?.Revision ?? 0)); + } - public async void Reload() - { - if (discordClient != null) - { - await discordClient.DisconnectAsync(); - discordClient.Dispose(); - Console.WriteLine("Discord client disconnected."); - } + public async void Reload() + { + if (this.discordClient != null) + { + await this.discordClient.DisconnectAsync(); + this.discordClient.Dispose(); + Console.WriteLine("Discord client disconnected."); + } - Console.WriteLine("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\""); - Config.LoadConfig(); + Console.WriteLine("Loading config \"" + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "config.yml\""); + Config.LoadConfig(); - // Check if token is unset - if (Config.token == "" || Config.token == "") - { - Console.WriteLine("You need to set your bot token in the config and start the bot again."); - throw new ArgumentException("Invalid Discord bot token"); - } + // Check if token is unset + if (Config.token == "" || Config.token == "") + { + Console.WriteLine("You need to set your bot token in the config and start the bot again."); + throw new ArgumentException("Invalid Discord bot token"); + } - // Database connection and setup - try - { - Console.WriteLine("Connecting to database... (" + Config.hostName + ":" + Config.port + ")"); - Database.SetConnectionString(Config.hostName, Config.port, Config.database, Config.username, Config.password); - Database.SetupTables(); - } - catch (Exception e) - { - Console.WriteLine("Could not set up database tables, please confirm connection settings, status of the server and permissions of MySQL user. Error: " + e); - throw; - } + // Database connection and setup + try + { + Console.WriteLine("Connecting to database... (" + Config.hostName + ":" + Config.port + ")"); + Database.SetConnectionString(Config.hostName, Config.port, Config.database, Config.username, Config.password); + Database.SetupTables(); + } + catch (Exception e) + { + 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..."); + 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; - } + // 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 - { - Token = Config.token, - TokenType = TokenType.Bot, - MinimumLogLevel = logLevel, - AutoReconnect = true, - Intents = DiscordIntents.All - }; + // Setting up client configuration + DiscordConfiguration cfg = new DiscordConfiguration + { + Token = Config.token, + TokenType = TokenType.Bot, + MinimumLogLevel = logLevel, + AutoReconnect = true, + Intents = DiscordIntents.All + }; - discordClient = new DiscordClient(cfg); + this.discordClient = new DiscordClient(cfg); - eventHandler = new EventHandler(discordClient); + this.eventHandler = new EventHandler(this.discordClient); - Console.WriteLine("Hooking events..."); - discordClient.Ready += eventHandler.OnReady; - discordClient.GuildAvailable += eventHandler.OnGuildAvailable; - discordClient.ClientErrored += eventHandler.OnClientError; - discordClient.MessageCreated += eventHandler.OnMessageCreated; - discordClient.GuildMemberAdded += eventHandler.OnMemberAdded; - discordClient.GuildMemberRemoved += eventHandler.OnMemberRemoved; - if (Config.reactionMessage != 0) - { - discordClient.MessageReactionAdded += eventHandler.OnReactionAdded; - } + Console.WriteLine("Hooking events..."); + this.discordClient.Ready += this.eventHandler.OnReady; + this.discordClient.GuildAvailable += this.eventHandler.OnGuildAvailable; + this.discordClient.ClientErrored += this.eventHandler.OnClientError; + this.discordClient.MessageCreated += this.eventHandler.OnMessageCreated; + this.discordClient.GuildMemberAdded += this.eventHandler.OnMemberAdded; + this.discordClient.GuildMemberRemoved += this.eventHandler.OnMemberRemoved; + if (Config.reactionMessage != 0) + { + this.discordClient.MessageReactionAdded += this.eventHandler.OnReactionAdded; + } - Console.WriteLine("Registering commands..."); - commands = discordClient.UseCommandsNext(new CommandsNextConfiguration - { - StringPrefixes = new[] { Config.prefix } - }); + Console.WriteLine("Registering commands..."); + commands = discordClient.UseCommandsNext(new CommandsNextConfiguration + { + StringPrefixes = new[] { Config.prefix } + }); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); - this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); + this.commands.RegisterCommands(); - Console.WriteLine("Hooking command events..."); - this.commands.CommandErrored += eventHandler.OnCommandError; + Console.WriteLine("Hooking command events..."); + this.commands.CommandErrored += this.eventHandler.OnCommandError; - Console.WriteLine("Connecting to Discord..."); - await discordClient.ConnectAsync(); - } - } + Console.WriteLine("Connecting to Discord..."); + await this.discordClient.ConnectAsync(); + } + } }