Added Load and Toggle sub commands to [DeathMessages|Functions|QuickChats] commands.

This commit is contained in:
Christopher Darnell committed 2021-04-26 17:59:34 -07:00
1 parent 177a689989
commit b2d6cff5ed
6 files changed
+89 -20

No files matched your search

+27 -2
View File
@@ -22,7 +22,7 @@ namespace StarsiegeBot
[Aliases("qc"), Group("quickchat")]
class Quickchat : BaseCommandModule
{
private readonly List<Quickchats> Quickchats;
private List<Quickchats> Quickchats;
private readonly Random rnd = new Random();
private bool QuickChatsEnabled;
@@ -51,6 +51,32 @@ namespace StarsiegeBot
}
}
[Command("load"), RequireOwner]
public async Task LoadQuickChats(CommandContext ctx)
{
await ctx.TriggerTypingAsync();
if (File.Exists("quickchats.json"))
{
// Load the JSON file.
var json = "";
using (var fs = File.OpenRead("quickchats.json"))
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
json = sr.ReadToEnd();
Dictionary<string, Quickchats> tempQC = JsonConvert.DeserializeObject<Dictionary<string, Quickchats>>(json);
// set the Quick Chat object.
Quickchats = Enumerable.ToList(tempQC.Values);
// enable the commands.
QuickChatsEnabled = true;
await ctx.RespondAsync("Loading Quick Chats successul.");
}
else
{
QuickChatsEnabled = false;
await ctx.RespondAsync("Loading Quick Chats failed. File does not exist.");
}
}
[Command("script")]
[Description("Gives the `say()` for use in the Quickchat.cs file.")]
public async Task GetQuickChatScript(CommandContext ctx, [Description("ID of Quick chat to get script for.")] int index)
@@ -239,7 +265,6 @@ namespace StarsiegeBot
QuickChatsEnabled = false;
output = "QuickChats.json file is missing, and it can not be enabled.";
}
await ctx.RespondAsync(output);
}
}