diff --git a/Bot/Modules/OttoLinux/BotGame.cs b/Bot/Modules/OttoLinux/BotGame.cs index c37371c..69ca0b5 100644 --- a/Bot/Modules/OttoLinux/BotGame.cs +++ b/Bot/Modules/OttoLinux/BotGame.cs @@ -1,4 +1,5 @@ using System.Collections; +using Newtonsoft.Json; using SoUnBot.AccessControl; using SoUnBot.ModuleLoader; using Telegram.Bot; @@ -37,6 +38,7 @@ namespace SoUnBot.Modules.OttoLinux _playedQuestions = new Dictionary>(); if (version == 2) LoadQuestionsV2(); + else if (version == 3) LoadQuestionsJSON(); else LoadQuestions(); } public BotGame(AccessManager accessManager) @@ -104,6 +106,13 @@ namespace SoUnBot.Modules.OttoLinux SanitizeQuestions(); } + private void LoadQuestionsJSON() + { + var json = System.IO.File.ReadAllText(_questionsPath); + var quests = JsonConvert.DeserializeObject(json); + if (quests != null) _questions = quests.ToList(); + } + private void SanitizeQuestions() { var invalidQuestions = new List(); diff --git a/Bot/Modules/OttoLinux/Question.cs b/Bot/Modules/OttoLinux/Question.cs index 7ab89a5..c024267 100644 --- a/Bot/Modules/OttoLinux/Question.cs +++ b/Bot/Modules/OttoLinux/Question.cs @@ -3,13 +3,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Newtonsoft.Json; namespace SoUnBot.Modules.OttoLinux { public class Question { + [JsonProperty("quest")] public String Quest { get; set; } + [JsonProperty("answers")] public List Answers { get; } + [JsonProperty("correct")] public int Correct { get; private set; } public Question(String quest) diff --git a/Bot/Program.cs b/Bot/Program.cs index d5d95c7..684740f 100644 --- a/Bot/Program.cs +++ b/Bot/Program.cs @@ -25,13 +25,20 @@ try { foreach (string f in Directory.GetFiles(dataPath + "/Questions")) { - if (!f.EndsWith("txt")) + if (f.EndsWith("txt")) + { + Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f)); + moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false)); + } + else if (f.EndsWith("json")) + { + Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f)); + moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false, 3)); + } + else { Console.WriteLine("Skipping " + Path.GetFileName(f) + " as the file extension is not supported"); - continue; } - Console.WriteLine("Loading module " + Path.GetFileNameWithoutExtension(f)); - moduleLoader.LoadModule(new BotGame(acl, Path.GetFileNameWithoutExtension(f), f, false)); } foreach (string d in Directory.GetDirectories(dataPath + "/Questions")) {