Added comments to the BotSettings.cs

This commit is contained in:
Chris Darnell committed 2021-04-19 18:47:48 -07:00
1 parent cb75dc1f5a
commit 8b9f1dc850
1 file changed
+21 -11
+21 -11
View File
@@ -23,6 +23,7 @@ using System.Threading;
namespace StarsiegeBot namespace StarsiegeBot
{ {
[Group("bot")] [Group("bot")]
[Description("Allows, viewing and editing settings on the bot.")]
class BotSettings : BaseCommandModule class BotSettings : BaseCommandModule
{ {
public static Dictionary<string, GuildSettings> GuildSettings; public static Dictionary<string, GuildSettings> GuildSettings;
@@ -30,8 +31,10 @@ namespace StarsiegeBot
public BotSettings() public BotSettings()
{ {
Console.WriteLine("Bot Setting Commands Loaded"); Console.WriteLine("Bot Setting Commands Loaded");
// Check for guild settings file. If it doesnt exist, create it.
if (!File.Exists("guildSettings.json")) if (!File.Exists("guildSettings.json"))
{ {
// Since we need to creat it, we're going to set some default stuff.
Console.Write("Guild Settings Config File Not Found. Creating One..."); Console.Write("Guild Settings Config File Not Found. Creating One...");
GuildSettings item = new GuildSettings(); GuildSettings item = new GuildSettings();
item.UseAutoRoles = false; item.UseAutoRoles = false;
@@ -52,36 +55,40 @@ namespace StarsiegeBot
{ "default", item } { "default", item }
}; };
// Now that we have the initial stuff in memory, write it to file.
string output = JsonConvert.SerializeObject(GuildSettings); string output = JsonConvert.SerializeObject(GuildSettings);
File.WriteAllTextAsync("guildSettings.json", output); File.WriteAllTextAsync("guildSettings.json", output);
// in form the console reader that we're done making the initial config.
Console.WriteLine(" Done!"); Console.WriteLine(" Done!");
} }
var json = ""; else
using (var fs = File.OpenRead("guildSettings.json")) {
using (var sr = new StreamReader(fs, new UTF8Encoding(false))) // load the config file to memory.
json = sr.ReadToEnd(); var json = "";
using (var fs = File.OpenRead("guildSettings.json"))
GuildSettings = JsonConvert.DeserializeObject<Dictionary<string, GuildSettings>>(json); using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
GuildSettings = JsonConvert.DeserializeObject<Dictionary<string, GuildSettings>>(json);
}
} }
[Group("Prefix")] [Group("Prefix")]
class BotPrefix : BotSettings class BotPrefix : BotSettings
{ {
public BotPrefix()
{
}
[GroupCommand] [GroupCommand]
public async Task GetPrefixes(CommandContext ctx) public async Task GetPrefixes(CommandContext ctx)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
var guild = ctx.Guild.Id.ToString(); // store the Guild ID as a string.
string guild = ctx.Guild.Id.ToString();
// if this server doesnt have a settings for whatever reason, let them know... why am i not creating it?
if (! GuildSettings.ContainsKey(guild)) if (! GuildSettings.ContainsKey(guild))
{ {
await ctx.RespondAsync("No guild settings found."); await ctx.RespondAsync("No guild settings found.");
} }
else else
{ {
// we have server settings... why does this give so much info? it should only show only prefix(es)
var server = GuildSettings[guild]; var server = GuildSettings[guild];
DiscordEmbedBuilder embed = new DiscordEmbedBuilder DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{ {
@@ -96,6 +103,7 @@ namespace StarsiegeBot
} }
} }
[Command("Add")] [Command("Add")]
[Description("Adds a new prefix to the Server's list of prefixes.")]
public async Task AddNewPrefix (CommandContext ctx, string prefix) public async Task AddNewPrefix (CommandContext ctx, string prefix)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
@@ -104,6 +112,7 @@ namespace StarsiegeBot
} }
[Command("delete"), Aliases("del")] [Command("delete"), Aliases("del")]
[Description("Removes the specified prefix from accepted prefixes.")]
public async Task RemovePrefix (CommandContext ctx, string prefix) public async Task RemovePrefix (CommandContext ctx, string prefix)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();
@@ -112,6 +121,7 @@ namespace StarsiegeBot
} }
[Command("global"), Aliases("g")] [Command("global"), Aliases("g")]
[Description("View or edit the status of allowing Global Prefix(es).")]
public async Task UseGlobalPrefixes(CommandContext ctx, bool isEnabled) public async Task UseGlobalPrefixes(CommandContext ctx, bool isEnabled)
{ {
await ctx.TriggerTypingAsync(); await ctx.TriggerTypingAsync();