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

+48 -48
View File
@@ -19,32 +19,32 @@ namespace StarsiegeBot
[Cooldown(1, 2, CooldownBucketType.Guild)]
class DeathMessages : BaseCommandModule
{
private DeathMessageLines dmLines;
private bool DeathMessagesEnabled;
private static readonly string fileName = "Json/deathmessages.json";
private DeathMessageLines _dmLines;
private bool _deathMessagesEnabled;
private static readonly string s_fileName = "Json/deathmessages.json";
public DeathMessages()
{
Console.WriteLine("Death Message Commands Loaded.");
// If the DeathMessages file exists, load it. And enable the commands.
// Otherwise disable all the commands.
if (File.Exists(fileName))
if (File.Exists(s_fileName))
{
// set some JSON text to blank.
var json = "";
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
string json = "";
using (FileStream fs = File.OpenRead(s_fileName))
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
// Decode the JSON and set it to dmLines.
dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
_dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
// Enable all the commands.
DeathMessagesEnabled = true;
_deathMessagesEnabled = true;
}
else
{
// Echo out that we're missing a file. Disable the commands due to that.
Console.WriteLine($" --- --- --- --- {fileName} is missing");
DeathMessagesEnabled = false;
Console.WriteLine($" --- --- --- --- {s_fileName} is missing");
_deathMessagesEnabled = false;
}
}
@@ -53,24 +53,24 @@ namespace StarsiegeBot
public async Task LoadDeathMessages(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
if (File.Exists(fileName))
if (File.Exists(s_fileName))
{
// set some JSON text to blank.
var json = "";
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
string json = "";
using (FileStream fs = File.OpenRead(s_fileName))
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
// Decode the JSON and set it to dmLines.
dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
_dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
// Enable all the commands.
DeathMessagesEnabled = true;
_deathMessagesEnabled = true;
await ctx.RespondAsync("Loading Death Messages successul.");
}
else
{
// Echo out that we're missing a file. Disable the commands due to that.
await ctx.RespondAsync("Can't load Death Messages. File missing.");
DeathMessagesEnabled = false;
_deathMessagesEnabled = false;
}
}
@@ -87,26 +87,26 @@ 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))
{
DeathMessagesEnabled = true;
_deathMessagesEnabled = true;
}
else if (turnOff.Contains(isEnabled))
{
DeathMessagesEnabled = false;
_deathMessagesEnabled = false;
}
else
{
}
output = $"DeathMessages Enabled: {DeathMessagesEnabled}";
output = $"DeathMessages Enabled: {_deathMessagesEnabled}";
}
else
{
DeathMessagesEnabled = false;
output = $"{fileName} file is missing, and it can not be enabled.";
_deathMessagesEnabled = false;
output = $"{s_fileName} file is missing, and it can not be enabled.";
}
await ctx.RespondAsync(output);
}
@@ -119,7 +119,7 @@ namespace StarsiegeBot
// IF we're missing the Death Messages dot JSON file, we're going to get disabled... Check for that.
// If disabled, let the person know the command set is disabled, and return.
if (!DeathMessagesEnabled)
if (!_deathMessagesEnabled)
{
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
return;
@@ -130,8 +130,8 @@ namespace StarsiegeBot
// if there is no target, we're going to "kill" the author.
if (target == null)
{
int choice = Program.rnd.Next(0, dmLines.Generic.Length);
line = dmLines.Generic[choice];
int choice = Program.rnd.Next(0, _dmLines.Generic.Length);
line = _dmLines.Generic[choice];
await ctx.RespondAsync(string.Format(line, ctx.Message.Author.Mention));
}
// we have a valid target... Have the bot kill them.
@@ -143,14 +143,14 @@ namespace StarsiegeBot
if (opt == 1)
{
// Pick an Active death message at random, and set our output to it.
int choice = Program.rnd.Next(0, dmLines.Active.Length);
line = dmLines.Active[choice];
int choice = Program.rnd.Next(0, _dmLines.Active.Length);
line = _dmLines.Active[choice];
}
else if (opt == 2)
{
// We picked a Passive death message type. Pick the exact line at random. Set it to the output.
int choice = Program.rnd.Next(0, dmLines.Passive.Length);
line = dmLines.Passive[choice];
int choice = Program.rnd.Next(0, _dmLines.Passive.Length);
line = _dmLines.Passive[choice];
}
// Give the selected death message to the user.
await ctx.RespondAsync(string.Format(line, ctx.Message.Author.Mention, target.Mention));
@@ -163,7 +163,7 @@ namespace StarsiegeBot
{
// IF we're missing the Death Messages dot JSON file, we're going to get disabled... Check for that.
// If disabled, let the person know the command set is disabled, and return.
if (!DeathMessagesEnabled)
if (!_deathMessagesEnabled)
{
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
return;
@@ -171,7 +171,7 @@ namespace StarsiegeBot
// We're typing here!
await ctx.TriggerTypingAsync();
// List all the types of Death Message types, and how many we have of each one.
await ctx.RespondAsync($"\r\nActive: {dmLines.Active.Length}\r\nPassive: {dmLines.Passive.Length}\r\nGeneric: {dmLines.Generic.Length}");
await ctx.RespondAsync($"\r\nActive: {_dmLines.Active.Length}\r\nPassive: {_dmLines.Passive.Length}\r\nGeneric: {_dmLines.Generic.Length}");
}
[Command("Add")]
@@ -181,7 +181,7 @@ namespace StarsiegeBot
{
// IF we're missing the Death Messages dot JSON file, we're going to get disabled... Check for that.
// If disabled, let the person know the command set is disabled, and return.
if (!DeathMessagesEnabled)
if (!_deathMessagesEnabled)
{
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
return;
@@ -191,10 +191,10 @@ namespace StarsiegeBot
// Message the owner know some one wants to add a new death message, along with a code block to that message.
// if the Queue is null, make it exist.
if (dmLines.Queue is null)
dmLines.Queue = new List<string>();
if (_dmLines.Queue is null)
_dmLines.Queue = new List<string>();
// add the message to the queue list.
dmLines.Queue.Add(msg);
_dmLines.Queue.Add(msg);
// Store the new stuff to file...
await StoreDeathMessages();
// Tell the person that the message has been added to a 'queue'.
@@ -208,7 +208,7 @@ namespace StarsiegeBot
await ctx.TriggerTypingAsync();
// IF we're missing the Death Messages dot JSON file, we're going to get disabled... Check for that.
// If disabled, let the person know the command set is disabled, and return.
if (!DeathMessagesEnabled)
if (!_deathMessagesEnabled)
{
await ctx.RespondAsync("Death Messages Commands have been disabled. Please contact the bot owners.");
return;
@@ -224,27 +224,27 @@ namespace StarsiegeBot
using StreamWriter file = new StreamWriter("deathmessages.cs");
// Write out the total lines for each. Requirement for Starsiege.
await file.WriteLineAsync($"$deathMessage::genericCount = {dmLines.Generic.Length};");
await file.WriteLineAsync($"$deathMessage::activeCount = {dmLines.Active.Length};");
await file.WriteLineAsync($"$deathMessage::passiveCount = {dmLines.Passive.Length};\r\n");
await file.WriteLineAsync($"$deathMessage::genericCount = {_dmLines.Generic.Length};");
await file.WriteLineAsync($"$deathMessage::activeCount = {_dmLines.Active.Length};");
await file.WriteLineAsync($"$deathMessage::passiveCount = {_dmLines.Passive.Length};\r\n");
// Set count to 0. Iterate over each type of Death Message, and put it into the file.
int count = 0;
foreach (string death in dmLines.Generic)
foreach (string death in _dmLines.Generic)
{
await file.WriteLineAsync(string.Format($"$deathMessage::generic{count} = \"{death}\";", "%s", "%s"));
count++;
}
// Reset the count...
count = 0;
foreach (string death in dmLines.Active)
foreach (string death in _dmLines.Active)
{
await file.WriteLineAsync(string.Format($"$deathMessage::active{count} = \"{death}\";", "%s", "%s"));
count++;
}
// Reset the count one last time...
count = 0;
foreach (string death in dmLines.Passive)
foreach (string death in _dmLines.Passive)
{
await file.WriteLineAsync(string.Format($"$deathMessage::passive{count} = \"{death}\";", "%s", "%s"));
count++;
@@ -269,8 +269,8 @@ namespace StarsiegeBot
private async Task StoreDeathMessages()
{
string output = JsonConvert.SerializeObject(dmLines);
await File.WriteAllTextAsync(fileName, output);
string output = JsonConvert.SerializeObject(_dmLines);
await File.WriteAllTextAsync(s_fileName, output);
return;
}
}
@@ -283,8 +283,8 @@ namespace StarsiegeBot
[JsonProperty("generic")]
public string[] Generic { get; set; }
[JsonProperty("flagged")]
public List<String> Flagged { get; set; }
public List<string> Flagged { get; set; }
[JsonProperty("queue")]
public List<String> Queue { get; set; }
public List<string> Queue { get; set; }
}
}
+28 -28
View File
@@ -16,27 +16,27 @@ namespace StarsiegeBot
[Group("functions"), Aliases("func")]
class Functions : BaseCommandModule
{
private Dictionary<string, SSFunction> ssFunctions;
private bool FunctionsEnabled;
private static readonly string fileName = "Json/functions.json";
private Dictionary<string, SSFunction> _ssFunctions;
private bool _functionsEnabled;
private static readonly string s_fileName = "Json/functions.json";
public Functions()
{
Console.WriteLine("Starsiege Function Commands Loaded");
// Check for file, if not there, disable commands.
if (File.Exists(fileName))
if (File.Exists(s_fileName))
{
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
var json = "";
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
string json = "";
using (FileStream fs = File.OpenRead(s_fileName))
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
FunctionsEnabled = true;
_ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
_functionsEnabled = true;
}
else
{
FunctionsEnabled = false;
_functionsEnabled = false;
Console.WriteLine(" --- --- --- Functions JSON not found.");
}
}
@@ -46,7 +46,7 @@ namespace StarsiegeBot
public async Task StarsiegeFunctions(CommandContext ctx, [RemainingText, Description("The function to attempt to look up.")] string command = "")
{
await ctx.TriggerTypingAsync();
if (!FunctionsEnabled)
if (!_functionsEnabled)
{
await ctx.RespondAsync("Function Commands have been disabled. Please contact the bot owners.");
return;
@@ -56,7 +56,7 @@ namespace StarsiegeBot
if (command.Equals(string.Empty))
{
// Get a list of the Keys.
List<string> keys = new List<string>(ssFunctions.Keys);
List<string> keys = new List<string>(_ssFunctions.Keys);
// get a new output.
string output = string.Empty;
// loop over the keys.
@@ -78,7 +78,7 @@ namespace StarsiegeBot
}
// we have a command the want to try to find.
else if (ssFunctions.TryGetValue(command.ToLower(), out SSFunction outItem))
else if (_ssFunctions.TryGetValue(command.ToLower(), out SSFunction outItem))
{
// New Message Embed!
DiscordEmbedBuilder embed = new DiscordEmbedBuilder();
@@ -113,13 +113,13 @@ namespace StarsiegeBot
await ctx.TriggerTypingAsync();
// check ot make sure these commands are enabled. if disabled, report it.
if (!FunctionsEnabled)
if (!_functionsEnabled)
{
await ctx.RespondAsync("Function Commands have been disabled. Please contact the bot owners.");
return;
}
// they wanted to know how many functions were documented... so tell them!
await ctx.RespondAsync($"There are {ssFunctions.Count} functions in the known list.");
await ctx.RespondAsync($"There are {_ssFunctions.Count} functions in the known list.");
}
[Command("toggle"), Aliases("t")]
@@ -135,26 +135,26 @@ 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))
{
FunctionsEnabled = true;
_functionsEnabled = true;
}
else if (turnOff.Contains(isEnabled))
{
FunctionsEnabled = false;
_functionsEnabled = false;
}
else
{
}
output = $"Functions Enabled: {FunctionsEnabled}";
output = $"Functions Enabled: {_functionsEnabled}";
}
else
{
FunctionsEnabled = false;
output = $"{fileName} file is missing, and it can not be enabled.";
_functionsEnabled = false;
output = $"{s_fileName} file is missing, and it can not be enabled.";
}
await ctx.RespondAsync(output);
}
@@ -164,20 +164,20 @@ namespace StarsiegeBot
await ctx.TriggerTypingAsync();
// Check for file, if not there, disable commands.
if (File.Exists(fileName))
if (File.Exists(s_fileName))
{
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
var json = "";
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
string json = "";
using (FileStream fs = File.OpenRead(s_fileName))
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
FunctionsEnabled = true;
_ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
_functionsEnabled = true;
await ctx.RespondAsync("Loading Quick Chats successul.");
}
else
{
FunctionsEnabled = false;
_functionsEnabled = false;
await ctx.RespondAsync("Loading Functions failed. File does not exist.");
}
}
+17 -17
View File
@@ -14,7 +14,7 @@ namespace StarsiegeBot
[Description("Gives various reports on the game or master servers.")]
class GameInfo : BaseCommandModule
{
private WebServerItems gameData;
private WebServerItems _gameData;
public GameInfo()
{
Update();
@@ -22,20 +22,20 @@ namespace StarsiegeBot
}
private void Update()
{
if (gameData is null)
if (_gameData is null)
{
using WebClient wc = new WebClient();
var json = wc.DownloadString("https://alpha.starsiegeplayers.com/api/v1/multiplayer/servers");
gameData = JsonConvert.DeserializeObject<WebServerItems>(json);
string json = wc.DownloadString("https://alpha.starsiegeplayers.com/api/v1/multiplayer/servers");
_gameData = JsonConvert.DeserializeObject<WebServerItems>(json);
}
else
{
using WebClient wc = new WebClient();
var json = wc.DownloadString("https://alpha.starsiegeplayers.com/api/v1/multiplayer/servers");
string json = wc.DownloadString("https://alpha.starsiegeplayers.com/api/v1/multiplayer/servers");
WebServerItems temp = JsonConvert.DeserializeObject<WebServerItems>(json);
if (temp.RequestTime != gameData.RequestTime)
if (temp.RequestTime != _gameData.RequestTime)
{
gameData = temp;
_gameData = temp;
}
}
}
@@ -47,7 +47,7 @@ namespace StarsiegeBot
// setup an exit point check.
bool exit = false;
// if its null, we're going to exit.
if (gameData is null || gameData.Errors is null)
if (_gameData is null || _gameData.Errors is null)
{
exit = true;
}
@@ -60,9 +60,9 @@ namespace StarsiegeBot
Title = "Master|Game Server Overview",
Description = "Number of Master, and Game servers. Along with number of errors."
};
embed.AddField("Masters", gameData.Masters.Length.ToString(), true);
embed.AddField("Games", gameData.Games.Length.ToString(), true);
embed.AddField("Errors", gameData.Errors.Length.ToString(), true);
embed.AddField("Masters", _gameData.Masters.Length.ToString(), true);
embed.AddField("Games", _gameData.Games.Length.ToString(), true);
embed.AddField("Errors", _gameData.Errors.Length.ToString(), true);
await ctx.RespondAsync(embed);
}
@@ -75,7 +75,7 @@ namespace StarsiegeBot
// setup an exit point check.
bool exit = false;
// if its null, we're going to exit.
if (gameData is null || gameData.Errors is null)
if (_gameData is null || _gameData.Errors is null)
{
exit = true;
}
@@ -87,7 +87,7 @@ namespace StarsiegeBot
{
Content = "Server Listing Errors:\r\n"
};
foreach (var item in gameData.Errors)
foreach (string item in _gameData.Errors)
{
msg.Content += $"{item}\r\n";
}
@@ -103,7 +103,7 @@ namespace StarsiegeBot
// setup an exit point check.
bool exit = false;
// if its null, we're going to exit.
if (gameData is null || gameData.Masters is null)
if (_gameData is null || _gameData.Masters is null)
{
exit = true;
}
@@ -116,7 +116,7 @@ namespace StarsiegeBot
Content = "```csharp\r\n"
};
int count = 0;
foreach (var item in gameData.Masters)
foreach (MasterServer item in _gameData.Masters)
{
count++;
msg.Content += $"$Inet::Master{count} = \"IP:{item.Address}\";\r\n";
@@ -135,7 +135,7 @@ namespace StarsiegeBot
// setup an exit point check.
bool exit = false;
// if its null, we're going to exit.
if (gameData is null || gameData.Games is null)
if (_gameData is null || _gameData.Games is null)
{
exit = true;
}
@@ -147,7 +147,7 @@ namespace StarsiegeBot
DiscordMessageBuilder msg = new DiscordMessageBuilder();
// we're on our way to greatness!
int count = 0;
foreach (var item in gameData.Games)
foreach (GameServer item in _gameData.Games)
{
// if (item.PlayerCount > playerCount)
if (item.GameStatus["Started"])
+90 -41
View File
@@ -16,15 +16,15 @@ namespace StarsiegeBot
[Aliases("qc"), Group("quickchat")]
class QuickchatHandler : BaseCommandModule
{
private Dictionary<string, Quickchat> quickchats;
private bool IsEnabled;
private readonly string fileName = "Json/quickchats.json";
private Dictionary<string, Quickchat> _quickchats;
private bool _isEnabled;
private readonly string _fileName = "Json/quickchats.json";
public QuickchatHandler()
{
Console.WriteLine("Quick Chat Handler Loaded");
IsEnabled = LoadQuickChatsImpl();
_isEnabled = LoadQuickChatsImpl();
}
/**
@@ -34,14 +34,14 @@ namespace StarsiegeBot
private bool LoadQuickChatsImpl()
{
// Check to see if the file exists...
if (File.Exists(fileName))
if (File.Exists(_fileName))
{
// Load the JSON file.
var json = "";
using (var fs = File.OpenRead(fileName))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
string json = "";
using (FileStream fs = File.OpenRead(_fileName))
using (StreamReader sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
quickchats = JsonConvert.DeserializeObject<Dictionary<string, Quickchat>>(json);
_quickchats = JsonConvert.DeserializeObject<Dictionary<string, Quickchat>>(json);
// enable the commands.
return true;
}
@@ -57,8 +57,8 @@ namespace StarsiegeBot
{
await ctx.TriggerTypingAsync();
string output;
IsEnabled = LoadQuickChatsImpl();
if (IsEnabled)
_isEnabled = LoadQuickChatsImpl();
if (_isEnabled)
{
output = "Loading Quick Chats successful.";
}
@@ -74,7 +74,7 @@ namespace StarsiegeBot
public async Task GetQuickChatScript(CommandContext ctx, [Description("ID of Quick chat to get script for.")] int index)
{
// If we're disabled, let them know. And exit out.
if (!IsEnabled)
if (!_isEnabled)
{
return;
}
@@ -85,16 +85,16 @@ namespace StarsiegeBot
index = Math.Abs(index);
// is our index within bounds?
if (index < quickchats.Count)
if (index < _quickchats.Count)
{
// yes it is, give the script to them.
Quickchat chat = quickchats[index.ToString()];
Quickchat chat = _quickchats[index.ToString()];
await ctx.RespondAsync("```" + chat.ToString() + "```");
return;
}
// we couldn't find it... Oh well, let the end user know.
await ctx.RespondAsync("The ID specified is out of bounds. 0-" + (quickchats.Count - 1));
await ctx.RespondAsync("The ID specified is out of bounds. 0-" + (_quickchats.Count - 1));
}
[Command("check")]
@@ -102,7 +102,7 @@ namespace StarsiegeBot
public async Task QuickChatCheck(CommandContext ctx)
{
// If we're disabled, let them know. And exit out.
if (!IsEnabled)
if (!_isEnabled)
{
return;
}
@@ -110,10 +110,10 @@ namespace StarsiegeBot
// Start a count
int missingFiles = 0;
for (int i = 0; i < quickchats.Count; i++)
for (int i = 0; i < _quickchats.Count; i++)
{
// If this file doesnt exist, log the ID in the console, and add to the count.
if (!File.Exists($"./qc/{quickchats[i.ToString()].SoundFile}"))
if (!File.Exists($"./qc/{_quickchats[i.ToString()].SoundFile}"))
{
missingFiles++;
Console.Write($"{i}, ");
@@ -129,7 +129,7 @@ namespace StarsiegeBot
public async Task QuickChat(CommandContext ctx, [Description("The ID of the quick Chat.")] int id = -1)
{
// If we're disabled, let them know. And exit out.
if (!IsEnabled)
if (!_isEnabled)
{
return;
}
@@ -148,7 +148,7 @@ namespace StarsiegeBot
{
id = Math.Abs(id);
}
chat = quickchats[id.ToString()];
chat = _quickchats[id.ToString()];
output = id + ": " + chat.Text;
}
catch (Exception)
@@ -158,8 +158,8 @@ namespace StarsiegeBot
{
try
{
id = Program.rnd.Next(quickchats.Count);
chat = quickchats[id.ToString()];
id = Program.rnd.Next(_quickchats.Count);
chat = _quickchats[id.ToString()];
output = $"[{id}] " + chat.Text;
}
catch (Exception)
@@ -195,7 +195,7 @@ namespace StarsiegeBot
string output;
// If we're disabled, let them know. And exit out.
if (!IsEnabled)
if (!_isEnabled)
{
await ctx.RespondAsync("Quick Chat Commands have been disabled. Please contact the bot owners.");
return;
@@ -207,19 +207,19 @@ namespace StarsiegeBot
int count = 0;
// We're going to search each QC for the stuff in toSearch.
foreach (KeyValuePair<string, Quickchat> qc in quickchats)
foreach (KeyValuePair<string, Quickchat> qc in _quickchats)
{
// do we have a match?
if (qc.Value.Text.ToLower().Contains(toSearch.ToLower()))
{
// add it to the list!
sb.Append($"[{qc.Key}][T] {quickchats[qc.Key].Text}\r\n");
sb.Append($"[{qc.Key}][T] {_quickchats[qc.Key].Text}\r\n");
count++;
}
if (qc.Value.SoundFile.ToLower().Contains(toSearch.ToLower()))
{
// add it to the list!
sb.Append($"[{qc.Key}][S] {quickchats[qc.Key].Text}\r\n");
sb.Append($"[{qc.Key}][S] {_quickchats[qc.Key].Text}\r\n");
count++;
}
}
@@ -243,16 +243,37 @@ namespace StarsiegeBot
[Command("flag")]
[Description("Flags a Quick Chat for moderator checking.")]
public async Task FlagQC(CommandContext ctx, [Description("ID of QC to flag.")] int id, [RemainingText, Description("The reason you believe it needs flagged.")] string flagRerason = "")
public async Task FlagQC(CommandContext ctx, [Description("ID of QC to flag.")] int id, [RemainingText, Description("The reason you believe it needs flagged.")] string flagReason = "")
{
await ctx.TriggerTypingAsync();
Quickchat chat = quickchats[id.ToString()];
Quickchat chat = _quickchats[id.ToString()];
DiscordEmbedBuilder embed;
chat.FlagCount++;
embed = StartEmbed($"Flagging QC ID `{id}` with reason of `{flagRerason}`. (F{chat.FlagCount})");
foreach (FlagEvent item in chat.Flags)
{
if (item.UserId == ctx.Member.Id)
{
item.Reason = flagReason;
embed = StartEmbed($"Each user can only flag an item once. Updating your reason to `{flagReason}`");
string dateReason = DateTime.UtcNow.ToString();
embed.WithFooter(dateReason);
await ctx.RespondAsync(embed);
//return;
}
}
//if (chat.Flags.ContainsKey(ctx.Member.Id))
//{
// chat.Flags[ctx.Member.Id] = flagReason;
// await ctx.RespondAsync(StartEmbed($"Each user can only flag an item once. Updating your reason to `{flagReason}`"));
//}
// chat.Flags.Add(ctx.Member.Id, flagReason);
//FlagEvent event = new FlagEvent();
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);
string output = JsonConvert.SerializeObject(_quickchats);
await File.WriteAllTextAsync(_fileName, output);
await ctx.RespondAsync(embed);
}
@@ -261,7 +282,7 @@ namespace StarsiegeBot
{
await ctx.TriggerTypingAsync();
int count = 0;
foreach (var chat in quickchats)
foreach (KeyValuePair<string, Quickchat> chat in _quickchats)
{
if (chat.Value.IsFlagged)
{
@@ -271,7 +292,6 @@ namespace StarsiegeBot
await ctx.RespondAsync(StartEmbed($"There are {count} flagged Quick Chats."));
}
[Command("toggle"), Aliases("t")]
[RequireOwner]
[Description("[Owner only] Enables or disables, or checks status of QuickChats.\r\nTo turn the feature on, use `TRUE`, `ON`, or `1`\r\nTo turn off, use `FALSE`, `OFF`, or `0`")]
@@ -283,23 +303,23 @@ namespace StarsiegeBot
string[] turnOn = { "on", "true", "1" };
string[] turnOff = { "off", "false", "0" };
if (File.Exists(fileName))
if (File.Exists(_fileName))
{
if (turnOn.Contains(isEnabled))
{
IsEnabled = true;
_isEnabled = true;
}
if (turnOff.Contains(isEnabled))
{
IsEnabled = false;
_isEnabled = false;
}
output = $"Quickchats {(IsEnabled ? "Enabled" : "Disabled")}";
output = $"Quickchats {(_isEnabled ? "Enabled" : "Disabled")}";
}
else
{
IsEnabled = false;
output = $"{fileName} file is missing, and it can not be enabled.";
_isEnabled = false;
output = $"{_fileName} file is missing, and it can not be enabled.";
}
await ctx.RespondAsync(StartEmbed(output));
}
@@ -322,11 +342,40 @@ namespace StarsiegeBot
[JsonProperty("soundFile")]
public string SoundFile { get; protected set; }
public bool IsFlagged { get; set; }
public int FlagCount { get; set; }
[JsonProperty("flags")]
public List<FlagEvent> Flags { get; set; }
public override string ToString()
{
return $"say(0,0, \"{Text}\", \"{SoundFile}\");";
}
}
public class FlagEvent : IEquatable<FlagEvent>
{
public ulong UserId { get; set; }
public string Reason { get; set; }
public string Timestamp { get; set; }
public FlagEvent(ulong UserId, string Reason, string Timestamp)
{
this.UserId = UserId;
this.Reason = Reason;
this.Timestamp = Timestamp;
}
public bool Equals(FlagEvent e)
{
return UserId == e.UserId;
}
public bool Equals(ulong s)
{
return UserId == s;
}
public override bool Equals(object o)
{
return false;
}
public override int GetHashCode()
{
return UserId.GetHashCode();
}
}
}