Added the ability to enable/disable the discord bot via settings.json

This commit is contained in:
TheUbMunster 2023-07-12 23:46:12 -06:00
parent a5b834834c
commit ba1a283c92
2 changed files with 7 additions and 4 deletions

View File

@ -30,9 +30,10 @@ public class DiscordBot
Init(); Init();
#pragma warning restore CS4014 #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; Settings.LoadHandler += OnLoadSettings;
Logger.AddLogHandler(LogToDiscordLogChannel); Logger.AddLogHandler(LogToDiscordLogChannel);
} }
@ -54,9 +55,10 @@ public class DiscordBot
private async Task Init() 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)) if (localSettings.Token == null || (localSettings.AdminChannel == null && localSettings.CommandChannel == null))
{ {

View File

@ -71,6 +71,7 @@ public class Settings {
} }
public class DiscordTable { public class DiscordTable {
public bool Enabled { get; set; } = true;
public string? Token { get; set; } public string? Token { get; set; }
public string Prefix { get; set; } = "$"; public string Prefix { get; set; } = "$";
public string? CommandChannel { get; set; } public string? CommandChannel { get; set; }