public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { string url = "http://know-that.ru/randomizer.php"; string result = string.Empty; HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Encoding = Encoding.GetEncoding(1251); hrm.Get(url); HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(hrm.Html); HtmlNodeCollection factList = htmlDoc.DocumentNode.SelectNodes(@"//./center/table"); if (factList != null) { Random random = new Random(); int showResult = random.Next(factList.Count-1); HtmlNodeCollection tds = factList[showResult].SelectNodes(".//./td");//.InnerText.Trim(); if ((tds != null) && (tds.Count >= 3)) { result = tds[2].InnerText.Trim(); } else { result = "Факт сломался... :("; } } else { result = "Факты кончились... :("; } sendMessageFunc(result,AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string,AnswerBehaviourType> sendMessageFunc) { HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Encoding = Encoding.GetEncoding(1251); hrm.Get("http://f*****g-great-advice.ru/api/random"); var json = JsonConvert.DeserializeObject<dynamic>(hrm.Html); string advice = json.text.ToString(); sendMessageFunc(HttpUtility.HtmlDecode(advice.RemoveAllTags()), AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { HtmlReaderManager hrm = new HtmlReaderManager(); Regex r = new Regex("[а-яА-ЯЁё]+"); bool isRu = r.IsMatch(args); string fromLang = isRu ? "ru" : "en"; string toLang = isRu ? "en" : "ru"; hrm.Get(string.Format("https://translate.google.ru/translate_a/single?client=t&sl={0}&tl={1}&hl=ru&dt=bd&dt=ex&dt=ld&dt=md&dt=qc&dt=rw&dt=rm&dt=ss&dt=t&dt=at&dt=sw&ie=UTF-8&oe=UTF-8&oc=1&otf=2&ssel=0&tsel=0&q=", fromLang, toLang) + HttpUtility.UrlEncode(args)); string html = hrm.Html; string anwser = html.Substring(4, html.IndexOf(@""",""") - 4); sendMessageFunc(anwser, AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string,AnswerBehaviourType> sendMessageFunc) { HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Get("http://pogoda.tut.by/"); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var tds = htmlDoc.DocumentNode.SelectNodes(@"//./td[@class='fcurrent-top' or @class='fcurrent-s']"); StringBuilder sb = new StringBuilder(); sb.Append("Погода в Минске :"); foreach (var td in tds) { sb.Append(td.SelectSingleNode(".//./div[@class='fcurrent-h']").InnerText + " "); sb.Append(td.SelectSingleNode(".//./span[@class='temp-i']").InnerText + " "); sb.Append(td.SelectSingleNode(".//./div[@class='fcurrent-descr']").InnerText + " "); sb.Append(Environment.NewLine); } sendMessageFunc(sb.ToString().Replace("°", "°"), AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { args = args.Replace("?"," ").Trim(); string answer = string.Empty; HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Get(string.Format("http://ru.wikipedia.org/w/index.php?search={0}",HttpUtility.UrlEncode(args))); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var content = htmlDoc.DocumentNode.SelectSingleNode(@"//./div[@id='mw-content-text']/p"); if (content != null && !content.InnerText.Contains("запросу не найдено")) { string h = content.InnerHtml; if (h.Contains("<b>")) { h = HttpUtility.HtmlDecode(h.Substring(h.IndexOf("<b>"))).Replace("\n", ""); htmlDoc.LoadHtml(h); h = Regex.Replace(htmlDoc.DocumentNode.InnerText, @"( ?\[.*?\])|( ?\(.*?\))", ""); if (h.Contains(".")) { h = h.Substring(0,h.IndexOf(".")); answer = h.Length > 700 ? h.Substring(0, 700) + "..." : h+"."; } } } if(string.IsNullOrEmpty(answer)) { answer = notFoundAnswers[r.Next(0,notFoundAnswers.Count)]; } else { answer += ". " + hrm.ResponseUri; } sendMessageFunc(answer, AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { if (!Images.Any()) { HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Get("http://boobs-selfshots.tumblr.com/page/" + r.Next(1, 600)); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var divs = htmlDoc.DocumentNode.SelectNodes(@"//./div[@class='photo_post']/a/img"); StringBuilder sb = new StringBuilder(); foreach (var div in divs) { Images.Add(div.Attributes["src"].Value); } } int rPos = r.Next(0, Images.Count); string url = Images[rPos]; Images.RemoveAt(rPos); sendMessageFunc(url, AnswerBehaviourType.Link); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { StringBuilder result = new StringBuilder(); HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Encoding = Encoding.GetEncoding(1251); hrm.Get(@"http://www.goroskop.org/luna/049/segodnya.shtml"); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); //title result.Append(htmlDoc.DocumentNode.SelectSingleNode(@"//./span[@class='tabl-header']").InnerText.Trim()); result.Append(Environment.NewLine); //info HtmlNodeCollection tblSpans = htmlDoc.DocumentNode.SelectNodes(@"//./span[@class='tabl-content']"); if ((tblSpans != null) && (tblSpans.Count >= 1)) { HtmlNodeCollection tds = tblSpans[1].SelectNodes(@".//./table[1]/tr/td"); if ((tds != null) && (tds.Count >= 2)) { result.Append(tds[1].InnerText);//.InnerHtml.Replace("<br>", Environment.NewLine).RemoveAllTags().Trim(); } } sendMessageFunc(result.ToString(), AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { if (!Jokes.Any()) { HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Encoding = Encoding.GetEncoding(1251); hrm.Get("http://bash.im/random"); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var divs = htmlDoc.DocumentNode.SelectNodes(@"//./div[@class='text']"); foreach (var div in divs) { Jokes.Add(HttpUtility.HtmlDecode(div.InnerHtml.Replace("<br>", Environment.NewLine))); } } int rPos = r.Next(0, Jokes.Count ); string joke = Jokes[rPos]; Jokes.RemoveAt(rPos); sendMessageFunc(joke, AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { if (!Jokes.Any()) { HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Get("http://ithappens.me/random"); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var divs = htmlDoc.DocumentNode.SelectNodes(@"//./div[@class='text']"); foreach (var div in divs) { Jokes.Add(div.InnerHtml.Replace("<p>", "").Replace("</p>", Environment.NewLine + Environment.NewLine).RemoveAllTags().Trim()); } } int rPos = r.Next(0, Jokes.Count ); string joke = Jokes[rPos]; Jokes.RemoveAt(rPos); sendMessageFunc(joke, AnswerBehaviourType.Text); }
public void HandleMessage(string command, string args, object clientData, Action<string, AnswerBehaviourType> sendMessageFunc) { string[] arg = args.Split(' '); string url = "http://goroskop.open.by/pda/"; StringBuilder result = new StringBuilder(); string sign, term="today", category="ОБЩИЙ"; string help = "!гороскоп <знак зодиака> [общий/эротический/антигороскоп/бизнес/любовный/здоровья/кулинарный/мобильный] [сегодня/завтра/неделя/месяц/год]"; if (arg.Length == 0) { sendMessageFunc(help, AnswerBehaviourType.Text); return; } if ((arg.Length >= 1) && (Signs.TryGetValue(arg[0].ToUpper(), out sign))) { url += sign; } else { if (string.IsNullOrEmpty(arg[0])){ sendMessageFunc(help, AnswerBehaviourType.Text); }else{ sendMessageFunc(arg[0] + " - неверный знак зодиака", AnswerBehaviourType.Text); } return; } if (arg.Length == 2) { if (!Terms.TryGetValue(arg[1].ToUpper(), out term)) category = arg[1].ToUpper(); }else{ if (arg.Length >= 2) { category = arg[1].ToUpper(); } if ((arg.Length >= 3) && (!Terms.TryGetValue(arg[2].ToUpper(), out term))) { result.Append(arg[2].ToUpper() + " - неверно задан срок. Возможные варианты: [сегодня/завтра/неделя/месяц/год] "); result.Append(Environment.NewLine); } } url += term; HtmlReaderManager hrm = new HtmlReaderManager(); hrm.Get(url); string html = hrm.Html; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); //title result.Append(arg[0].ToUpper()+" "); result.Append(htmlDoc.DocumentNode.SelectSingleNode(@"//./p[@class='horoTitleName']/span").InnerText); result.Append(Environment.NewLine); //select proper horoscope category HtmlNodeCollection horoCategories = htmlDoc.DocumentNode.SelectNodes(@"//./p[@class='categoryName' or @class='categoryText']"); if ((horoCategories != null)&&(horoCategories.Count >= 2)) { bool categoryFound = false; for (int i = 0; i < horoCategories.Count; i = i + 2) { if (horoCategories[i].InnerText.ToUpper() == category) { result.Append(category); result.Append(Environment.NewLine); result.Append(horoCategories[i + 1].InnerText); categoryFound = true; break; } } if (!categoryFound) { result.Append(category.ToUpper() + " - не удалось найти гороскоп такого типа."); result.Append(Environment.NewLine); result.Append(horoCategories[0].InnerText.ToUpper()); result.Append(Environment.NewLine); result.Append(horoCategories[1].InnerText); } } else { result.Append("На запрашиваемый Вами период гороскоп отсутствует"); } sendMessageFunc(result.ToString(), AnswerBehaviourType.Text); }