diff options
author | TrueDoctor <d-kobert@web.de> | 2018-09-26 20:51:37 +0200 |
---|---|---|
committer | TrueDoctor <d-kobert@web.de> | 2018-09-26 20:51:37 +0200 |
commit | b411aa2128c2724bec0ecedb8cb4e1ffa59f3b53 (patch) | |
tree | 14e0a0cca2cf66b95fda402c8c7d7b6bd5b7b222 /DSACore/DSA_Game/Save/SaveCommand.cs | |
parent | 92e8bb7523c775014ccf68355e3f0178ebf4a61c (diff) |
disconnected most vital calles from the Discord Bot
Diffstat (limited to 'DSACore/DSA_Game/Save/SaveCommand.cs')
-rw-r--r-- | DSACore/DSA_Game/Save/SaveCommand.cs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/DSACore/DSA_Game/Save/SaveCommand.cs b/DSACore/DSA_Game/Save/SaveCommand.cs new file mode 100644 index 0000000..9a2ae8e --- /dev/null +++ b/DSACore/DSA_Game/Save/SaveCommand.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using System.Threading.Tasks; + +namespace DiscoBot.DSA_Game.Save +{ + using System.IO; + + public class SaveCommand + { + public void LoadSession(string name = "") + { + if (name.Equals("?") || name.Equals(string.Empty)) + { + Console.WriteLine($"Gespeicherte Sessions:"); + Console.WriteLine(this.ListSessions()); + return; + } + + var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name; + + var files = Directory.GetFiles(path); + var session = files.OrderByDescending(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())).First(); + Dsa.Session = Session.Load(session); + + Console.WriteLine($"{name} wurde geladen"); + } + + public void SessionSave(string name = "") + { + //var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif"); + + if (name.Equals("?") || name.Equals(string.Empty)) + { + Console.WriteLine($"Gespeicherte Sessions:"); + Console.WriteLine(this.ListSessions()); + return; + } + + var path = DSA_Game.Save.Session.DirectoryPath + @"\" + name; + if (Directory.Exists(path)) + { + var files = Directory.GetFiles(path); + int current = files.Max(x => Convert.ToInt32(x.Split('-').Last().Split('.').First())); + Dsa.Session.SessionName = name; + Dsa.Session.Save(path + "\\" + name + $"-{++current}.json"); + } + else + { + Directory.CreateDirectory(path); + Dsa.Session.SessionName = name; + Dsa.Session.Save(path + "\\" + name + $"-0.json"); + } + + Console.WriteLine($"{name} wurde gespeichert"); + //await sendFile; + } + + private string[] ListSessions() + { + string[] dirs = Directory.GetDirectories(Session.DirectoryPath).OrderByDescending(x => new DirectoryInfo(x).LastAccessTime.Ticks).ToArray(); + for (int i = 0; i < dirs.Length; i++) + { + dirs[i] += "; " + new DirectoryInfo(dirs[i]).LastAccessTime; + } + + return dirs; + } + } +} |