From ba1a283c929a1e93f44e53e741f8295672c05bce Mon Sep 17 00:00:00 2001 From: TheUbMunster Date: Wed, 12 Jul 2023 23:46:12 -0600 Subject: [PATCH] Added the ability to enable/disable the discord bot via settings.json --- Server/DiscordBot.cs | 10 ++++++---- Server/Settings.cs | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Server/DiscordBot.cs b/Server/DiscordBot.cs index 477bdf9..8200569 100644 --- a/Server/DiscordBot.cs +++ b/Server/DiscordBot.cs @@ -30,9 +30,10 @@ public class DiscordBot Init(); #pragma warning restore CS4014 }); - return "Restarting Discord bot..."; + return localSettings.Enabled ? "Restarting Discord bot..." : "The discord bot is disabled in settings.json (no action was taken)."; }); - logger.Info("Starting discord bot (ctor)"); + if (localSettings.Enabled) + logger.Info("Starting discord bot (ctor)"); Settings.LoadHandler += OnLoadSettings; Logger.AddLogHandler(LogToDiscordLogChannel); } @@ -54,9 +55,10 @@ public class DiscordBot private async Task Init() { - if (client != null) + if (client != null || !localSettings.Enabled) { - return; //this is bad if the client ever crashes and isn't reassigned to null, but we don't want multiple instances of the bot running at the same time. + return; //Either: the discord bot is disabled, or: this is bad if the client ever crashes and + //isn't reassigned to null, but we don't want multiple instances of the bot running at the same time. } if (localSettings.Token == null || (localSettings.AdminChannel == null && localSettings.CommandChannel == null)) { diff --git a/Server/Settings.cs b/Server/Settings.cs index c89b275..25a6e4c 100644 --- a/Server/Settings.cs +++ b/Server/Settings.cs @@ -71,6 +71,7 @@ public class Settings { } public class DiscordTable { + public bool Enabled { get; set; } = true; public string? Token { get; set; } public string Prefix { get; set; } = "$"; public string? CommandChannel { get; set; }