diff options
author | TrueDoctor <d-kobert@web.de> | 2018-04-09 14:13:28 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-04-09 14:13:28 +0200 |
commit | 5cb8346a6a3ccc55295c00ac333e410629ff7c42 (patch) | |
tree | 1603fdf24f1ead61cf7dd23c09a9784cfb1c780e /DiscoBot/Commands/FileHandler.cs | |
parent | e49ac2778bb6d38517f14447c0675df354552528 (diff) | |
parent | 4ca7291ebee440d9f3ef2a1643d8d01b29006459 (diff) |
Merge branch 'Reset'
Diffstat (limited to 'DiscoBot/Commands/FileHandler.cs')
-rw-r--r-- | DiscoBot/Commands/FileHandler.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/DiscoBot/Commands/FileHandler.cs b/DiscoBot/Commands/FileHandler.cs new file mode 100644 index 0000000..efebe3f --- /dev/null +++ b/DiscoBot/Commands/FileHandler.cs @@ -0,0 +1,43 @@ +namespace DiscoBot.Commands +{ + using System; + using System.Linq; + using System.Net; + + using DiscoBot.Auxiliary; + using DiscoBot.Characters; + + using Discord.Commands; + + public class FileHandler : ModuleBase + { + [Command("add"), Summary("fügt Helden hinzu")] + public void AddChar() + { + var msg = this.Context.Message; + if (msg.Attachments == null) + { + throw new ArgumentException("Es wurde keine Datei angehängt"); + } + + var attachments = msg.Attachments.ToList(); + + if (!attachments.Any(x => x.Filename.EndsWith(".xml"))) + { + throw new ArgumentException("Es wurde kein xml Held mitgeschickt"); + } + + foreach (var attachment in attachments.Where(x => x.Filename.EndsWith(".xml"))) + { + using (var client = new WebClient()) + { + client.DownloadFile(attachment.Url, "helden\\" + attachment.Filename); + } + + Dsa.Chars.Add(new Character("helden\\" + attachment.Filename)); + (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)); + } + } + } +} |