Converted all filename location variables to static.
This commit is contained in:
1 parent
1e3e8eb69b
commit
91d6d1531b
2 files changed
+11
-11
No files matched your search
@@ -18,7 +18,7 @@ namespace StarsiegeBot
|
|||||||
class BotSettings : BaseCommandModule
|
class BotSettings : BaseCommandModule
|
||||||
{
|
{
|
||||||
public static Dictionary<string, GuildSettings> GuildSettings;
|
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;
|
private readonly CancellationTokenSource _cancelToken;
|
||||||
public BotSettings()
|
public BotSettings()
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ namespace StarsiegeBot
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check for guild settings file. If it doesnt exist, create it.
|
// 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.
|
// 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...");
|
||||||
@@ -57,7 +57,7 @@ namespace StarsiegeBot
|
|||||||
|
|
||||||
// Now that we have the initial stuff in memory, write it to file.
|
// 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(_fileName, output);
|
File.WriteAllTextAsync(s_fileName, output);
|
||||||
// in form the console reader that we're done making the initial config.
|
// in form the console reader that we're done making the initial config.
|
||||||
Console.WriteLine(" Done!");
|
Console.WriteLine(" Done!");
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ namespace StarsiegeBot
|
|||||||
{
|
{
|
||||||
// load the config file to memory.
|
// load the config file to memory.
|
||||||
string json = "";
|
string json = "";
|
||||||
using (FileStream fs = File.OpenRead(_fileName))
|
using (FileStream fs = File.OpenRead(s_fileName))
|
||||||
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
|
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||||
json = sr.ReadToEnd();
|
json = sr.ReadToEnd();
|
||||||
GuildSettings = JsonConvert.DeserializeObject<Dictionary<string, GuildSettings>>(json);
|
GuildSettings = JsonConvert.DeserializeObject<Dictionary<string, GuildSettings>>(json);
|
||||||
@@ -128,7 +128,7 @@ namespace StarsiegeBot
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
string output = JsonConvert.SerializeObject(GuildSettings);
|
string output = JsonConvert.SerializeObject(GuildSettings);
|
||||||
await File.WriteAllTextAsync(_fileName, output);
|
await File.WriteAllTextAsync(s_fileName, output);
|
||||||
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
|
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace StarsiegeBot
|
|||||||
{
|
{
|
||||||
private Dictionary<string, Quickchat> _quickchats;
|
private Dictionary<string, Quickchat> _quickchats;
|
||||||
private bool _isEnabled;
|
private bool _isEnabled;
|
||||||
private readonly string _fileName = "Json/quickchats.json";
|
private static readonly string s_fileName = "Json/quickchats.json";
|
||||||
|
|
||||||
|
|
||||||
public QuickchatHandler()
|
public QuickchatHandler()
|
||||||
@@ -34,11 +34,11 @@ namespace StarsiegeBot
|
|||||||
private bool LoadQuickChatsImpl()
|
private bool LoadQuickChatsImpl()
|
||||||
{
|
{
|
||||||
// Check to see if the file exists...
|
// Check to see if the file exists...
|
||||||
if (File.Exists(_fileName))
|
if (File.Exists(s_fileName))
|
||||||
{
|
{
|
||||||
// Load the JSON file.
|
// Load the JSON file.
|
||||||
string json = "";
|
string json = "";
|
||||||
using (FileStream fs = File.OpenRead(_fileName))
|
using (FileStream fs = File.OpenRead(s_fileName))
|
||||||
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
|
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||||
json = sr.ReadToEnd();
|
json = sr.ReadToEnd();
|
||||||
_quickchats = JsonConvert.DeserializeObject<Dictionary<string, Quickchat>>(json);
|
_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})");
|
embed = StartEmbed($"Flagging QC ID `{id}` with reason of `{flagReason}`. (F{chat.Flags.Count})");
|
||||||
chat.IsFlagged = true;
|
chat.IsFlagged = true;
|
||||||
string output = JsonConvert.SerializeObject(_quickchats);
|
string output = JsonConvert.SerializeObject(_quickchats);
|
||||||
await File.WriteAllTextAsync(_fileName, output);
|
await File.WriteAllTextAsync(s_fileName, output);
|
||||||
|
|
||||||
await ctx.RespondAsync(embed);
|
await ctx.RespondAsync(embed);
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ namespace StarsiegeBot
|
|||||||
string[] turnOn = { "on", "true", "1" };
|
string[] turnOn = { "on", "true", "1" };
|
||||||
string[] turnOff = { "off", "false", "0" };
|
string[] turnOff = { "off", "false", "0" };
|
||||||
|
|
||||||
if (File.Exists(_fileName))
|
if (File.Exists(s_fileName))
|
||||||
{
|
{
|
||||||
if (turnOn.Contains(isEnabled))
|
if (turnOn.Contains(isEnabled))
|
||||||
{
|
{
|
||||||
@@ -319,7 +319,7 @@ namespace StarsiegeBot
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
_isEnabled = false;
|
_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));
|
await ctx.RespondAsync(StartEmbed(output));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user