Пример #1
0
        static public string Answering(string key, Chat CurChat = null)
        {
            string BotPrev;

            if (CurChat != null)
            {
                BotPrev = CurChat.BotPrev;
            }
            else
            {
                BotPrev = "";
            }
            string responce = "";

            if (key == null || key == "ignore")
            {
                return(null);
            }
            if (key == "привет" && BotPrev.Contains("привет"))
            {
                key = "а ты как";
            }
            if (key == "как дела" && !BotPrev.Contains("как дела"))
            {
                key += "+";
            }
            if ((key == "любима" || key == "любишь") && !CurChat.IsAdmin())
            {
                key += "-";
            }
            if (DB.ContainsKey(key))
            {
                responce = DB.RandResp(key) + " ";
                if (key == "приветствие")
                {
                    responce = DB.RandResp("привет") + ", " + responce + DB.RandResp("smile");
                }
                else if (key == "настроение")
                {
                    responce = DB.RandResp("настроение") + DB.RandResp("smile");
                }
                else if (key == "как дела+")
                {
                    responce = DB.RandResp("как дела") + ", " + responce;
                }
                else if ((key == "любима" || key == "любишь" || key == "пока") && CurChat.IsAdmin())
                {
                    responce += DB.RandResp("kiss");
                }
                else if (key.Contains("привет"))
                {
                    responce += DB.RandResp("smile");
                }
                else if (key == "none")
                {
                    responce += DB.RandResp("sad");
                }
            }
            else
            {
                responce = key;
            }
            return(responce);
        }
Пример #2
0
        private static void GetMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
        {
            var msg = e.Message;

            if (msg == null)
            {
                return;
            }
            msg.Date = msg.Date.ToLocalTime();
            if (TurnOn == DateTime.MinValue || DateTime.Compare(msg.Date, TurnOn) < 0)
            {
                return;                                                                                    ///not first
            }
            Chat CurChat = DB.IDtoChat(msg.Chat.Id);

            if (CurChat.LastMsgId == msg.MessageId)
            {
                return;
            }
            if (msg.Type == Telegram.Bot.Types.Enums.MessageType.Voice && CurChat.IsAdmin())
            {
                SpecCommands("block", CurChat);
            }
            if (msg.Type == Telegram.Bot.Types.Enums.MessageType.Text)
            {
                if (msg.Text[0] == '/')
                {
                    CommandAnalyse(msg.Text, CurChat, msg.Date);
                }
                else
                {
                    bool FromBot = msg.ReplyToMessage != null && msg.ReplyToMessage.From.Id == BOT;
                    if (!CurChat.IsPrivate() && !StringChanger.ToLower(StringChanger.RemoveSymb(msg.Text, "none")).Contains("сапфир") && !FromBot)
                    {
                        return;
                    }
                    if (CurChat.mode == 0)
                    {
                        SimpleTextAnalyse(msg.Text, CurChat);
                    }
                    else if (!TextToResp(msg.Text, CurChat))
                    {
                        if (!FromBot && !CurChat.IsPrivate())
                        {
                            return;
                        }
                        if (CurChat.mode == 1)
                        {
                            FindPhoto(msg.Text, CurChat);
                        }
                        else if (CurChat.mode == 2)
                        {
                            msg.Text = StringChanger.RemoveSymb(msg.Text, "none");
                            msg.Text = StringChanger.ToLower(msg.Text);
                            FindSong(msg.Text, CurChat);
                        }
                        else if (CurChat.mode == 3)
                        {
                            msg.Text = StringChanger.RemoveSpaces(msg.Text);
                            FindRhyme(msg.Text, CurChat);
                        }
                    }
                }
            }
            CurChat.LastMsgId = msg.MessageId;
            DB.SaveChat(CurChat, false);
        }
Пример #3
0
        static void CommandAnalyse(string src, Chat CurChat, DateTime DT)
        {
            if (src.Length < 1 || src[0] != '/')
            {
                return;
            }
            src = StringChanger.ToLower(src);
            int x = src.IndexOf("@");

            if (x > 0 && src.IndexOf(name) < 0)
            {
                return;
            }
            else if (x > 0)
            {
                src = src.Substring(0, x);
            }
            if (src == "/start")
            {
                Say(Answering("приветствие"), CurChat);
            }
            else if (src == "/reset")
            {
                SpecCommands("reset", CurChat);
            }
            else if (src == "/show")
            {
                SpecCommands("show", CurChat);
            }
            else if (src == "/exit")
            {
                SpecCommands("exit", CurChat);
            }
            else if (src == "/block")
            {
                SpecCommands("block", CurChat);
            }
            else if (src == "/full")
            {
                SpecCommands("full", CurChat);
            }
            else if (src == "/help")
            {
                Say(DB.Help(), CurChat);
            }
            else if (src == "/talk")
            {
                CurChat.ChangeMode(0);
            }
            else if (src == "/photo")
            {
                CurChat.ChangeMode(1);
            }
            else if (src == "/song")
            {
                CurChat.ChangeMode(2);
            }
            else if (src == "/poet")
            {
                CurChat.ChangeMode(3);
            }
            else if (src == "/ping")
            {
                Say(Pong(DT), CurChat);
            }
            else if (src == "/next" && CurChat.mode == 1)
            {
                SendPhoto(CurChat);
            }
            else if (src == "/next" && CurChat.mode == 3)
            {
                SayRhymes(CurChat);
            }
            else if (src == "/stat")
            {
                Say(Answering(CurChat.mode + "mode"), CurChat);
            }
            DB.SaveChat(CurChat, false);
        }