public MonikaBot() { if (!File.Exists("config.json")) //check if the configuration file exists { new MonikaBotConfig().WriteConfig("config.json"); Console.WriteLine("Please edit the config file!"); return; } /// Load config config = new MonikaBotConfig(); config = config.LoadConfig("config.json"); /// Verify parts of the config if (config.Token == MonikaBotConfig.BlankTokenString) //this is static so I have to reference by class name vs. an instance of the class. { Console.WriteLine("Please edit the config file!"); return; } if (config.OwnerID == MonikaBotConfig.BlankOwnerIDString || String.IsNullOrEmpty(config.OwnerID)) { SetupMode = true; AuthorizationCode = RandomCodeGenerator.GenerateRandomCode(10); Log(LogLevel.Warning, $"Bot is in setup mode. Please type this command in a channel the bot has access to: \n {config.Prefix}authenticate {AuthorizationCode}\n"); } /// Setup the Client DiscordConfiguration dConfig = new DiscordConfiguration { AutoReconnect = true, LogLevel = LogLevel.Debug, Token = config.Token, TokenType = TokenType.Bot, UseInternalLogHandler = true }; client = new DiscordClient(dConfig); Log(LogLevel.Info, "OS: " + OperatingSystemDetermination.GetUnixName()); if (OperatingSystemDetermination.GetUnixName().Contains("Windows 7") || OperatingSystemDetermination.IsOnMac() || OperatingSystemDetermination.IsOnUnix()) { Log(LogLevel.Info, "On macOS, Windows 7, or Unix; using WebSocket4Net"); //only do this on windows 7 or Unix systems client.SetWebSocketClient <DSharpPlus.Net.WebSocket.WebSocket4NetClient>(); } }
public void Dispose() { Log(LogLevel.Info, "Shutting down!"); File.WriteAllText("settings.json", JsonConvert.SerializeObject(config)); commandManager.Dispose(); if (CommandsManager.UserRoles != null && CommandsManager.UserRoles.Count > 0) { File.WriteAllText("permissions.json", JsonConvert.SerializeObject(CommandsManager.UserRoles)); } if (client != null) { client.Dispose(); } config = null; }