summaryrefslogtreecommitdiff
path: root/DiscoBot/Commands
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
parent111b46289213b293f0977060588a90f880b3852e (diff)
Added generic Help system
added EasyCompare as static method
Diffstat (limited to 'DiscoBot/Commands')
-rw-r--r--DiscoBot/Commands/Help.cs49
-rw-r--r--DiscoBot/Commands/List.cs3
-rw-r--r--DiscoBot/Commands/MiscCommands.cs2
3 files changed, 53 insertions, 1 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```");
+ }
+ }
+}
diff --git a/DiscoBot/Commands/List.cs b/DiscoBot/Commands/List.cs
index 9c745b2..c688daa 100644
--- a/DiscoBot/Commands/List.cs
+++ b/DiscoBot/Commands/List.cs
@@ -29,6 +29,9 @@
case "Chars":
res.AddRange(Dsa.Chars.Select(x => x.Name));
break;
+ case "commands":
+ res.AddRange(Help.Commands.Select(x => x.Name));
+ break;
case "e":
case "eig":
case "eigenschaft":
diff --git a/DiscoBot/Commands/MiscCommands.cs b/DiscoBot/Commands/MiscCommands.cs
index daf34e2..46cd6eb 100644
--- a/DiscoBot/Commands/MiscCommands.cs
+++ b/DiscoBot/Commands/MiscCommands.cs
@@ -88,7 +88,7 @@ namespace DiscoBot.Commands
var sc = new SpellCorrect();
var rand = new System.Random((s1+s2).GetHashCode());
- var wert = Math.Log10(Math.Floor(1000.0 * (sc.CompareExact(s1, s2) + rand.NextDouble() * 10.0)) / 1000.0);
+ var wert = Math.Log10(Math.Floor(1000.0 * (SpellCorrect.CompareExact(s1, s2) + rand.NextDouble() * 10.0)) / 1000.0);
wert = ((wert * 100.0) < 100.0 ? wert * 100.0 : 100.0 - wert);
wert = wert < 0 ? -wert : wert;
return this.ReplyAsync($"Ihr passt zu {Math.Floor(100.0 * wert )/ 100.0}% zusammen");