mirror of
https://github.com/appinfosapienza/so-un-bot.git
synced 2025-05-06 00:52:34 +02:00
Add JSON support ...finally!
This commit is contained in:
parent
391862b3fb
commit
276ae8af2e
3 changed files with 24 additions and 4 deletions
|
@ -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<long, List<int>>();
|
||||
|
||||
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<Question[]>(json);
|
||||
if (quests != null) _questions = quests.ToList();
|
||||
}
|
||||
|
||||
private void SanitizeQuestions()
|
||||
{
|
||||
var invalidQuestions = new List<Question>();
|
||||
|
|
|
@ -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<string> Answers { get; }
|
||||
[JsonProperty("correct")]
|
||||
public int Correct { get; private set; }
|
||||
|
||||
public Question(String quest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue