From f89f308c525e9deebc6d2cf6416e27dfe1a299dc Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sun, 19 May 2019 16:03:38 +0200 Subject: Cleanup DiscoBot Project --- DSACore/Commands/CommandHandler.cs | 21 ++++------- DSACore/Commands/CommandTypes.cs | 2 +- DSACore/Commands/FileHandler.cs | 25 +++++-------- DSACore/Commands/Gm.cs | 2 +- DSACore/Commands/HeldList.cs | 72 ++++++++++++++++++++------------------ DSACore/Commands/Help.cs | 29 ++++++++------- DSACore/Commands/LebenUndAstral.cs | 52 +++++++++++++++------------ DSACore/Commands/List.cs | 6 ++-- DSACore/Commands/MiscCommands.cs | 2 +- DSACore/Commands/NpcCommands.cs | 14 ++------ DSACore/Commands/ProbenTest.cs | 4 +-- 11 files changed, 108 insertions(+), 121 deletions(-) (limited to 'DSACore/Commands') diff --git a/DSACore/Commands/CommandHandler.cs b/DSACore/Commands/CommandHandler.cs index f43633f..6879045 100644 --- a/DSACore/Commands/CommandHandler.cs +++ b/DSACore/Commands/CommandHandler.cs @@ -10,8 +10,8 @@ namespace DSACore.Commands { public static CommandResponse ExecuteCommand(Command cmd) { - string res = string.Empty; - ResponseType type = ResponseType.Broadcast; + var res = string.Empty; + var type = ResponseType.Broadcast; switch (cmd.CmdIdentifier.ToLower()) { case "addChar": @@ -21,7 +21,7 @@ namespace DSACore.Commands case "wert": case "werte": case "char": - res = Commands.HeldList.ListAsync(cmd.CharId, cmd.CmdText); + res = HeldList.ListAsync(cmd.CharId, cmd.CmdText); break; case "help": case "man": @@ -54,23 +54,16 @@ namespace DSACore.Commands case "npc": res = NpcCommands.CreateNpc(cmd.CharId, cmd.CmdTexts, cmd.Cmdmodifier); break; - } - if (res == string.Empty) - { - res= Proben(cmd.Name, cmd.CmdIdentifier, cmd.CmdText, cmd.Cmdmodifier); - } - if (res != string.Empty) - { - return new CommandResponse(res, type); - } + if (res == string.Empty) res = Proben(cmd.Name, cmd.CmdIdentifier, cmd.CmdText, cmd.Cmdmodifier); + if (res != string.Empty) return new CommandResponse(res, type); return new CommandResponse($"Kommando {cmd.CmdIdentifier} nicht gefunden", ResponseType.Error); } private static string Proben(string name, string command, string waffe, int erschwernis = 0) { - string res = string.Empty; + var res = string.Empty; switch (command.ToLower()) { case "f": @@ -138,4 +131,4 @@ namespace DSACore.Commands throw new NotImplementedException("access char by id ore name and group id"); } } -} +} \ No newline at end of file diff --git a/DSACore/Commands/CommandTypes.cs b/DSACore/Commands/CommandTypes.cs index d53328b..6838ac2 100644 --- a/DSACore/Commands/CommandTypes.cs +++ b/DSACore/Commands/CommandTypes.cs @@ -10,4 +10,4 @@ KeinChar, Zauber } -} +} \ No newline at end of file diff --git a/DSACore/Commands/FileHandler.cs b/DSACore/Commands/FileHandler.cs index af4698a..d8fb585 100644 --- a/DSACore/Commands/FileHandler.cs +++ b/DSACore/Commands/FileHandler.cs @@ -6,32 +6,25 @@ namespace DSACore.Commands using System; using System.Linq; using System.Net; - using DSALib; public class FileHandler { public static string AddChar(ulong id, string url) { - if (url == string.Empty) - { - throw new ArgumentException("Es wurde keine Datei angehängt"); - } - + if (url == string.Empty) throw new ArgumentException("Es wurde keine Datei angehängt"); + + + if (!url.EndsWith(".xml")) throw new ArgumentException("Es wurde kein xml Held mitgeschickt"); - if (!url.EndsWith(".xml")) + using (var client = new WebClient()) { - throw new ArgumentException("Es wurde kein xml Held mitgeschickt"); + client.DownloadFile(url, "helden\\" + url.Split("/").Last()); } - - using (var client = new WebClient()) - { - client.DownloadFile(url, "helden\\" + url.Split("/").Last()); - } - Dsa.Chars.Add(new Character("helden\\" + url.Split("/").Last())); - (Dsa.Chars.Last() as Character)?.Talente.Select(x => new Talent(x.Name, x.Probe, 0)) - .Where(c => !Dsa.Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Dsa.Talente.Add(v)); + Dsa.Chars.Add(new Character("helden\\" + url.Split("/").Last())); + (Dsa.Chars.Last() as Character)?.Talente.Select(x => new Talent(x.Name, x.Probe, 0)) + .Where(c => !Dsa.Talente.Exists(v => v.Name.Equals(c.Name))).ToList().ForEach(v => Dsa.Talente.Add(v)); return $"{url.Split("/").Last()} wurde erfolgreich gespeichert"; } diff --git a/DSACore/Commands/Gm.cs b/DSACore/Commands/Gm.cs index a320269..59b3129 100644 --- a/DSACore/Commands/Gm.cs +++ b/DSACore/Commands/Gm.cs @@ -180,4 +180,4 @@ namespace DSACore.Commands return res; } }*/ -} +} \ No newline at end of file diff --git a/DSACore/Commands/HeldList.cs b/DSACore/Commands/HeldList.cs index 825474c..73861b7 100644 --- a/DSACore/Commands/HeldList.cs +++ b/DSACore/Commands/HeldList.cs @@ -15,63 +15,65 @@ namespace DSACore.Commands var character = Dsa.GetCharacter(id) as Character; - int first_column_width = 18; - + var first_column_width = 18; - if (prop_list.Length == 0 || prop_list[0].ToLower().StartsWith("all") || prop_list[0].ToLower().StartsWith("brief") || prop_list[0].ToLower().StartsWith("zettel")) - { + if (prop_list.Length == 0 || prop_list[0].ToLower().StartsWith("all") || + prop_list[0].ToLower().StartsWith("brief") || prop_list[0].ToLower().StartsWith("zettel")) + { res.Add(character.Name + ":\n"); //Eigenschaften res.AddRange( - character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); + character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); res.Add(""); //LE/AE res.Add("LE:\t " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); if (character.Astralpunkte_Basis > 0) - { res.Add("AE:\t " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis); - } res.Add(""); //Kampfwerte res.Add("".AddSpaces(first_column_width) + " AT/PA"); res.AddRange( - character.Kampftalente.Select(s => s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + "/" + s.Pa.ToString().AddSpacesAtHead(2))); + character.Kampftalente.Select(s => + s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + "/" + + s.Pa.ToString().AddSpacesAtHead(2))); res.Add(""); //Fernkampf res.Add("".AddSpaces(first_column_width) + " FK"); res.AddRange( - character.Talente.Where(x => x.IstFernkampftalent()).Select(s => s.Name.AddSpaces(first_column_width) + " " + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); + character.Talente.Where(x => x.IstFernkampftalent()).Select(s => + s.Name.AddSpaces(first_column_width) + " " + + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); res.Add(""); //Vorteile res.AddRange( character.Vorteile - .Select(s => s.Name + "\t " + s.Value)); + .Select(s => s.Name + "\t " + s.Value)); res.Add(""); //Talente res.AddRange( - character.Talente.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); + character.Talente.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + + s.Probe)); res.Add(""); //evtl Zauber if (character.Zauber.Count > 0) - { res.AddRange( - character.Zauber.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); - } - + character.Zauber.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + + " " + s.Probe)); } - else if (prop_list[0].ToLower().StartsWith("man") || prop_list[0].ToLower().StartsWith("help") || prop_list[0].ToLower().StartsWith("hilf")) + else if (prop_list[0].ToLower().StartsWith("man") || prop_list[0].ToLower().StartsWith("help") || + prop_list[0].ToLower().StartsWith("hilf")) { return "```xl\n" + Help.Get_Specific_Help("Held") + "\n```"; } else { - res.Add(character.Name + ":\n"); - foreach (string prop in prop_list) + foreach (var prop in prop_list) { - switch (prop.ToLower()) { case "e": @@ -79,18 +81,16 @@ namespace DSACore.Commands case "eigenschaft": case "eigenschaften": res.AddRange( - character.Eigenschaften.Take(8).Select(s => s.Key + ":\t " + s.Value)); + character.Eigenschaften.Take(8).Select(s => s.Key + ":\t " + s.Value)); break; case "stat": case "stats": res.AddRange( - character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); + character.Eigenschaften.Take(9).Select(s => s.Key + ":\t " + s.Value)); res.Add(""); res.Add("LE:\t " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); if (character.Astralpunkte_Basis > 0) - { res.Add("AE:\t " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis); - } break; case "le": res.Add("LE:\t " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); @@ -103,12 +103,16 @@ namespace DSACore.Commands case "talent": case "talente": res.AddRange( - character.Talente.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); + character.Talente.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces( + first_column_width + 5) + " " + s.Probe)); break; case "zauber": case "z": res.AddRange( - character.Zauber.Select(s => (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces(first_column_width + 5) + " " + s.Probe)); + character.Zauber.Select(s => + (s.Name.AddSpaces(first_column_width) + " " + s.Value).AddSpaces( + first_column_width + 5) + " " + s.Probe)); break; case "w": case "waffe": @@ -118,13 +122,17 @@ namespace DSACore.Commands case "kampfwerte": res.Add("".AddSpaces(first_column_width) + " AT/PA"); res.AddRange( - character.Kampftalente.Select(s => s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + "/" + s.Pa.ToString().AddSpacesAtHead(2))); + character.Kampftalente.Select(s => + s.Name.AddSpaces(first_column_width) + " " + s.At.ToString().AddSpacesAtHead(2) + + "/" + s.Pa.ToString().AddSpacesAtHead(2))); break; case "f": case "fern": res.Add("".AddSpaces(first_column_width) + " FK"); res.AddRange( - character.Talente.Where(x => x.IstFernkampftalent()).Select(s => s.Name.AddSpaces(first_column_width) + " " + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); + character.Talente.Where(x => x.IstFernkampftalent()).Select(s => + s.Name.AddSpaces(first_column_width) + " " + + (character.Eigenschaften["fk"] + s.Value).ToString().AddSpacesAtHead(2))); break; case "v": case "vt": @@ -135,7 +143,7 @@ namespace DSACore.Commands case "nachteile": res.AddRange( character.Vorteile - .Select(s => s.Name + "\t " + s.Value)); + .Select(s => s.Name + "\t " + s.Value)); break; default: @@ -145,15 +153,11 @@ namespace DSACore.Commands res.Add(""); } - } var sb = new StringBuilder(); - foreach (string re in res) - { - sb.AppendLine(re); - } + foreach (var re in res) sb.AppendLine(re); return sb.ToString(); /* @@ -167,4 +171,4 @@ namespace DSACore.Commands }*/ } } -} +} \ No newline at end of file diff --git a/DSACore/Commands/Help.cs b/DSACore/Commands/Help.cs index 1575b36..6458c20 100644 --- a/DSACore/Commands/Help.cs +++ b/DSACore/Commands/Help.cs @@ -33,44 +33,43 @@ namespace DSACore.Commands public static string Get_Specific_Help(string command) { // return command specific help - var com = DSACore.DSA_Game.Save.Properties.CommandInfos.OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command + var com = DSA_Game.Save.Properties.CommandInfos + .OrderBy(x => SpellCorrect.CompareEasy(x.Name, command.ToLower())).First(); // get best fit command return com.GetDescription(); } public static string Get_Generic_Help() { - string res = ""; - foreach (var com in DSACore.DSA_Game.Save.Properties.CommandInfos) + var res = ""; + foreach (var com in DSA_Game.Save.Properties.CommandInfos) { - int first_column_width = 8; + var first_column_width = 8; res += ("!" + com.Name + ": ").AddSpaces(first_column_width) + com.Brief; if (com.Description.Length > 1) - { - res += "\n" + "".AddSpaces(first_column_width) + "(\"!man " + com.Name + "\" gibt genauere Informationen)"; - } + res += "\n" + "".AddSpaces(first_column_width) + "(\"!man " + com.Name + + "\" gibt genauere Informationen)"; res += "\n\n"; } + return res; } - + public static string ShowHelp(params string[] commandList) { var command = ""; - if (commandList.Length > 0) { - command = commandList.Aggregate((s, c) => s + " " + c); - } + if (commandList.Length > 0) command = commandList.Aggregate((s, c) => s + " " + c); if (command.Equals(string.Empty)) // return generic Help { - string res = Get_Generic_Help(); - + var res = Get_Generic_Help(); + return res; } - + return Get_Specific_Help(command); } } -} +} \ No newline at end of file diff --git a/DSACore/Commands/LebenUndAstral.cs b/DSACore/Commands/LebenUndAstral.cs index b5bc260..7e0cb5c 100644 --- a/DSACore/Commands/LebenUndAstral.cs +++ b/DSACore/Commands/LebenUndAstral.cs @@ -12,9 +12,9 @@ namespace DSACore.Commands public static string LEAsync(ulong id, string modifier) { //This is the string that will be printed - string res = ""; + var res = ""; + - //Get the actual text res += Dsa.GetCharacter(id).get_LE_Text(modifier); @@ -23,17 +23,17 @@ namespace DSACore.Commands } } - public class AE + public class AE { public static string AEAsync(ulong id, string modifier) { //This is the string that will be printed - string res = ""; + var res = ""; //Get the actual text res += Dsa.GetCharacter(id).get_AE_Text(modifier); - + return res; } } @@ -42,11 +42,11 @@ namespace DSACore.Commands { public static string get_LE_Text(this ICharacter c, string prop) { - string res = ""; + var res = ""; var comp = new SpellCorrect(); var character = c; - res += (character.Name + ":\n"); + res += character.Name + ":\n"; //If there is actual input we process it if (prop.Length > 0) @@ -60,15 +60,20 @@ namespace DSACore.Commands //Allow overflowing the max if (prop.StartsWith("++")) { - character.Lebenspunkte_Aktuell = character.Lebenspunkte_Aktuell + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); + character.Lebenspunkte_Aktuell = character.Lebenspunkte_Aktuell + + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); } else { - int temp = character.Lebenspunkte_Aktuell + Convert.ToInt32(prop) - character.Lebenspunkte_Basis; + var temp = character.Lebenspunkte_Aktuell + Convert.ToInt32(prop) - + character.Lebenspunkte_Basis; //Stop from overflow overflow if (temp > 0 && prop.StartsWith("+")) { - character.Lebenspunkte_Aktuell = (character.Lebenspunkte_Basis > character.Lebenspunkte_Aktuell) ? character.Lebenspunkte_Basis : character.Lebenspunkte_Aktuell; + character.Lebenspunkte_Aktuell = + character.Lebenspunkte_Basis > character.Lebenspunkte_Aktuell + ? character.Lebenspunkte_Basis + : character.Lebenspunkte_Aktuell; res += " Maximale Lebenspunkte sind erreicht "; } //Simply apply change @@ -91,23 +96,23 @@ namespace DSACore.Commands //If no value is passed, the curent value is displayed else { - res += ("LE: " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis); + res += "LE: " + character.Lebenspunkte_Aktuell + "/" + character.Lebenspunkte_Basis; } return res; } + public static string get_AE_Text(this ICharacter c, string prop) { - string res = ""; + var res = ""; var comp = new SpellCorrect(); var character = c; - res += (character.Name + ":\n"); + res += character.Name + ":\n"; //If there is actual input we process it if (prop.Length > 0) { - res += "AE: "; res += character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis + " -> "; @@ -117,15 +122,20 @@ namespace DSACore.Commands //Allow overflowing the max if (prop.StartsWith("++")) { - character.Astralpunkte_Aktuell = character.Astralpunkte_Aktuell + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); + character.Astralpunkte_Aktuell = character.Astralpunkte_Aktuell + + Convert.ToInt32(prop.Substring(1, prop.Length - 1)); } else { - int temp = character.Astralpunkte_Aktuell + Convert.ToInt32(prop) - character.Astralpunkte_Basis; + var temp = character.Astralpunkte_Aktuell + Convert.ToInt32(prop) - + character.Astralpunkte_Basis; //Stop from overflow overflow if (temp > 0 && prop.StartsWith("+")) { - character.Astralpunkte_Aktuell = (character.Astralpunkte_Basis > character.Astralpunkte_Aktuell) ? character.Astralpunkte_Basis : character.Astralpunkte_Aktuell; + character.Astralpunkte_Aktuell = + character.Astralpunkte_Basis > character.Astralpunkte_Aktuell + ? character.Astralpunkte_Basis + : character.Astralpunkte_Aktuell; res += " Maximale Astralpunkte sind erreicht "; } //Simply apply change @@ -142,7 +152,6 @@ namespace DSACore.Commands } res += character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis; - } //Set to new value regardless of original else @@ -155,14 +164,11 @@ namespace DSACore.Commands //If no value is passed, the curent value is displayed else { - res += ("AE: " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis); + res += "AE: " + character.Astralpunkte_Aktuell + "/" + character.Astralpunkte_Basis; } return res; } } -} - - - +} \ No newline at end of file diff --git a/DSACore/Commands/List.cs b/DSACore/Commands/List.cs index 1fa0dde..2c8f3d0 100644 --- a/DSACore/Commands/List.cs +++ b/DSACore/Commands/List.cs @@ -12,7 +12,7 @@ namespace DSACore.Commands public static string ListAsync(string prop) { var res = new List(); - + //int persist = 0; switch (prop.ToLower()) @@ -20,7 +20,7 @@ namespace DSACore.Commands case "man": case "help": return Help.Get_Specific_Help("List"); - // break; + // break; case "chars": res.AddRange(Dsa.Chars.Select(x => x.Name)); break; @@ -44,4 +44,4 @@ namespace DSACore.Commands return res.ToString(); } } -} +} \ No newline at end of file diff --git a/DSACore/Commands/MiscCommands.cs b/DSACore/Commands/MiscCommands.cs index 21646e7..36d5fb1 100644 --- a/DSACore/Commands/MiscCommands.cs +++ b/DSACore/Commands/MiscCommands.cs @@ -227,4 +227,4 @@ namespace DSACore.Commands }*/ } -} +} \ No newline at end of file diff --git a/DSACore/Commands/NpcCommands.cs b/DSACore/Commands/NpcCommands.cs index 50ea966..9a27e6a 100644 --- a/DSACore/Commands/NpcCommands.cs +++ b/DSACore/Commands/NpcCommands.cs @@ -12,16 +12,11 @@ namespace DSACore.Commands { public class NpcCommands { - public static string CreateNpc(ulong id, IEnumerable props, int modifier) { - if (int.TryParse(props.Last(), out int mean)) - { - return Random(id, props.First(), mean, modifier); - } + if (int.TryParse(props.Last(), out var mean)) return Random(id, props.First(), mean, modifier); return Copy(id, props.First(), props.Last(), modifier); - } private static string Random(ulong id, string npcName, int mean = 9, int stDv = 1) @@ -30,13 +25,10 @@ namespace DSACore.Commands Dsa.Chars.Add(new Npc(npcName, mean, stDv)); return $"{npcName} wurde zufällig generiert"; } - + private static string Copy(ulong id, string npcName, string source, int stDv = 1) { - if (Dsa.Chars.Exists(x => x.Name.Equals(npcName))) - { - throw new Exception("Char gibt es schon"); - } + if (Dsa.Chars.Exists(x => x.Name.Equals(npcName))) throw new Exception("Char gibt es schon"); throw new NotImplementedException(); var chr = Dsa.GetCharacter(id); Dsa.Chars.Add(new Character(chr as Character, npcName, stDv)); diff --git a/DSACore/Commands/ProbenTest.cs b/DSACore/Commands/ProbenTest.cs index a927cd9..d0800d6 100644 --- a/DSACore/Commands/ProbenTest.cs +++ b/DSACore/Commands/ProbenTest.cs @@ -1,6 +1,6 @@ namespace DSACore.Commands { - public class ProbenTest + public class ProbenTest { /*[Command("t"), Summary("Würfelt ein Talent-/Zauberprobe")] [Alias("T", "Talent", "talent", "versuche")] @@ -82,4 +82,4 @@ return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Session.Relation[this.Context.User.Username])).Fernkampf(waffe, erschwernis) + "\n```"); }*/ } -} +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf