Пример #1
0
        public void StartBot()
        {
            string key = "622335668:AAEv62L9dRi4BH6JVyW8gfEg-tCmd-qTRXo";

            this.bw         = new BackgroundWorker();
            this.bw.DoWork += bw_DoWork;
            this.bw.RunWorkerAsync(key);
            BotAs = new BotAssistent();
        }
Пример #2
0
        async void GetQuestion(Telegram.Bot.TelegramBotClient Bot, Telegram.Bot.Args.CallbackQueryEventArgs ev, Telegram.Bot.Types.Message message)
        {
            await Bot.AnswerCallbackQueryAsync(ev.CallbackQuery.Id);

            if (!BotAs.GameStarted)
            {
                BotAs = new BotAssistent();
            }


            Country country   = BotAs.GetRandomCountry();
            string  tCountry1 = country.Name;
            string  tCapital1 = country.Capital;
            string  tFlagPath = country.Flag;

            string tCapital2 = BotAs.GetRandomCapital(tCapital1, "");
            string tCapital3 = BotAs.GetRandomCapital(tCapital1, tCapital2);


            //Визначаємо рандомно порядок правильної відповіді
            Random rnd      = new Random();
            int    rndValue = rnd.Next(1, 4);

            Dictionary <int, string> dic = new Dictionary <int, string>();

            dic.Add(rndValue, tCapital1);

            if (rndValue == 1)
            {
                dic.Add(2, tCapital2);
                dic.Add(3, tCapital3);
            }
            else if (rndValue == 2)
            {
                dic.Add(1, tCapital2);
                dic.Add(3, tCapital3);
            }
            else
            {
                dic.Add(1, tCapital2);
                dic.Add(2, tCapital3);
            }

            dic = dic.OrderBy(x => x.Key).ToDictionary(y => y.Key, z => z.Value);


            var keyboard = new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardMarkup(
                new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardButton[][]
            {
                new [] {
                    new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardButton {
                        Text = dic[1], CallbackData = (rndValue == 1) ? "correctAnswer" + tCountry1 : "wrongAnswer"
                    },
                    new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardButton {
                        Text = dic[2], CallbackData = (rndValue == 2) ? "correctAnswer" + tCountry1 : "wrongAnswer"
                    },
                    new Telegram.Bot.Types.ReplyMarkups.InlineKeyboardButton {
                        Text = dic[3], CallbackData = (rndValue == 3) ? "correctAnswer" + tCountry1 : "wrongAnswer"
                    },
                },
            }
                );

            await Bot.SendTextMessageAsync(message.Chat.Id, tCountry1 + " ?", replyMarkup : keyboard);

            await Bot.SendPhotoAsync(message.Chat.Id, tFlagPath, "");
        }