Beispiel #1
0
        //ждет ответа !определенного! ответа от юзера,
        //always отвечает за время ожидания(false - 1 попытка, true - ждет, пока юзер не напишет нужное)
        static long WaitWordFromUser(long userID, string[] word, long word_id, int wait_time = 5)
        {
            var ind  = Timers.IndicatorTimer(wait_time);
            var user = users.GetUser(userID);

            while (user.lastMsg.Item2 != false)
            {
                if (ind.x)
                {
                    return(-1);
                }
                Thread.Sleep(100);
            }
            WriteLine("get word");
            WriteLine(user.lastMsg.Item3);
            user.lastMsg.Item2 = true;
            user.lastMsg.Item1 = GetFormatedWord(user.lastMsg.Item1);
            return(word.Any(x => x == user.lastMsg.Item1) ? -word_id : user.lastMsg.Item3);
        }
Beispiel #2
0
        static bool WaitAgreeFromUser_Timer(long userID, string[] agree, string[] deny, int wait_time, string wait_message, string wrong_ans = "Не понял")
        {
            var user = users.GetUser(userID);

            var  ind       = Timers.IndicatorTimer(wait_time);
            long ident_msg = user.lastMsg.Item3;

            while (true)
            {
                if (ind.x)
                {
                    if (user.tests_passed > 0)
                    {
                        user.keyb = User.Main_Keyboard;
                    }
                    SendMessage(userID, wait_message, null, true);
                    return(false);
                }
                if (ident_msg == user.lastMsg.Item3)
                {
                    Thread.Sleep(100);  //ожидание согласия
                    continue;
                }
                ident_msg = user.lastMsg.Item3;
                string text = GetFormatedWord(user.lastMsg.Item1);

                if (agree.Any(x => x == text))
                {
                    break;
                }
                if (deny.Any(x => x == text))
                {
                    user.keyb = User.Main_Keyboard;
                    SendMessage(userID, wait_message, null, true);
                    return(false);
                }
                SendMessage(userID, wrong_ans, null, true);
            }
            user.lastMsg.Item2 = true;
            WriteLine($"Get \"Ready\" from {userID}");
            ind.x = true;
            return(true);
        }
Beispiel #3
0
        static void WaitWords(long id, int wait_time = 15, string error_msg = "Ладно, давай в другой раз")
        {
            var user = users.GetUser(id);
            var ind  = Timers.IndicatorTimer(wait_time);

            long ident_msg = user.lastMsg.Item3;

            while (true)
            {
                if (ind.x)
                {
                    user.keyb = User.Main_Keyboard;
                    SendMessage(id, error_msg, null, true);
                    return;
                }
                if (ident_msg == user.lastMsg.Item3)
                {
                    Thread.Sleep(100);
                    continue;
                }
                ident_msg = user.lastMsg.Item3;
                var text = GetFormatedWord(user.lastMsg.Item1);
                if (text == "вернуться назад")
                {
                    user.keyb = User.Main_Keyboard;
                    SendMessage(id, error_msg, null, true);
                    return;
                }
                var errors = user.AddWords(text);
                user.keyb = User.Main_Keyboard;

                if (errors.Item1.Length == 0 && errors.Item2 == 0)
                {
                    SendMessage(id, "Я тут ничего не разобрал🙃", null, true);
                    return;
                }

                if (errors.Item2 != 0)
                {
                    SendMessage(id, $"Добавлено слов: {errors.Item2}.", null, true);
                }
                if (errors.Item1.Length > 0)
                {
                    var str = "Данные слова я не распознал🙃: ";
                    for (int i = 0; i < errors.Item1.Length; i++)
                    {
                        if (i + 1 == errors.Item1.Length)
                        {
                            str += errors.Item1[i] + ".";
                        }
                        else
                        {
                            str += errors.Item1[i] + ", ";
                        }
                    }
                    SendMessage(id, str);
                    SendMessage(id, "Убедитесь в правильности их написания и попробуйте их добавить ещё раз.", null, true);
                }
                return;
            }
        }