summaryrefslogtreecommitdiff
path: root/DiscoBot/Commands/Help.cs
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-06-07 02:35:19 +0200
committerTrueDoctor <d-kobert@web.de>2018-06-07 02:35:19 +0200
commit8b2cd65526f7535ab43266653bd1146add8bd880 (patch)
tree57e0941cfab44d8720dc8f0aed5cee4e695b6176 /DiscoBot/Commands/Help.cs
parent111b46289213b293f0977060588a90f880b3852e (diff)
Added generic Help system
added EasyCompare as static method
Diffstat (limited to 'DiscoBot/Commands/Help.cs')
-rw-r--r--DiscoBot/Commands/Help.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/DiscoBot/Commands/Help.cs b/DiscoBot/Commands/Help.cs
new file mode 100644
index 0000000..2ba3fb6
--- /dev/null
+++ b/DiscoBot/Commands/Help.cs
@@ -0,0 +1,49 @@
+using System.Linq;
+
+namespace DiscoBot.Commands
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Threading.Tasks;
+
+ using DiscoBot.Auxiliary;
+
+ using Discord.Commands;
+
+ using Newtonsoft.Json;
+
+ using CommandInfo = DiscoBot.Auxiliary.CommandInfo;
+
+ public class Help : ModuleBase
+ {
+ static Help()
+ {
+ TextReader stream = new StreamReader(@"..\..\Help.json"); // Load command-description file
+ var reader = new JsonTextReader(stream); // create stream reader
+
+ reader.Read(); // step into structure, until the array starts
+ reader.Read();
+ reader.Read();
+ var test = new JsonSerializer().Deserialize<List<CommandInfo>>(reader); // Deserialize Data and create CommandInfo Struct
+ Commands.AddRange(test); // Add new CommandInfos to List
+ }
+
+ public static List<CommandInfo> Commands { get; } = new List<CommandInfo>();
+
+ [Command("help"), Summary("prints the help menu.")]
+ public async Task ShowHelpAsync(string command = "")
+ {
+ if (command.Equals(string.Empty)) // return generic Help
+ {
+ await this.ReplyAsync("```\n[hilfreiche Erklärungen]\nAuflistung aller Commands mit !list commands\n```");
+ return;
+ }
+
+ // return command specific help
+ var com = Commands.OrderBy(x => SpellCorrect.CompareEasy(x.Name, command)).First(); // get best fit command
+
+ await this.ReplyAsync("```\n" + com.Name + "\n" + com.Description + "\n```");
+ }
+ }
+}