diff options
Diffstat (limited to 'DiscoBot')
-rw-r--r-- | DiscoBot/Auxiliary/CommandInfo.cs | 24 | ||||
-rw-r--r-- | DiscoBot/Auxiliary/SpellCorrect.cs | 9 | ||||
-rw-r--r-- | DiscoBot/Commands/Help.cs | 49 | ||||
-rw-r--r-- | DiscoBot/Commands/List.cs | 3 | ||||
-rw-r--r-- | DiscoBot/Commands/MiscCommands.cs | 2 | ||||
-rw-r--r-- | DiscoBot/DiscoBot.csproj | 3 | ||||
-rw-r--r-- | DiscoBot/Help.json | 24 |
7 files changed, 111 insertions, 3 deletions
diff --git a/DiscoBot/Auxiliary/CommandInfo.cs b/DiscoBot/Auxiliary/CommandInfo.cs new file mode 100644 index 0000000..b08ba1b --- /dev/null +++ b/DiscoBot/Auxiliary/CommandInfo.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DiscoBot.Auxiliary +{ + public struct CommandInfo + { + public CommandInfo(string name, string description, string scope) + { + this.Name = name; + this.Scope = scope; + this.Description = description; + } + + public string Name { get; } + + public string Scope { get; } + + public string Description { get; } + } +} diff --git a/DiscoBot/Auxiliary/SpellCorrect.cs b/DiscoBot/Auxiliary/SpellCorrect.cs index 4f4f7d0..01cce62 100644 --- a/DiscoBot/Auxiliary/SpellCorrect.cs +++ b/DiscoBot/Auxiliary/SpellCorrect.cs @@ -10,6 +10,11 @@ public override int Compare(string x, string y) { + return CompareEasy(x, y); + } + + public static int CompareEasy(string x, string y) + { if (string.IsNullOrEmpty(x)) { throw new ArgumentException("message", nameof(x)); @@ -47,7 +52,7 @@ return score + 1; } - return 100000 - (int)(this.CompareExact(x, y) * 1000.0); + return 100000 - (int)(CompareExact(x, y) * 1000.0); /*if (y.Contains(x)) return 6;*/ } @@ -63,7 +68,7 @@ throw new NotImplementedException(); } - public double CompareExact(string s, string q) + public static double CompareExact(string s, string q) { s = s.ToLower(); 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"); diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index 6fec671..9e8b193 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -149,6 +149,8 @@ <ItemGroup> <Compile Include="Audio\AudioModule.cs" /> <Compile Include="Audio\AudioService.cs" /> + <Compile Include="Auxiliary\CommandInfo.cs" /> + <Compile Include="Commands\Help.cs" /> <Compile Include="Commands\Man.cs" /> <Compile Include="Auxiliary\Dice.cs" /> <Compile Include="Auxiliary\TalentEnumerableExtension.cs" /> @@ -184,6 +186,7 @@ </ItemGroup> <ItemGroup> <None Include="App.config" /> + <None Include="Help.json" /> <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> diff --git a/DiscoBot/Help.json b/DiscoBot/Help.json new file mode 100644 index 0000000..ffbbaf3 --- /dev/null +++ b/DiscoBot/Help.json @@ -0,0 +1,24 @@ +{ + "CommandInfos": [ + { + "Name": "List", + "Scope": "All", + "Description": "Testbeschreibung" + }, + { + "Name": "LE", + "Scope": "All", + "Description": "Verändert Leben - im wahrsten Sinne des Wortes" + }, + { + "Name": "AE", + "Scope": "All", + "Description": "Verändert ASTRALPUNKTE" + }, + { + "Name": "Gm", + "Scope": "Meister", + "Description": "Gm Aktionen" + } + ] +} |