From 8b2cd65526f7535ab43266653bd1146add8bd880 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Thu, 7 Jun 2018 02:35:19 +0200 Subject: Added generic Help system added EasyCompare as static method --- DiscoBot/Commands/Help.cs | 49 +++++++++++++++++++++++++++++++++++++++ DiscoBot/Commands/List.cs | 3 +++ DiscoBot/Commands/MiscCommands.cs | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 DiscoBot/Commands/Help.cs (limited to 'DiscoBot/Commands') 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>(reader); // Deserialize Data and create CommandInfo Struct + Commands.AddRange(test); // Add new CommandInfos to List + } + + public static List Commands { get; } = new List(); + + [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"); -- cgit v1.2.3-70-g09d2