Пример #1
0
        static void SendMessage(SimpleCross scw)
        {
            Stopwatch stp = new Stopwatch();

            stp.Start();

            long   id     = scw.id;
            string legend = "";

            for (int i = 0; i < scw.words.Count; i++)
            {
                if (!scw.is_answered[i])
                {
                    legend = legend + scw.legend[i];
                }
            }


            string url = EngBot.bot.Api.Photo.GetMessagesUploadServer(id).UploadUrl;

            var uploader = new WebClient();
            var uploadResponseInBytes  = uploader.UploadFile(url, @"users\" + id + @"\cross.jpg");
            var uploadResponseInString = Encoding.UTF8.GetString(uploadResponseInBytes);
            // VKRootObject response = Methods.DeSerializationObjFromStr<VKRootObject>(uploadResponseInString);
            var photos = EngBot.bot.Api.Photo.SaveMessagesPhoto(uploadResponseInString);

            try
            {
                EngBot.bot.Api.Messages.Send(new VkNet.Model.RequestParams.MessagesSendParams()
                {
                    RandomId    = Environment.TickCount64,
                    UserId      = id,
                    Message     = legend,
                    Attachments = photos
                });

                stp.Stop();
            }
            catch (VkNet.Exception.TooMuchOfTheSameTypeOfActionException)
            {
                Console.WriteLine("VK poshel v zhopu");
            }
            catch (VkNet.Exception.PublicServerErrorException)
            {
                Console.WriteLine("Server error with sending message!");
            }
            catch (VkNet.Exception.CannotSendToUserFirstlyException)
            {
                Console.WriteLine("Server error with sending message!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Some error with sending gallow");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            Console.WriteLine("Elapsed for sending: " + stp.ElapsedMilliseconds);
        }
Пример #2
0
        static void Crossvord_thread_start(object Idobj)
        {
            long id = (long)Idobj;

            var scw = new SimpleCross(id);

            EngBot.users[id].keyb = User.Crossword1_Keyboard;
            EngBot.SendMessage(id, "Итак, твоя задача - перевести пронумерованные слова на английский.");
            EngBot.SendMessage(id, "Полученное слово, выделенное жёлтым, требуется перевести на русский.");
            EngBot.SendMessage(id, "Жду переводы по-порядку или ответы в виде:\n цифра перевод ", null, true);

            SendMessage(scw);

            if (Wait_normal_answers(scw))
            {
                EngBot.users[id].cross_passed++;
            }
            EngBot.users[id].on_Test = false;
        }
Пример #3
0
        static bool Wait_normal_answers(SimpleCross scw)
        {
            int wait_time = 5;
            var ind       = IndicatorTimer(wait_time);

            long   userID    = scw.id;
            var    user      = EngBot.users[scw.id];
            string text      = user.lastMsg.Item1.ToLower();
            long   ident_msg = user.lastMsg.Item3;

            while (true)
            {
                if (ind.x)
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(userID, "Ладно, тогда потом поиграем...", null, true);
                    return(false);
                }
                if (ident_msg == user.lastMsg.Item3)
                {
                    Thread.Sleep(100);
                    continue;
                }

                ind.x = true;
                ind   = IndicatorTimer(wait_time);

                ident_msg = user.lastMsg.Item3;
                text      = EngBot.GetFormatedWord(user.lastMsg.Item1);
                if (text == null || text.Length == 0)
                {
                    EngBot.SendMessage(userID, "Я жду текстовые ответы");
                    continue;
                }
                var words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (text == "/hint" || text == "подсказать слово")
                {
                    EngBot.SendMessage(userID, @"Ну как хочешь :-\");
                    for (int i = 0; i < scw.is_answered.Count; i++)
                    {
                        if (!scw.is_answered[i])
                        {
                            scw.DrawWord(i);
                            SendMessage(scw);
                            break;
                        }
                    }
                    if (scw.is_all_answered)
                    {
                        break;
                    }
                    continue;
                }

                if (text == "/give_up" || text == "я сдаюсь")
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(userID, @"Ну как хочешь :-\", null, true);
                    scw.DrawWords();
                    SendMessage(scw);
                    return(false);
                }

                if (words.Length == 1)
                {
                    int i = scw.is_answered.FindIndex(x => !x);
                    if (i >= scw.words.Count || i < 0)
                    {
                        break;
                    }
                    if (text != scw.words[i].Item1)
                    {
                        EngBot.SendMessage(userID, "Ошибочка, попробуй ещё раз.");
                        continue;
                    }
                    EngBot.SendMessage(userID, "Отлично");
                    scw.DrawWord(i);
                    SendMessage(scw);

                    if (scw.is_all_answered)
                    {
                        break;
                    }
                    continue;
                }

                if (words.Length > 2)
                {
                    EngBot.SendMessage(userID, @"Что-то не так с количеством слов :-\");
                    continue;
                }
                int num = -1;
                if (!int.TryParse(words[0], out num))
                {
                    EngBot.SendMessage(userID, $" \"{words[0]}\" - это точно цифра?)");
                    continue;
                }
                if (num < 1 || num > scw.words.Count)
                {
                    EngBot.SendMessage(userID, "Такого номера я не вижу...");
                    continue;
                }
                if (scw.is_answered[num - 1])
                {
                    EngBot.SendMessage(userID, "Это слово уже отгадано.");
                    continue;
                }
                if (scw.words[num - 1].Item1 != words[1])
                {
                    EngBot.SendMessage(userID, "Ошибочка, попробуй ещё раз.");
                    continue;
                }
                EngBot.SendMessage(userID, "Отлично");
                scw.DrawWord(num - 1);

                SendMessage(scw);

                if (scw.is_all_answered)
                {
                    break;
                }
            }

            user.keyb = User.Crossword2_Keyboard;
            EngBot.SendMessage(userID, "Супер, так что же такое " + scw.MainWord.Item1 + "?", null, true);

            //string ans = EngBot.dictionary[scw.MainWord.Item2].rus;
            List <string> ans = new List <string>();

            foreach (var def in EngBot.dictionary[scw.MainWord.Item2].mean_rus.def)
            {
                ans.Add(def.tr[0].text);
            }

            while (true)
            {
                if (ind.x)
                {
                    user.keyb = User.Main_Keyboard;
                    EngBot.SendMessage(userID, "Ладно, тогда потом поиграем...", null, true);
                    return(false);
                }
                if (ident_msg == user.lastMsg.Item3)
                {
                    Thread.Sleep(100);
                    continue;
                }

                ind.x     = true;
                ind       = IndicatorTimer(wait_time);
                ident_msg = user.lastMsg.Item3;
                text      = EngBot.GetFormatedWord(user.lastMsg.Item1);
                if (text == null || text.Length == 0)
                {
                    EngBot.SendMessage(userID, "Я жду текстовые ответы");
                    continue;
                }
                if (text == "/give_up" || text == "я сдаюсь")
                {
                    user.keyb = User.Main_Keyboard;
                    string s = $"Стыдно не знать, это же ";
                    for (int i = 0; i < ans.Count; i++)
                    {
                        s += ans[i];
                        if (i != ans.Count - 1)
                        {
                            s += @"/";
                        }
                    }
                    EngBot.SendMessage(userID, s);
                    EngBot.SendMessage(userID, $"В следующий раз повтори слова тщательней)", null, true);
                    return(false);
                }

                if (!ans.Contains(text))
                {
                    EngBot.SendMessage(userID, "Ошибочка, попробуй ещё раз.");
                    continue;
                }
                break;
            }
            user.keyb = User.Main_Keyboard;
            EngBot.SendMessage(userID, "Правильно, поздравляю!", null, true);
            return(true);
        }