Пример #1
0
        static void FindSong(string src, Chat CurChat)
        {
            string next = FindRow(src, CurChat.Arr);

            if (next != null)
            {
                Say(next, CurChat);
                return;
            }
            else
            {
                WebClient wc   = new WebClient();
                string    goog = "http://www.google.com/search?q=" + src + " текст песни";
                goog.Replace(' ', '+');
                string s = wc.DownloadString(goog), temp;
                s = s.Substring(s.IndexOf("id=\"search\""));
                string[] urls = StringChanger.HTMLtoURLS(s);
                foreach (string url in urls)
                {
                    Console.WriteLine(url);
                    try
                    {
                        wc.Encoding = Encoding.UTF8;
                        temp        = wc.DownloadString(url);
                        if (!StringChanger.HasKirill(temp))
                        {
                            wc.Encoding = Encoding.Default;
                            temp        = wc.DownloadString(url);
                        }
                    }
                    catch (WebException e) { continue; }

                    string[] Song = StringChanger.HTMLtoText(temp);
                    CurChat.Arr = Song;
                    next        = FindRow(src, Song);
                    if (next != null)
                    {
                        Say(next, CurChat);
                        DB.SaveChat(CurChat, true);
                        return;
                    }
                }
            }

            Say(Answering("idk"), CurChat);
        }
Пример #2
0
 static void SimpleTextAnalyse(string src, Chat CurChat)
 {
     if (CurChat.AddNew == "")
     {
         if (!StringChanger.HasKirill(src))
         {
             src = StringChanger.LatinToKirill(src);
             Say(Answering("mistake") + "\n" + src, CurChat);
         }
         else
         {
             src = StringChanger.ToLower(src);
             src = StringChanger.RemoveSymb(src, "part");
             if (src[src.Length - 1] != '.' && src[src.Length - 1] != '?' && src[src.Length - 1] != '!')
             {
                 src += '.';
             }
             if (src.Length > 2 && src[0] == '?')
             {
                 Say(Answering("чтосказать"), CurChat);
                 CurChat.AddNew = src.Substring(1);
             }
             else if (StringChanger.HasKirill(src))
             {
                 TextToResp(src, CurChat);
             }
         }
     }
     else             // Addnew !=""
     {
         if (!DB.CancelSignal(src))
         {
             src = StringChanger.RemoveSymb(src, "none");
             DB.UpdateOrSaveReq(src, CurChat.AddNew);
             Say(Answering("запомню"), CurChat);
             Console.WriteLine(CurChat.ID + " added " + CurChat.AddNew + " -> " + src);
         }
         else if (CurChat.AddNew != "")
         {
             DB.DeleteReq(CurChat.AddNew);
             Say(Answering("cancel"), CurChat);
         }
         CurChat.AddNew = "";
     }
     DB.SaveChat(CurChat, false);
 }
Пример #3
0
        static void FindPhoto(string tag, Chat CurChat)
        {
            string url = "https://www.google.com/search?q=" + tag + "&tbm=isch";

            url.Replace(" ", "+");
            string data = "";

            var request  = (HttpWebRequest)WebRequest.Create(url);
            var response = (HttpWebResponse)request.GetResponse();

            using (Stream dataStream = response.GetResponseStream())
            {
                using (var sr = new StreamReader(dataStream))
                {
                    data = sr.ReadToEnd();
                }
            }
            //File.WriteAllText("log.html", data);
            CurChat.Arr   = StringChanger.HTMLtoPhoto(data);
            CurChat.index = 0;
            SendPhoto(CurChat);
        }
Пример #4
0
        static void FindRhyme(string src, Chat CurChat)
        {
            src = StringChanger.ToLower(src);
            if (src.IndexOf(' ') > 0)
            {
                src = src.Substring(src.LastIndexOf(' '));
            }
            if (src.Length < 0)
            {
                return;
            }
            CurChat.index = 0;
            CurChat.Arr   = null;
            string    goog = "https://rifmus.net/rifma/" + src;
            WebClient wc   = new WebClient();

            wc.Encoding = Encoding.UTF8;
            int    x = -1;
            string s = "";

            try
            {
                s = wc.DownloadString(goog);
                x = s.IndexOf("multicolumn");
            }
            catch {}
            if (x < 0)
            {
                Say(Answering("none"), CurChat);
                return;
            }
            s           = s.Substring(x);
            x           = s.IndexOf("</div>");
            s           = s.Substring(0, x);
            CurChat.Arr = StringChanger.HTMLtoText(s);
            SayRhymes(CurChat);
        }
Пример #5
0
        static string FindRow(string src, string[] Song)
        {
            bool found = false;

            if (Song != null)
            {
                foreach (string s in Song)
                {
                    if (!found && StringChanger.CalculateSimilarity(s, src) > 0.9)
                    {
                        found = true;
                    }
                    else if (found)
                    {
                        return(StringChanger.ToUpper(s));
                    }
                }
                if (found)
                {
                    return(Answering("finish"));
                }
            }
            return(null);
        }
Пример #6
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);
        }
Пример #7
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);
        }