示例#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);
 }