Modified the Flag sub command of QuickChatHandler. Added '.editorconfig' and conformed majority of files to fit within it's scopes.

This commit is contained in:
Christopher Darnell authored and cmd276 committed 2021-05-06 13:53:56 -07:00
1 parent 990aca3e41
commit 1e3e8eb69b
16 files changed
+581 -330

No files matched your search

+27 -27
View File
@@ -14,31 +14,31 @@ namespace StarsiegeBot
[Group("notfact")]
class NotFacts : BaseCommandModule
{
private List<string> notfacts;
private bool IsEnabled;
private readonly string fileName = "Json/notfacts.json";
private List<string> _notfacts;
private bool _isEnabled;
private static readonly string s_fileName = "Json/notfacts.json";
public NotFacts()
{
Console.WriteLine("NotFacts Command Loaded");
IsEnabled = Load();
_isEnabled = Load();
}
[GroupCommand, Description("Get a NotFact")]
public async Task NotFact(CommandContext ctx, [Description("[Optional] A NotFact ID")] int notFactID = 0)
{
if (!IsEnabled)
if (!_isEnabled)
return;
await ctx.TriggerTypingAsync();
string output;
notFactID--;
try
{
output = notfacts[notFactID];
output = _notfacts[notFactID];
}
catch (Exception)
{
output = notfacts[Program.rnd.Next(0, notfacts.Count)];
output = _notfacts[Program.rnd.Next(0, _notfacts.Count)];
}
await ctx.RespondAsync(StartEmbed(output));
}
@@ -46,10 +46,10 @@ namespace StarsiegeBot
[Command("count"), Aliases("c"), Description("Get a count of the NotFacts")]
public async Task NotFactCount(CommandContext ctx)
{
if (!IsEnabled)
if (!_isEnabled)
return;
await ctx.TriggerTypingAsync();
await ctx.RespondAsync(StartEmbed(notfacts.Count + " NotFacts in the NotFacts Bank"));
await ctx.RespondAsync(StartEmbed(_notfacts.Count + " NotFacts in the NotFacts Bank"));
}
[Command("load"), RequireOwner, Aliases("l")]
@@ -60,14 +60,14 @@ namespace StarsiegeBot
// start the response.
DiscordEmbedBuilder embed = StartEmbed("Reloading NotFacts");
// our old setting...
embed.AddField("Old", (IsEnabled ? "Enabled" : "Disabled"));
embed.AddField("Old", (_isEnabled ? "Enabled" : "Disabled"));
// run this, we dont care about its actual results.
_ = Load();
// report our new setting.
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
embed.AddField("New", (_isEnabled ? "Enabled" : "Disabled"));
// since the only thing that *should* go wrong is a missing file, report it if thats the case.
if (!File.Exists(fileName))
embed.WithFooter($":warning: {fileName} file is missing.");
if (!File.Exists(s_fileName))
embed.WithFooter($":warning: {s_fileName} file is missing.");
// send our results.
await ctx.RespondAsync(embed);
}
@@ -83,34 +83,34 @@ namespace StarsiegeBot
string[] turnOff = { "off", "false", "0" };
//start our response.
DiscordEmbedBuilder embed = StartEmbed("NotFact Toggle");
embed.AddField("Old", (IsEnabled ? "Enabled" : "Disabled"));
embed.AddField("Old", (_isEnabled ? "Enabled" : "Disabled"));
// check for file.
if (File.Exists(fileName))
if (File.Exists(s_fileName))
{
// compare desired input against on or off values.
if (turnOn.Contains(isEnabled))
{
IsEnabled = true;
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
_isEnabled = true;
embed.AddField("New", (_isEnabled ? "Enabled" : "Disabled"));
}
else if (turnOff.Contains(isEnabled))
{
IsEnabled = false;
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
_isEnabled = false;
embed.AddField("New", (_isEnabled ? "Enabled" : "Disabled"));
}
else
{
// we dont know what they were trying to do, throw an error in the footer with a :warning: emote.
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
embed.AddField("New", (_isEnabled ? "Enabled" : "Disabled"));
embed.WithFooter(":warning: Invalid command given?");
}
}
else
{
// file is missing, disable this, regardless of their desires. Report the file is missing in the footer with a :warning:
IsEnabled = false;
embed.AddField("New", (IsEnabled ? "Enabled" : "Disabled"));
embed.WithFooter($":warning: {fileName} file is missing, and it can not be enabled.");
_isEnabled = false;
embed.AddField("New", (_isEnabled ? "Enabled" : "Disabled"));
embed.WithFooter($":warning: {s_fileName} file is missing, and it can not be enabled.");
}
await ctx.RespondAsync(embed);
}
@@ -129,17 +129,17 @@ namespace StarsiegeBot
private bool Load()
{
bool ret;
if (File.Exists(fileName))
if (File.Exists(s_fileName))
{
string json = File.ReadAllText(fileName);
notfacts = JsonConvert.DeserializeObject<List<string>>(json);
string json = File.ReadAllText(s_fileName);
_notfacts = JsonConvert.DeserializeObject<List<string>>(json);
ret = true;
}
else
{
ret = false;
}
IsEnabled = ret;
_isEnabled = ret;
return ret;
}
}