Converted all filename location variables to static.

This commit is contained in:
Christopher Darnell committed 2021-05-06 13:58:01 -07:00
1 parent 1e3e8eb69b
commit 91d6d1531b
2 files changed
+11 -11

No files matched your search

+5 -5
View File
@@ -18,7 +18,7 @@ namespace StarsiegeBot
class BotSettings : BaseCommandModule
{
public static Dictionary<string, GuildSettings> 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<Dictionary<string, GuildSettings>>(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)
{
+6 -6
View File
@@ -18,7 +18,7 @@ namespace StarsiegeBot
{
private Dictionary<string, Quickchat> _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<Dictionary<string, Quickchat>>(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));
}