From f62b15bca236e777d8b234efd06d646716ff5ba2 Mon Sep 17 00:00:00 2001 From: Marco Realacci Date: Sun, 21 Jan 2024 14:04:11 +0100 Subject: [PATCH] Fix bot considering empty lines --- Bot/Modules/OttoLinux/BotGame.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Bot/Modules/OttoLinux/BotGame.cs b/Bot/Modules/OttoLinux/BotGame.cs index 7653553..f1b2fa5 100644 --- a/Bot/Modules/OttoLinux/BotGame.cs +++ b/Bot/Modules/OttoLinux/BotGame.cs @@ -108,6 +108,7 @@ namespace SoUnBot.Modules.OttoLinux //var number = int.Parse(new StreamReader(w.GetResponse().GetResponseStream()).ReadToEnd()); var number = _rng.Next(1, _questions.Count - 1); + while (_questions[number].Quest == "") number = _rng.Next(1, _questions.Count - 1); if (!_playedQuestions.ContainsKey(player)) _playedQuestions.Add(player, new List()); @@ -336,8 +337,22 @@ namespace SoUnBot.Modules.OttoLinux { var qst = PickRandomQuestion(uid, botClient); - if (qst.Quest.StartsWith("img=")) Console.WriteLine("Sto inviando la domanda " + qst.Quest.Substring(qst.Quest.IndexOf("\n"), 7) + " a " + uid); - else Console.WriteLine("Sto inviando la domanda " + qst.Quest.Substring(0, 7) + " a " + uid); + try + { + if (qst.Quest.StartsWith("img=")) + Console.WriteLine("Sto inviando la domanda " + qst.Quest.Substring(qst.Quest.IndexOf("\n"), 7) + + " a " + uid); + else Console.WriteLine("Sto inviando la domanda " + qst.Quest.Substring(0, 7) + " a " + uid); + + } + catch(Exception e) + { + botClient.SendTextMessageAsync( + chatId: _accessManager.AdminId, + text: $"Question is malformed -> {qst.Quest} \n" + e.Message + ); + return; + } while (qst.Answers.Count == 0) {