Added Load and Toggle sub commands to [DeathMessages|Functions|QuickChats] commands.
This commit is contained in:
1 parent
177a689989
commit
b2d6cff5ed
6 files changed
+89
-20
No files matched your search
@@ -26,7 +26,7 @@ namespace StarsiegeBot
|
||||
class DeathMessages : BaseCommandModule
|
||||
{
|
||||
private readonly Random rnd = new Random();
|
||||
private readonly DeathMessageLines dmLines;
|
||||
private DeathMessageLines dmLines;
|
||||
private bool DeathMessagesEnabled;
|
||||
|
||||
public DeathMessages()
|
||||
@@ -54,9 +54,35 @@ namespace StarsiegeBot
|
||||
}
|
||||
}
|
||||
|
||||
[Command("load")]
|
||||
public async Task LoadDeathMessages(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
if (File.Exists("DeathMessages.json"))
|
||||
{
|
||||
// set some JSON text to blank.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("DeathMessages.json"))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
// Decode the JSON and set it to dmLines.
|
||||
dmLines = JsonConvert.DeserializeObject<DeathMessageLines>(json);
|
||||
// Enable all the commands.
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Command("toggle"), Aliases("t")]
|
||||
[RequireOwner]
|
||||
public async Task ToggleQC(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
public async Task ToggleDM(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace StarsiegeBot
|
||||
DiscordColor.Rose, DiscordColor.SapGreen, DiscordColor.Sienna, DiscordColor.SpringGreen, DiscordColor.Teal, DiscordColor.Turquoise, DiscordColor.VeryDarkGray,
|
||||
DiscordColor.Violet, DiscordColor.Wheat, DiscordColor.White, DiscordColor.Yellow };
|
||||
private readonly Random rnd = new Random();
|
||||
private readonly Dictionary<string, SSFunction> ssFunctions;
|
||||
private Dictionary<string, SSFunction> ssFunctions;
|
||||
private bool FunctionsEnabled;
|
||||
|
||||
public Functions()
|
||||
@@ -138,7 +138,7 @@ namespace StarsiegeBot
|
||||
|
||||
[Command("toggle"), Aliases("t")]
|
||||
[RequireOwner]
|
||||
public async Task ToggleQC(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
public async Task ToggleFunctions(CommandContext ctx, [RemainingText] string isEnabled = null)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
@@ -172,6 +172,29 @@ namespace StarsiegeBot
|
||||
}
|
||||
await ctx.RespondAsync(output);
|
||||
}
|
||||
[Command("load"), RequireOwner]
|
||||
public async Task LoadFunctions(CommandContext ctx)
|
||||
{
|
||||
await ctx.TriggerTypingAsync();
|
||||
|
||||
// Check for file, if not there, disable commands.
|
||||
if (File.Exists("functions.json"))
|
||||
{
|
||||
// Load the Functions JSON file. Has all information regarding Starsiege in-game Functions.
|
||||
var json = "";
|
||||
using (var fs = File.OpenRead("functions.json"))
|
||||
using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
|
||||
json = sr.ReadToEnd();
|
||||
ssFunctions = JsonConvert.DeserializeObject<Dictionary<string, SSFunction>>(json);
|
||||
FunctionsEnabled = true;
|
||||
await ctx.RespondAsync("Loading Quick Chats successul.");
|
||||
}
|
||||
else
|
||||
{
|
||||
FunctionsEnabled = false;
|
||||
await ctx.RespondAsync("Loading Functions failed. File does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SSFunction
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user