From 91d6d1531b294fac1b01c84621d91baf758822a9 Mon Sep 17 00:00:00 2001 From: Christopher Darnell Date: Thu, 6 May 2021 13:58:01 -0700 Subject: [PATCH] Converted all filename location variables to static. --- StarsiegeBot/BotSettings.cs | 10 +++++----- StarsiegeBot/Starsiege/QuickchatHandler.cs | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/StarsiegeBot/BotSettings.cs b/StarsiegeBot/BotSettings.cs index 99284c3..30b13db 100644 --- a/StarsiegeBot/BotSettings.cs +++ b/StarsiegeBot/BotSettings.cs @@ -18,7 +18,7 @@ namespace StarsiegeBot class BotSettings : BaseCommandModule { public static Dictionary GuildSettings; - private readonly string _fileName = "Json/guildsettings.json"; + private static readonly string s_fileName = "Json/guildsettings.json"; private readonly CancellationTokenSource _cancelToken; public BotSettings() { @@ -30,7 +30,7 @@ namespace StarsiegeBot return; } // Check for guild settings file. If it doesnt exist, create it. - if (!File.Exists(_fileName)) + if (!File.Exists(s_fileName)) { // Since we need to creat it, we're going to set some default stuff. Console.Write("Guild Settings Config File Not Found. Creating One..."); @@ -57,7 +57,7 @@ namespace StarsiegeBot // Now that we have the initial stuff in memory, write it to file. string output = JsonConvert.SerializeObject(GuildSettings); - File.WriteAllTextAsync(_fileName, output); + File.WriteAllTextAsync(s_fileName, output); // in form the console reader that we're done making the initial config. Console.WriteLine(" Done!"); } @@ -65,7 +65,7 @@ namespace StarsiegeBot { // load the config file to memory. string json = ""; - using (FileStream fs = File.OpenRead(_fileName)) + using (FileStream fs = File.OpenRead(s_fileName)) using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false))) json = sr.ReadToEnd(); GuildSettings = JsonConvert.DeserializeObject>(json); @@ -128,7 +128,7 @@ namespace StarsiegeBot while (true) { string output = JsonConvert.SerializeObject(GuildSettings); - await File.WriteAllTextAsync(_fileName, output); + await File.WriteAllTextAsync(s_fileName, output); await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken); if (cancellationToken.IsCancellationRequested) { diff --git a/StarsiegeBot/Starsiege/QuickchatHandler.cs b/StarsiegeBot/Starsiege/QuickchatHandler.cs index da15575..64f451c 100644 --- a/StarsiegeBot/Starsiege/QuickchatHandler.cs +++ b/StarsiegeBot/Starsiege/QuickchatHandler.cs @@ -18,7 +18,7 @@ namespace StarsiegeBot { private Dictionary _quickchats; private bool _isEnabled; - private readonly string _fileName = "Json/quickchats.json"; + private static readonly string s_fileName = "Json/quickchats.json"; public QuickchatHandler() @@ -34,11 +34,11 @@ namespace StarsiegeBot private bool LoadQuickChatsImpl() { // Check to see if the file exists... - if (File.Exists(_fileName)) + if (File.Exists(s_fileName)) { // Load the JSON file. string json = ""; - using (FileStream fs = File.OpenRead(_fileName)) + using (FileStream fs = File.OpenRead(s_fileName)) using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false))) json = sr.ReadToEnd(); _quickchats = JsonConvert.DeserializeObject>(json); @@ -272,7 +272,7 @@ namespace StarsiegeBot embed = StartEmbed($"Flagging QC ID `{id}` with reason of `{flagReason}`. (F{chat.Flags.Count})"); chat.IsFlagged = true; string output = JsonConvert.SerializeObject(_quickchats); - await File.WriteAllTextAsync(_fileName, output); + await File.WriteAllTextAsync(s_fileName, output); await ctx.RespondAsync(embed); } @@ -303,7 +303,7 @@ namespace StarsiegeBot string[] turnOn = { "on", "true", "1" }; string[] turnOff = { "off", "false", "0" }; - if (File.Exists(_fileName)) + if (File.Exists(s_fileName)) { if (turnOn.Contains(isEnabled)) { @@ -319,7 +319,7 @@ namespace StarsiegeBot else { _isEnabled = false; - output = $"{_fileName} file is missing, and it can not be enabled."; + output = $"{s_fileName} file is missing, and it can not be enabled."; } await ctx.RespondAsync(StartEmbed(output)); }