static async void ProcessUpdate(TelegramBotClient bot, Update update, User me) { // Read Configuration var wundergroundKey = ConfigurationManager.AppSettings["WundergroundKey"]; var bingKey = ConfigurationManager.AppSettings["BingKey"]; var wolframAppId = ConfigurationManager.AppSettings["WolframAppID"]; // Process Request try { var httpClient = new ProHttpClient(); var text = update.Message.Text; var replyText = string.Empty; var replyTextMarkdown = string.Empty; var replyImage = string.Empty; var replyImageCaption = string.Empty; var replyDocument = string.Empty; if (text != null && (text.StartsWith("/", StringComparison.Ordinal) || text.StartsWith("!", StringComparison.Ordinal))) { // Log to console Console.WriteLine(update.Message.Chat.Id + " < " + update.Message.From.Username + " - " + text); // Allow ! or / if (text.StartsWith("!", StringComparison.Ordinal)) { text = "/" + text.Substring(1); } // Strip @BotName text = text.Replace("@" + me.Username, ""); // Parse string command; string body; if (text.StartsWith("/s/", StringComparison.Ordinal)) { command = "/s"; // special case for sed body = text.Substring(2); } else { command = text.Split(' ')[0]; body = text.Replace(command, "").Trim(); } var stringBuilder = new StringBuilder(); switch (command.ToLowerInvariant()) { case "/beer": if (body == string.Empty) { replyText = "Usage: /beer <Name of beer>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); var beerSearch = httpClient.DownloadString("http://www.beeradvocate.com/search/?q=" + HttpUtility.UrlEncode(body) + "&qt=beer").Result.Replace("\r", "").Replace("\n", ""); // Load First Result var firstBeer = Regex.Match(beerSearch, @"<div id=""ba-content"">.*?<ul>.*?<li>.*?<a href=""(.*?)"">").Groups[1].Value.Trim(); if (firstBeer == string.Empty) { replyText = "The Great & Powerful Trixie was unable to find a beer name matching: " + body; break; } var beer = httpClient.DownloadString("http://www.beeradvocate.com" + firstBeer).Result.Replace("\r", "").Replace("\n", ""); var beerName = Regex.Match(beer, @"<title>(.*?)</title>").Groups[1].Value.Replace(" | BeerAdvocate", string.Empty).Trim(); beer = Regex.Match(beer, @"<div id=""ba-content"">.*?<div>(.*?)<div style=""clear:both;"">").Groups[1].Value.Trim(); replyImage = Regex.Match(beer, @"img src=""(.*?)""").Groups[1].Value.Trim(); replyImageCaption = "http://www.beeradvocate.com" + firstBeer; var beerScore = Regex.Match(beer, @"<span class=""BAscore_big ba-score"">(.*?)</span>").Groups[1].Value.Trim(); var beerScoreText = Regex.Match(beer, @"<span class=""ba-score_text"">(.*?)</span>").Groups[1].Value.Trim(); var beerbroScore = Regex.Match(beer, @"<span class=""BAscore_big ba-bro_score"">(.*?)</span>").Groups[1].Value.Trim(); var beerbroScoreText = Regex.Match(beer, @"<b class=""ba-bro_text"">(.*?)</b>").Groups[1].Value.Trim(); var beerHads = Regex.Match(beer, @"<span class=""ba-ratings"">(.*?)</span>").Groups[1].Value.Trim(); var beerAvg = Regex.Match(beer, @"<span class=""ba-ravg"">(.*?)</span>").Groups[1].Value.Trim(); var beerStyle = Regex.Match(beer, @"<b>Style:</b>.*?<b>(.*?)</b>").Groups[1].Value.Trim(); var beerAbv = beer.Substring(beer.IndexOf("(ABV):", StringComparison.Ordinal) + 10, 7).Trim(); var beerDescription = Regex.Match(beer, @"<b>Notes / Commercial Description:</b>(.*?)</div>").Groups[1].Value.Replace("|", "").Trim(); stringBuilder.Append(beerName.Replace("|", "- " + beerStyle + " by") + "\r\nScore: " + beerScore + " (" + beerScoreText + ") | Bros: " + beerbroScore + " (" + beerbroScoreText + ") | Avg: " + beerAvg + " (" + beerHads + " hads)\r\nABV: " + beerAbv + " | "); stringBuilder.Append(HttpUtility.HtmlDecode(beerDescription).Replace("<br>"," ").Trim()); break; case "/cat": replyImage = "http://thecatapi.com/api/images/get?format=src&type=jpg,png"; break; case "/doge": replyImage = "http://dogr.io/wow/" + body.Replace(",", "/").Replace(" ", "") + ".png"; replyImageCaption = "wow"; break; case "/echo": replyText = body; break; case "/fat": if (body == string.Empty) { replyText = "Usage: /fat <Name of food>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); var search = httpClient.DownloadString("http://www.calorieking.com/foods/search.php?keywords=" + body).Result.Replace("\r", "").Replace("\n", ""); // Load First Result var firstUrl = Regex.Match(search, @"<a class=""food-search-result-name"" href=""([\w:\/\-\._]*)""").Groups[1].Value.Trim(); if (firstUrl == string.Empty) { replyText = "The Great & Powerful Trixie was unable to find a food name matching: " + body; break; } var food = httpClient.DownloadString(firstUrl).Result.Replace("\r", "").Replace("\n", ""); // Scrape it var label = string.Empty; var protein = 0.0; var carbs = 0.0; var fat = 0.0; var fiber = 0.0; stringBuilder.Append(Regex.Match(food, @"<title>(.*)\ \|.*<\/title>").Groups[1].Value.Replace("Calories in ", "").Trim() + " per "); // Name of item stringBuilder.Append(Regex.Match(food, @"<select name=""units"".*?<option.*?>(.*?)<\/option>", RegexOptions.IgnoreCase).Groups[1].Value.Trim() + "\r\n"); // Unit foreach (Match fact in Regex.Matches(food, @"<td class=""(calories|label|amount)"">([a-zA-Z0-9\ &;<>=\/\""\.]*)<\/td>")) { switch (fact.Groups[1].Value.Trim().ToLowerInvariant()) { case "calories": stringBuilder.Append("Calories: " + fact.Groups[2].Value.Replace("Calories <span class=\"amount\">", "").Replace("</span>", "") + ", "); break; case "label": label = fact.Groups[2].Value.Trim(); break; case "amount": stringBuilder.Append(label + ": " + fact.Groups[2].Value + ", "); switch (label.ToLowerInvariant()) { case "protein": protein = Convert.ToDouble(fact.Groups[2].Value.Replace("mg", "").Replace("g", "").Replace("<", "").Replace(">", "")); break; case "total carbs.": carbs = Convert.ToDouble(fact.Groups[2].Value.Replace("mg", "").Replace("g", "").Replace("<", "").Replace(">", "")); break; case "total fat": fat = Convert.ToDouble(fact.Groups[2].Value.Replace("mg", "").Replace("g", "").Replace("<", "").Replace(">", "")); break; case "dietary fiber": fiber = Convert.ToDouble(fact.Groups[2].Value.Replace("mg", "").Replace("g", "").Replace("<", "").Replace(">", "")); break; } break; } } // WW Points = (Protein/10.9375) + (Carbs/9.2105) + (Fat/3.8889) - (Fiber/12.5) stringBuilder.Append("WW PointsPlus: " + Math.Round((protein / 10.9375) + (carbs / 9.2105) + (fat / 3.8889) - (fiber / 12.5), 1)); break; case "/forecast": if (body.Length < 2) { body = "Cincinnati, OH"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic dfor = JObject.Parse(httpClient.DownloadString("http://api.wunderground.com/api/" + wundergroundKey + "/forecast/q/" + body + ".json").Result); if (dfor.forecast == null || dfor.forecast.txt_forecast == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try \"City, ST\" or \"City, Country\" next time."; break; } for (var ifor = 0; ifor < Enumerable.Count(dfor.forecast.txt_forecast.forecastday) - 1; ifor++) { stringBuilder.AppendLine(dfor.forecast.txt_forecast.forecastday[ifor].title.ToString() + ": " + dfor.forecast.txt_forecast.forecastday[ifor].fcttext.ToString()); } break; case "/help": replyText = "The Great & powerful Trixie understands the following commands:\r\n" + "/cat /doge /fat /forecast /help /image /imdb /google /joke /map /outside /overwatch /pony /radar /satellite /stock /stock7 /stockyear /translate /translateto /trixie /version /weather /wiki /ww"; /* Send this string of text to BotFather to register the bot's commands: cat - Get a picture of a cat doge - Dogeify a comma sep list of terms fat - Nutrition information forecast - Weather forecast help - Displays help text image - Search for an image imdb - Search IMDB for a movie name google - Search Google map - Returns a location for the given search joke - Returns a random joke from /r/jokes on Reddit outside - Webcam image overwatch - Overwatch Stats pony - Ponies matching comma separated tags radar - Weather radar remind - Sets a reminder message after X minutes satellite - Weather Satellite stock - US Stock Chart (1 day) stock7 - US Stock Chart (7 day) stockyear - US Stock Chart (12 month) translate - Translate to english translateto - Translate to a given language trixie - Wolfram Alpha logic search version - Display version info weather - Current weather conditions wiki - Search Wikipedia ww - WeightWatcher PointsPlus calc */ break; case "/image": case "/img": if (body == string.Empty) { replyText = "Usage: /image <Description of image to find>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); httpClient.AuthorizationHeader = "Basic " + bingKey; dynamic dimg = JObject.Parse(httpClient.DownloadString("https://api.datamarket.azure.com/Data.ashx/Bing/Search/Image?Market=%27en-US%27&Adult=%27Moderate%27&Query=%27" + HttpUtility.UrlEncode(body) + "%27&$format=json&$top=3").Result); httpClient.AuthorizationHeader = string.Empty; if (dimg.d == null || dimg.d.results == null || Enumerable.Count(dimg.d.results) < 1) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try harder next time."; break; } var rimg = new Random(); var iimgmax = Enumerable.Count(dimg.d.results); if (iimgmax > 3) { iimgmax = 3; } var iimg = rimg.Next(0, iimgmax); string imageUrl = dimg.d.results[iimg].MediaUrl.ToString(); if (imageUrl.Trim().EndsWith(".gif", StringComparison.Ordinal)) { replyDocument = dimg.d.results[iimg].MediaUrl; } else { replyImage = dimg.d.results[iimg].MediaUrl; } break; case "/imdb": case "/rt": case "/movie": if (body == string.Empty) { replyText = "Usage: /imdb <Movie Title>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); // Search Bing httpClient.AuthorizationHeader = "Basic " + bingKey; dynamic dimdb = JObject.Parse(httpClient.DownloadString("https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Market=%27en-US%27&Adult=%27Moderate%27&Query=%27site%3Aimdb.com%20" + HttpUtility.UrlEncode(body) + "%27&$format=json&$top=1").Result); httpClient.AuthorizationHeader = string.Empty; if (dimdb.d == null || dimdb.d.results == null || Enumerable.Count(dimdb.d.results) < 1) { replyText = "Trixie was unable to find a movie name matching:" + body; break; } // Find correct /combined URL string imdbUrl = dimdb.d.results[0].Url; imdbUrl = (imdbUrl.Replace("/business", "").Replace("/combined", "").Replace("/faq", "").Replace("/goofs", "").Replace("/news", "").Replace("/parentalguide", "").Replace("/quotes", "").Replace("/ratings", "").Replace("/synopsis", "").Replace("/trivia", "") + "/combined").Replace("//combined","/combined"); // Scrape it var imdb = httpClient.DownloadString(imdbUrl).Result.Replace("\r", "").Replace("\n", ""); var title = Regex.Match(imdb, @"<title>(IMDb \- )*(.*?) \(.*?</title>", RegexOptions.IgnoreCase).Groups[2].Value.Trim(); var year = Regex.Match(imdb, @"<title>.*?\(.*?(\d{4}).*?\).*?</title>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var rating = Regex.Match(imdb, @"<b>(\d.\d)/10</b>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var votes = Regex.Match(imdb, @">(\d+,?\d*) votes<", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var plot = Regex.Match(imdb, @"Plot:</h5>.*?<div class=""info-content"">(.*?)(<a|</div)", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var tagline = Regex.Match(imdb, @"Tagline:</h5>.*?<div class=""info-content"">(.*?)(<a|</div)", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var poster = Regex.Match(imdb, @"<div class=""photo"">.*?<a name=""poster"".*?><img.*?src=""(.*?)"".*?</div>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var posterFull = string.Empty; if (!string.IsNullOrEmpty(poster) && poster.IndexOf("media-imdb.com", StringComparison.Ordinal) > 0) { poster = Regex.Replace(poster, @"_V1.*?.jpg", "_V1._SY200.jpg"); posterFull = Regex.Replace(poster, @"_V1.*?.jpg", "_V1._SX1280_SY1280.jpg"); } if (title.Length < 2) { replyText = "Trixie was unable to find a movie name matching: " + body; } else { // Try for RT score scrape httpClient.AuthorizationHeader = "Basic " + bingKey; dynamic drt = JObject.Parse(httpClient.DownloadString("https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Market=%27en-US%27&Adult=%27Moderate%27&Query=%27site%3Arottentomatoes.com%20" + HttpUtility.UrlEncode(body) + "%27&$format=json&$top=1").Result); httpClient.AuthorizationHeader = string.Empty; if (drt.d != null && drt.d.results != null && Enumerable.Count(drt.d.results) > 0) { string rtUrl = drt.d.results[0].Url; var rt = httpClient.DownloadString(rtUrl).Result; //var rtCritic = Regex.Match(rt, @"<span class=""meter-value .*?<span>(.*?)</span>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var rtCritic = Regex.Match(rt, @"<span class=""meter-value superPageFontColor""><span>(.*?)</span>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var rtAudience = Regex.Match(rt, @"<span class=""superPageFontColor"" style=""vertical-align:top"">(.*?)</span>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); replyText = HttpUtility.HtmlDecode(title) + " (" + year + ") - " + HttpUtility.HtmlDecode(tagline) + "\r\nIMDb: " + rating + " (" + votes + " votes) | RT critic: " + rtCritic + "% | RT audience: " + rtAudience + "\r\n" + HttpUtility.HtmlDecode(plot); } else { var rt = httpClient.DownloadString("http://www.rottentomatoes.com/search/?search=" + HttpUtility.UrlEncode(body)).Result; //var rtCritic = Regex.Match(rt, @"<span class=""meter-value .*?<span>(.*?)</span>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var rtCritic = Regex.Match(rt, @"<span class=""meter-value superPageFontColor""><span>(.*?)</span>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); var rtAudience = Regex.Match(rt, @"<span class=""superPageFontColor"" style=""vertical-align:top"">(.*?)</span>", RegexOptions.IgnoreCase).Groups[1].Value.Trim(); replyText = HttpUtility.HtmlDecode(title) + " (" + year + ") - " + HttpUtility.HtmlDecode(tagline) + "\r\nIMDb: " + rating + " (" + votes + " votes) | RT critic: " + rtCritic + "% | RT audience: " + rtAudience + "\r\n" + HttpUtility.HtmlDecode(plot); } // Remove trailing pipe that sometimes occurs if (replyText.EndsWith("|")) { replyText = replyText.Substring(0, replyText.Length - 2).Trim(); } // Set referrer URI to grab IMDB poster httpClient.ReferrerUri = imdbUrl; replyImage = posterFull; replyImageCaption = imdbUrl; } break; case "/joke": await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic djoke = JObject.Parse(httpClient.DownloadString("https://api.reddit.com/r/jokes/top?t=day&limit=5").Result); var rjoke = new Random(); var ijokemax = Enumerable.Count(djoke.data.children); if (ijokemax > 4) { ijokemax = 4; } var ijoke = rjoke.Next(0, ijokemax); replyText = djoke.data.children[ijoke].data.title.ToString() + " " + djoke.data.children[ijoke].data.selftext.ToString(); break; case "/map": case "/location": if (body == string.Empty) { replyText = "Usage: /map <Search Text>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic dmap = JObject.Parse(httpClient.DownloadString("http://maps.googleapis.com/maps/api/geocode/json?address=" + HttpUtility.UrlEncode(body)).Result); if (dmap == null || dmap.results == null || Enumerable.Count(dmap.results) < 1) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try harder next time."; } else { await bot.SendLocationAsync(update.Message.Chat.Id, (float)dmap.results[0].geometry.location.lat, (float)dmap.results[0].geometry.location.lng); } break; case "/google": case "/bing": if (body == string.Empty) { replyText = "Usage: /google <Search Text>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); httpClient.AuthorizationHeader = "Basic " + bingKey; dynamic dgoog = JObject.Parse(httpClient.DownloadString("https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Market=%27en-US%27&Adult=%27Moderate%27&Query=%27" + HttpUtility.UrlEncode(body) + "%27&$format=json&$top=1").Result); httpClient.AuthorizationHeader = string.Empty; if (dgoog.d == null || dgoog.d.results == null || Enumerable.Count(dgoog.d.results) < 1) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try harder next time."; } else { var rgoog = new Random(); var igoog = rgoog.Next(0, Enumerable.Count(dgoog.d.results)); replyText = HttpUtility.HtmlDecode(dgoog.d.results[igoog].Title.ToString()) + " | " + HttpUtility.HtmlDecode(dgoog.d.results[igoog].Description.ToString()) + "\r\n" + dgoog.d.results[igoog].Url; } break; case "/outside": if (body.Length < 2) { body = "Cincinnati, OH"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic dout = JObject.Parse(httpClient.DownloadString("http://api.wunderground.com/api/" + wundergroundKey + "/webcams/q/" + body + ".json").Result); if (dout.webcams == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try \"City, ST\" or \"City, Country\" next time."; break; } var rout = new Random(); var iout = rout.Next(0, Enumerable.Count(dout.webcams)); replyImage = dout.webcams[iout].CURRENTIMAGEURL; replyImageCaption = dout.webcams[iout].organization + " " + dout.webcams[iout].neighborhood + " " + dout.webcams[iout].city + ", " + dout.webcams[iout].state + "\r\n" + dout.webcams[iout].CAMURL; break; case "/overwatch": if (body.Length < 2) { replyText = "Usage: /overwatch <Battletag with no spaces> eg: /overwatch SniperFox#1513"; break; } var ow = new OverwatchPlayer(body, Platform.pc, Region.us); await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); ow.UpdateStats().GetAwaiter().GetResult(); if (ow.CompetitiveStats.AllHeroes != null) { replyTextMarkdown = "*Competitive Play - Rank " + ow.CompetitiveRank + "*\r\n" + ow.CompetitiveStats.AllHeroes.Game.GamesWon + " wins, " + (ow.CompetitiveStats.AllHeroes.Game.GamesPlayed - ow.CompetitiveStats.AllHeroes.Game.GamesWon) + " losses " + "(" + Math.Round((ow.CompetitiveStats.AllHeroes.Game.GamesWon / ow.CompetitiveStats.AllHeroes.Game.GamesPlayed) * 100, 2) + "%) " + "over " + Math.Round(ow.CompetitiveStats.AllHeroes.Game.TimePlayed.TotalHours / 24, 2) + " days played.\r\n" + ow.CompetitiveStats.AllHeroes.Combat.Eliminations + " eliminations, " + ow.CompetitiveStats.AllHeroes.Deaths.Deaths + " deaths, " + Math.Round(ow.CompetitiveStats.AllHeroes.Combat.Eliminations / ow.CompetitiveStats.AllHeroes.Deaths.Deaths, 2) + " eliminations per death.\r\n" + ow.CompetitiveStats.AllHeroes.MatchAwards.Cards + " cards, " + ow.CompetitiveStats.AllHeroes.MatchAwards.MedalsGold + " gold, " + ow.CompetitiveStats.AllHeroes.MatchAwards.MedalsSilver + " silver, and " + ow.CompetitiveStats.AllHeroes.MatchAwards.MedalsGold + " bronze medals.\r\n"; } replyTextMarkdown += "*Quick Filthy Casual Play - Level " + ow.PlayerLevel + "*\r\n" + ow.CasualStats.AllHeroes.Game.GamesWon + " wins, " + (ow.CasualStats.AllHeroes.Game.GamesPlayed - ow.CasualStats.AllHeroes.Game.GamesWon) + " losses " + "(" + Math.Round((ow.CasualStats.AllHeroes.Game.GamesWon / ow.CasualStats.AllHeroes.Game.GamesPlayed) * 100, 2) + "%) " + "over " + Math.Round(ow.CasualStats.AllHeroes.Game.TimePlayed.TotalHours / 24, 2) + " days played.\r\n" + ow.CasualStats.AllHeroes.Combat.Eliminations + " eliminations, " + ow.CasualStats.AllHeroes.Deaths.Deaths + " deaths, " + Math.Round(ow.CasualStats.AllHeroes.Combat.Eliminations / ow.CasualStats.AllHeroes.Deaths.Deaths, 2) + " eliminations per death.\r\n" + ow.CasualStats.AllHeroes.MatchAwards.Cards + " cards, " + ow.CasualStats.AllHeroes.MatchAwards.MedalsGold + " gold, " + ow.CasualStats.AllHeroes.MatchAwards.MedalsSilver + " silver, and " + ow.CasualStats.AllHeroes.MatchAwards.MedalsGold + " bronze medals.\r\n" + ow.ProfileURL.Replace("/en-gb/", "/en-us/"); break; case "/pony": case "/pone": if (body.Length < 2) { replyText = "I like ponies too. What kind of pony would you like me to search for?"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic dpony = JObject.Parse(httpClient.DownloadString("https://derpibooru.org/search.json?q=safe," + HttpUtility.UrlEncode(body)).Result); if (dpony.search == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it."; break; } var rpony = new Random(); var iponymax = Enumerable.Count(dpony.search); if (iponymax < 1) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it."; break; } if (iponymax > 5) { iponymax = 5; } var ipony = rpony.Next(0, iponymax); replyImage = "https:" + dpony.search[ipony].representations.large; replyImageCaption = "https:" + dpony.search[ipony].image; break; case "/radar": if (body.Length < 2) { body = "Cincinnati, OH"; } replyDocument = "http://api.wunderground.com/api/" + wundergroundKey + "/animatedradar/q/" + body + ".gif?newmaps=1&num=15&width=1024&height=1024"; break; case "/remind": case "/remindme": case "/reminder": if (body.Length < 2 || !body.Contains(" ")) { replyText = "Usage: /remind <minutes> <Reminder Text>"; } else { var delayMinutesString = body.Substring(0, body.IndexOf(" ", StringComparison.Ordinal)); int delayMinutes; if (int.TryParse(delayMinutesString, out delayMinutes)) { if (delayMinutes > 1440 || delayMinutes < 1) { replyText = "Reminders can not be set for longer than 1440 minutes (24 hours)."; } else { DelayedMessage(bot, update.Message.Chat.Id, "@" + update.Message.From.Username + " Reminder: " + body.Substring(delayMinutesString.Length).Trim(), delayMinutes); replyText = "OK, I'll remind you at " + DateTime.Now.AddMinutes(delayMinutes).ToString("MM/dd/yyyy HH:mm") + " (US Eastern)"; } } else { replyText = "Usage: /remind <minutes as positive integer> <Reminder Text>"; } } break; case "/s": if (body.Length < 2 || update.Message.ReplyToMessage == null) { replyText = "This must be done as a reply in the format /s/replace this/replace with/"; } else { var sed = body.Split('/'); if (sed.Length != 4) replyText = "The only sed command parsed is /s/replace this/replace with/"; else { replyTextMarkdown = "*" + update.Message.ReplyToMessage.From.FirstName + " " + update.Message.ReplyToMessage.From.LastName + "* \r\n" + update.Message.ReplyToMessage.Text.Replace(sed[1], sed[2]); } } break; case "/satellite": if (body.Length < 2) { body = "Cincinnati, OH"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic rsat = JObject.Parse(httpClient.DownloadString("http://api.wunderground.com/api/" + wundergroundKey + "/satellite/q/" + body + ".json").Result); if (rsat.satellite == null || rsat.satellite.image_url == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try \"City, ST\" or \"City, Country\" next time."; } else { string saturl = rsat.satellite.image_url; replyImage = saturl.Replace("height=300", "height=1280").Replace("width=300", "width=1280").Replace("radius=75", "radius=250"); replyImageCaption = body + " as of " + DateTime.Now.ToString("MM/dd/yyy HH:mm:ss"); } break; case "/stock": if (body.Length < 1 || body.Length > 5) { body = "^DJI"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); replyImage = "https://chart.yahoo.com/t?s=" + body + "&lang=en-US®ion=US&width=1200&height=765"; replyImageCaption = "Chart for " + body + " as of " + DateTime.Now.ToString("MM/dd/yyy HH:mm:ss"); break; case "/stock5": if (body.Length < 1 || body.Length > 5) { body = "^DJI"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); replyImage = "https://chart.yahoo.com/w?s=" + body + "&lang=en-US®ion=US&width=1200&height=765"; replyImageCaption = "5 day chart for " + body + " as of " + DateTime.Now.ToString("MM/dd/yyy HH:mm:ss"); break; case "/stockyear": if (body.Length < 1 || body.Length > 5) { body = "^DJI"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); replyImage = "https://chart.yahoo.com/c/1y/" + body; replyImageCaption = "Year chart for " + body + " as of " + DateTime.Now.ToString("MM/dd/yyy HH:mm:ss"); break; case "/translateto": if (body == string.Empty) { replyText = "Usage: /translateto <Language Code> <English Text>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); var lang = body.Substring(0, body.IndexOf(" ", StringComparison.Ordinal)); var query = body.Substring(body.IndexOf(" ", StringComparison.Ordinal) + 1); httpClient.AuthorizationHeader = "Basic " + bingKey; dynamic dtto = JObject.Parse(httpClient.DownloadString("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text=%27" + HttpUtility.UrlEncode(query) + "%27&To=%27" + lang + "%27&$format=json").Result); httpClient.AuthorizationHeader = string.Empty; if (dtto.d == null || dtto.d.results == null || Enumerable.Count(dtto.d.results) < 1 || dtto.d.results[0].Text == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try harder next time."; } else { replyText = dtto.d.results[0].Text; } break; case "/translate": if (body == string.Empty) { replyText = "Usage: /translate <Foreign Text>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); httpClient.AuthorizationHeader = "Basic " + bingKey; dynamic dtrans = JObject.Parse(httpClient.DownloadString("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text=%27" + HttpUtility.UrlEncode(body) + "%27&To=%27en%27&$format=json").Result); httpClient.AuthorizationHeader = string.Empty; if (dtrans.d == null || dtrans.d.results == null || Enumerable.Count(dtrans.d.results) < 1 || dtrans.d.results[0].Text == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try harder next time."; } else { replyText = dtrans.d.results[0].Text; } break; case "/trixie": if (body == string.Empty) { replyText = "Usage: /trixie <Query>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(httpClient.DownloadString("http://api.wolframalpha.com/v2/query?input=" + HttpUtility.UrlEncode(body) + "&appid=" + wolframAppId).Result); var queryResult = xmlDoc.SelectSingleNode("/queryresult"); if (queryResult == null || queryResult?.Attributes == null || queryResult.Attributes?["success"] == null || queryResult.Attributes?["success"].Value != "true") { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try harder next time."; break; } var pods = queryResult.SelectNodes("pod"); foreach (var pod in pods.Cast<XmlNode>().Where(pod => pod.Attributes != null && pod.Attributes["title"].Value != "Input interpretation")) { // Parse Image if (replyImage == string.Empty) { try { var subPodImage = pod.SelectSingleNode("subpod/img"); if (subPodImage.Attributes != null) { replyImage = subPodImage.Attributes?["src"].Value.Trim(); } } catch { // Don't care } } // Parse plain text try { var subPodPlainText = pod.SelectSingleNode("subpod/plaintext"); if (subPodPlainText == null || subPodPlainText.InnerText.Trim().Length <= 0) continue; var podName = pod.Attributes?["title"].Value.Trim(); if (podName == "Response" || podName == "Result") { stringBuilder.AppendLine(subPodPlainText.InnerText); } else { stringBuilder.AppendLine(podName + ": " + subPodPlainText.InnerText); } } catch { // Don't care } } break; case "/version": case "/about": replyText = "Trixie Is Best Pony Bot\r\nRelease fourty-two\r\nBy http://scottrfrost.github.io"; break; case "/weather": if (body.Length < 2) { body = "Cincinnati, OH"; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); dynamic dwthr = JObject.Parse(httpClient.DownloadString("http://api.wunderground.com/api/" + wundergroundKey + "/conditions/q/" + body + ".json").Result); if (dwthr.current_observation == null) { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it. Try \"City, ST\" or \"City, Country\" next time."; } else { replyText = dwthr.current_observation.display_location.full + " Conditions: " + dwthr.current_observation.weather + " Wind: " + dwthr.current_observation.wind_string + " Temp: " + dwthr.current_observation.temperature_string + " Feels Like: " + dwthr.current_observation.feelslike_string; } break; case "/wiki": if (body == string.Empty) { replyText = "Usage: /wiki <Query>"; break; } await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); var dwiki = JObject.Parse(httpClient.DownloadString("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&redirects=true&titles=" + HttpUtility.UrlEncode(body)).Result); if (dwiki["query"].HasValues && dwiki["query"]["pages"].HasValues) { var page = dwiki["query"]["pages"].First().First(); if (Convert.ToString(page["pageid"]).Length > 0) replyTextMarkdown = "*" + page["title"] + "*\r\n" + page["extract"] + "\r\n" + "https://en.wikipedia.org/?curid=" + page["pageid"]; else { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it."; } } else { replyText = "You have disappointed Trixie. \"" + body + "\" is bullshit and you know it."; } break; case "/ww": var split = body.Split(' '); if (split.Length != 4) { replyText = "Usage: /ww <carbs> <fat> <fiber> <protein>"; break; } try { var wwcarbs = Convert.ToDouble(split[0]); var wwfat = Convert.ToDouble(split[1]); var wwfiber = Convert.ToDouble(split[2]); var wwprotein = Convert.ToDouble(split[3]); replyText = "WW PointsPlus value for " + wwcarbs + "g carbs, " + wwfat + "g fat, " + wwfiber + "g fiber, " + wwprotein + "g protein is: " + Math.Round((wwprotein / 10.9375) + (wwcarbs / 9.2105) + (wwfat / 3.8889) - (wwfiber / 12.5), 1); } catch { replyText = "Trixie is disappointed that you used /ww incorrectly. The correct usage is: /ww <carbs> <fat> <fiber> <protein>"; } break; } // Output replyText += stringBuilder.ToString(); if (!string.IsNullOrEmpty(replyText)) { Console.WriteLine(update.Message.Chat.Id + " > " + replyText); await bot.SendTextMessageAsync(update.Message.Chat.Id, replyText); } if (!string.IsNullOrEmpty(replyTextMarkdown)) { Console.WriteLine(update.Message.Chat.Id + " > " + replyTextMarkdown); await bot.SendTextMessageAsync(update.Message.Chat.Id, replyTextMarkdown, false, false, 0, null, ParseMode.Markdown); } if (!string.IsNullOrEmpty(replyImage) && replyImage.Length > 5) { Console.WriteLine(update.Message.Chat.Id + " > " + replyImage); await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.Typing); try { var stream = httpClient.DownloadData(replyImage).Result; var extension = ".jpg"; if (replyImage.Contains(".gif") || replyImage.Contains("image/gif")) { extension = ".gif"; } else if (replyImage.Contains(".png") || replyImage.Contains("image/png")) { extension = ".png"; } else if (replyImage.Contains(".tif")) { extension = ".tif"; } else if (replyImage.Contains(".bmp")) { extension = ".bmp"; } var photo = new FileToSend("Photo" + extension, stream); await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.UploadPhoto); if (extension == ".gif") { await bot.SendDocumentAsync(update.Message.Chat.Id, photo); } else { await bot.SendPhotoAsync(update.Message.Chat.Id, photo, replyImageCaption == string.Empty ? replyImage : replyImageCaption); } } catch (System.Net.Http.HttpRequestException ex) { Console.WriteLine("Unable to download " + ex.HResult + " " + ex.Message); await bot.SendTextMessageAsync(update.Message.Chat.Id, replyImage); } catch (System.Net.WebException ex) { Console.WriteLine("Unable to download " + ex.HResult + " " + ex.Message); await bot.SendTextMessageAsync(update.Message.Chat.Id, replyImage); } catch (Exception ex) { Console.WriteLine(replyImage + " Threw: " + ex.Message); await bot.SendTextMessageAsync(update.Message.Chat.Id, replyImage); } } if (!string.IsNullOrEmpty(replyDocument) && replyDocument.Length > 5) { Console.WriteLine(update.Message.Chat.Id + " > " + replyDocument); await bot.SendChatActionAsync(update.Message.Chat.Id, ChatAction.UploadDocument); var stream = httpClient.DownloadData(replyDocument).Result; var filename = replyDocument.Substring(replyDocument.LastIndexOf("/", StringComparison.Ordinal)); var document = new FileToSend(filename, stream); await bot.SendDocumentAsync(update.Message.Chat.Id, document); } } } catch (System.Net.WebException ex) { Console.WriteLine("Unable to download " + ex.HResult + " " + ex.Message); await bot.SendTextMessageAsync(update.Message.Chat.Id, "The Great & Powerful Trixie got bored while waiting for that to download. Try later."); } catch (Exception ex) { Console.WriteLine("ERROR - " + ex); } }
public async Task SendPhotoMessageAsync(BotChat chat, string fileName, string caption = null) { if (!_active) { return; } if (!File.Exists(fileName)) { throw new FileNotFoundException("The filename doesn't exist", fileName); } using (var ms = new MemoryStream()) { using (var fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) await fs.CopyToAsync(ms).ConfigureAwait(false); ms.Position = 0; await _bot.SendPhotoAsync(chat.Id.ParseTo <long>(-1), ms, caption).ConfigureAwait(false); } }
public async void BotSendMessage(string msg) { string path = @"img\fullscreen.bmp"; try { imgMacro.GetFullScreen().Save(path, System.Drawing.Imaging.ImageFormat.Bmp); } catch { } if (bot != null) { FileStream stream = System.IO.File.OpenRead(path); await bot.SendPhotoAsync(botID, stream, msg); } }
private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs) { String Answer = ""; string[] arrayChar = { "https://www.meme-arsenal.com/memes/382906c071b1656c03104e98775b99b7.jpg", "https://www.meme-arsenal.com/memes/c27ee50cd596b0bd73ce01b543246de6.jpg", "https://pbs.twimg.com/media/EVqEsClXsAQ7Mio.jpg", "https://cs.pikabu.ru/post_img/2013/09/01/8/1378039082_293717672.jpg", "https://i.pinimg.com/originals/5f/67/a6/5f67a64f65f27821a81a9193c97f9573.jpg" }; Telegram.Bot.Types.Message msg = messageEventArgs.Message; //if (msg == null || msg.Type != MessageType.Document) return; //{ // Console.WriteLine(msg.Document.FileId); // var file = await BOT.GetFileAsync(msg.Document.FileId); // FileStream fs = new FileStream("C:\\Users\\anton\\OneDrive\\Рабочий стол\\DangerousSausages\\file.pdf", FileMode.Create); // await BOT.DownloadFileAsync(file.FilePath, fs); // fs.Close(); // fs.Dispose(); //} if (msg == null || msg.Type != MessageType.Text) { return; } switch (msg.Text) { case "/start": Answer = "Чтобы узнать, что я умею напишите /help\n"; break; case "/help": Answer = "Бот не может работать по следующему сценарию:\n\n" + "1.отправляется файл frx на экспорт\n" + "2.экспортируется в некий формат, например pdf\n" + "3.возвращается\n\n" + "Но зато, есть секретик на команду /memes\n"; break; case "/status": Answer = "Пока не работает остальное, мы не можем добавить данную функцию\n"; break; case "/memes": Answer = "Поздравляю, вы нашли ржумбу и открыли панель с клавишей)\n"; break; case "Скрыть панель": Answer = "напишите команду заново"; await BOT.SendTextMessageAsync(msg.Chat.Id, "Для повторного вызова панели", replyMarkup : new ReplyKeyboardRemove()); break; case "Мемесы:)": Answer = "Ржумба"; await BOT.SendPhotoAsync(msg.Chat.Id, arrayChar[new Random().Next(0, arrayChar.Length)], " "); break; default: Answer = "В разработке"; break; } await BOT.SendTextMessageAsync(msg.Chat.Id, Answer); if (msg.Text == "/memes") { var keyboard = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 5 { new KeyboardButton("Мемесы:)"), }, new[] // row 6 { new KeyboardButton("Скрыть панель"), }, }, ResizeKeyboard = true }; await BOT.SendTextMessageAsync(msg.Chat.Id, "Нажмите на клавишу, чтобы получить мемчик", replyMarkup : keyboard); } }
private async void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; var key = e.Argument as String; try { var Bot = new Telegram.Bot.TelegramBotClient(key); Bot.SetWebhookAsync("").Wait(); int offset = 0; int stageM = 0; while (true) { var updates = await Bot.GetUpdatesAsync(offset); foreach (var update in updates) { var message = update.Message; stageM = 0; int index = -1; for (int i = 0; i < persons.Count; i++) { if (persons[i].userid == message.From.Id) { index = i; break; } } if (message.Type == Telegram.Bot.Types.Enums.MessageType.TextMessage) { if (message.Text == "/reset" && index >= 0) { persons.RemoveAt(index); await Bot.SendTextMessageAsync(message.Chat.Id, "Ваш профиль очищен."); } else if (message.Text == "/reset") { await Bot.SendTextMessageAsync(message.Chat.Id, "Профиль чист."); } else { if (index >= 0) { stageM = persons[index].stage; } else { persons.Add(new Person { FirstName = message.From.FirstName, SecondName = message.From.LastName, gender = 0, temperament = "", bd = 0, bm = 0, by = 0, userid = message.From.Id, stage = 0 }); index = persons.Count - 1; stageM = 0; } switch (stageM) { case 0: Telegram.Bot.Types.FileToSend file = new Telegram.Bot.Types.FileToSend(); file.Content = File.Open("hello.jpg", FileMode.Open); file.Filename = "hello.jpg"; await Bot.SendPhotoAsync(message.Chat.Id, file); await Bot.SendTextMessageAsync(message.Chat.Id, "Привет, " + message.From.FirstName + "!\nЯ Миша.\nЯ постараюсь быть тебе другом.\nРасскажи немного о себе😊"); var keyboard = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 1 { new Telegram.Bot.Types.KeyboardButton("👨Мужской"), new Telegram.Bot.Types.KeyboardButton("👱♀Женский") }, }, ResizeKeyboard = true, OneTimeKeyboard = true }; await Bot.SendTextMessageAsync(message.Chat.Id, "Укажи свой пол", ParseMode.Default, false, false, 0, keyboard); stageM++; break; case 1: if (message.Text == "👨Мужской") { persons[index].gender = 1; } else if (message.Text == "👱♀Женский") { persons[index].gender = 2; } else { stageM--; break; } var keyboard1 = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 1 { new Telegram.Bot.Types.KeyboardButton("👍Хорошо"), new Telegram.Bot.Types.KeyboardButton("😞Плохо"), new Telegram.Bot.Types.KeyboardButton("😐Не очень") }, }, ResizeKeyboard = true, OneTimeKeyboard = true }; await Bot.SendTextMessageAsync(message.Chat.Id, "Как прошел твой день?", ParseMode.Default, false, false, 0, keyboard1); stageM++; break; case 2: bool inGame = false; int indexgame = -1; int indexGamer = 0; string pathGamePhoto = ""; for (int i = 0; i < gamesphoto.Count; i++) { if (gamesphoto[i].user1 == message.From.Id || gamesphoto[i].user2 == message.From.Id || gamesphoto[i].user3 == message.From.Id || gamesphoto[i].user4 == message.From.Id) { inGame = true; indexgame = i; } } if (!inGame) { await Bot.SendTextMessageAsync(message.Chat.Id, "Я понял. Давай сыграем в игру, где надо будет собрать части картинки в одну. Я отправлю картинки всем в твоей команде и ты должен найти недостающие части."); } else if (gamesphoto[indexgame].count == 4) { if (message.Text.ToLower() == "кот" || message.Text.ToLower() == "котик" || message.Text.ToLower() == "кошка") { await Bot.SendTextMessageAsync(message.Chat.Id, "Правильно!"); var keyboard6 = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 1 { new Telegram.Bot.Types.KeyboardButton("Учился в школе"), new Telegram.Bot.Types.KeyboardButton("Гуляли с друзьями"), new Telegram.Bot.Types.KeyboardButton("Справляли день рождения"), new Telegram.Bot.Types.KeyboardButton("Ничего") }, }, ResizeKeyboard = true, OneTimeKeyboard = true }; await Bot.SendTextMessageAsync(message.Chat.Id, "Что запомнилось тебе за этот день?", ParseMode.Default, false, false, 0, keyboard6); stageM++; break; } else { await Bot.SendTextMessageAsync(message.Chat.Id, "Подумай еще!😊"); break; } } if (!inGame) { for (int i = 0; i < gamesphoto.Count; i++) { if (gamesphoto[i].count != 4) { if (gamesphoto[i].user1 == -1) { gamesphoto[i].chatID1 = message.Chat.Id; gamesphoto[i].user1 = message.From.Id; pathGamePhoto = gamesphoto[i].firstPath; } else if (gamesphoto[i].user2 == -1) { indexGamer = 1; gamesphoto[i].chatID2 = message.Chat.Id; gamesphoto[i].user2 = message.From.Id; pathGamePhoto = gamesphoto[i].secondPath; } else if (gamesphoto[i].user3 == -1) { indexGamer = 2; gamesphoto[i].chatID3 = message.Chat.Id; gamesphoto[i].user3 = message.From.Id; pathGamePhoto = gamesphoto[i].thirdPath; } else if (gamesphoto[i].user4 == -1) { indexGamer = 3; gamesphoto[i].chatID4 = message.Chat.Id; gamesphoto[i].user4 = message.From.Id; pathGamePhoto = gamesphoto[i].fourPath; } inGame = true; indexgame = i; gamesphoto[indexgame].count++; if (gamesphoto[indexgame].count == 4) { Telegram.Bot.Types.FileToSend file1 = new Telegram.Bot.Types.FileToSend(); file1.Content = File.Open(gamesphoto[indexgame].firstPath, FileMode.Open); file1.Filename = gamesphoto[indexgame].firstPath; await Bot.SendPhotoAsync(gamesphoto[indexgame].chatID1, file1); await Bot.SendTextMessageAsync(gamesphoto[indexgame].chatID1, "Найди другие части картинки и скажи что на картинке. Удачи!😊"); file1.Content = File.Open(gamesphoto[indexgame].secondPath, FileMode.Open); file1.Filename = gamesphoto[indexgame].secondPath; await Bot.SendPhotoAsync(gamesphoto[indexgame].chatID2, file1); await Bot.SendTextMessageAsync(gamesphoto[indexgame].chatID2, "Найди другие части картинки и скажи что на картинке. Удачи!😊"); file1.Content = File.Open(gamesphoto[indexgame].thirdPath, FileMode.Open); file1.Filename = gamesphoto[indexgame].thirdPath; await Bot.SendPhotoAsync(gamesphoto[indexgame].chatID3, file1); await Bot.SendTextMessageAsync(gamesphoto[indexgame].chatID3, "Найди другие части картинки и скажи что на картинке. Удачи!😊"); file1.Content = File.Open(gamesphoto[indexgame].fourPath, FileMode.Open); file1.Filename = gamesphoto[indexgame].fourPath; await Bot.SendPhotoAsync(gamesphoto[indexgame].chatID4, file1); await Bot.SendTextMessageAsync(gamesphoto[indexgame].chatID4, "Найди другие части картинки и скажи что на картинке. Удачи!😊"); break; } } } } if (!inGame) { await Bot.SendTextMessageAsync(message.Chat.Id, "Игр пока нет😊"); } else { if (gamesphoto[indexgame].count != 4) { await Bot.SendTextMessageAsync(message.Chat.Id, "Подожди немного, я поищу тебе команду😊"); } } break; case 3: persons[index].answer2 = message.Text; var keyboard3 = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 1 { new Telegram.Bot.Types.KeyboardButton("Да"), new Telegram.Bot.Types.KeyboardButton("Нет"), }, }, ResizeKeyboard = true, OneTimeKeyboard = true }; await Bot.SendTextMessageAsync(message.Chat.Id, "Понравилось ли тебе сегодняшнее задание?", ParseMode.Default, false, false, 0, keyboard3); stageM++; break; case 4: persons[index].answer3 = message.Text; await Bot.SendTextMessageAsync(message.Chat.Id, "Какое задание ты сегодня выполнял?"); stageM++; break; case 5: persons[index].answer4 = message.Text; var keyboard5 = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup { Keyboard = new[] { new[] // row 1 { new Telegram.Bot.Types.KeyboardButton("Да"), new Telegram.Bot.Types.KeyboardButton("Нет"), }, }, ResizeKeyboard = true, OneTimeKeyboard = true }; await Bot.SendTextMessageAsync(message.Chat.Id, "У тебя есть чем поделиться со мной?", ParseMode.Default, false, false, 0, keyboard5); stageM++; break; case 6: if (message.Text.ToLower() == "нет") { await Bot.SendTextMessageAsync(message.Chat.Id, "До завтра!"); } else if (message.Text.ToLower() == "да") { await Bot.SendTextMessageAsync(message.Chat.Id, "Излагай свои мысли"); } stageM++; break; case 7: persons[index].answer5 += message.Text + Environment.NewLine; break; } ; persons[index].stage = stageM; } offset = update.Id + 1; } } } } catch (Telegram.Bot.Exceptions.ApiRequestException ex) { MessageBox.Show(ex.Message); } }
//listing https://support.hbtc.co/hc/en-us/sections/360009462813-New-Listings // Notice https://support.hbtc.co/hc/en-us/sections/360009462793-Withdrawal-Opening-Suspension-Notice // others https://support.hbtc.co/hc/en-us/sections/360001994473-Others async void bw_DoWork(object sender, DoWorkEventArgs e) { var worker = sender as BackgroundWorker; try { ; // инициализируем API try { await Bot.SetWebhookAsync(""); // !!!!!!!!!!!!!!!!!!!!!!ЦИКЛ ПЕРЕЗАПУСКА } catch { await Bot.SetWebhookAsync(""); } { /* * // Inlin'ы * Bot.OnMessage += async (object sender2, Telegram.Bot.Args.MessageEventArgs e1) => * * Bot.StartReceiving(Array.Empty<UpdateType>()); * var timer = new Timer(); * timer.Interval = 7000; * timer.Tick += new EventHandler(SimpleFunc); //И печатает на экран что-то * timer.Start(); * * void SimpleFunc(object sendear, EventArgs e2) * { * if (link_pars != link_new) * { * * link_pars = link_new; * } * * System.Net.WebClient wc1 = new System.Net.WebClient(); * String link_Response = wc1.DownloadString("https://support.hbtc.co/hc/en-us/sections/360002667194-Recent-Activities"); * link_new = System.Text.RegularExpressions.Regex.Match(link_Response, @"(/hc/en-us/articles)+(.+)(?="" class)").Groups[0].Value; * Bot.SendTextMessageAsync(@"pesik123d", "", ParseMode.Html, false, false, 0, null); * if (Form1.count != 0) * { * Bot.SendTextMessageAsync(@"pesik123d", "", ParseMode.Html, false, false, 0, null); * } * Form1.count++; * Task.Delay(60000); * } * * Bot.StopReceiving(); * * }; * * Bot.OnCallbackQuery += async (object sc, Telegram.Bot.Args.CallbackQueryEventArgs ev) => * { * * }; */ Bot.OnUpdate += async(object su, Telegram.Bot.Args.UpdateEventArgs evu) => { try { var update = evu.Update; var message = update.Message; if (message == null) { return; } /* * if (question1.Count == 2 || message.From.Username == @"off_fov") * { * question1[1] = message.Text; * await Bot.SendTextMessageAsync(message.Chat.Id, question1[0] + "\n" + question1[1], ParseMode.Html, false, false, 0, keyboard_full); * await Bot.SendTextMessageAsync(message.Chat.Id, @"Вопрос ответ! Добавлен", ParseMode.Html, false, false, 0, keyboard_full); * * }*/ if (message.Text == "/win" & message.From.Username == @"off_fov") { await Bot.SendTextMessageAsync(message.Chat.Id, @"сам макака", ParseMode.Html, false, false, 0, null); } // https://www.hbtc.com/api/v1/hobbit/repurchase/info // @"https://api.hbtc.com/openapi/quote/v1/ticker/price" // charts // https://finviz.com/crypto_charts.ashx?t=ALL&tf=h1 if (message.Text == "/daily_repo@HBTC_RU_BOT") { try { System.Net.WebClient wc1 = new System.Net.WebClient(); String price_Responsehbc = wc1.DownloadString("https://api.hbtc.com/openapi/quote/v1/ticker/price"); String hbc_price1 = System.Text.RegularExpressions.Regex.Match(price_Responsehbc, @"HBCUSDT""+,""price"":""+[0-9]+.[0-9]+").Groups[0].Value; String hbc_price = System.Text.RegularExpressions.Regex.Match(hbc_price1, @"[0-9]+.[0-9]+").Groups[0].Value; System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://www.hbtc.com/api/v1/hobbit/repurchase/info"); String Distributed1 = System.Text.RegularExpressions.Regex.Match(price_Response, @"allocated"":""+[0-9]+.[0-9][0-9]").Groups[0].Value; String Distributed = System.Text.RegularExpressions.Regex.Match(Distributed1, @"[0-9]+.[0-9][0-9]").Groups[0].Value; System.Net.WebClient wc2 = new System.Net.WebClient(); String LatestPricefor10xPE_Response = wc2.DownloadString("https://www.hbtc.com/api/v1/hobbit/repurchase/info"); String LatestPricefor10xPE1 = System.Text.RegularExpressions.Regex.Match(LatestPricefor10xPE_Response, @"tenTimesPrice"":""+[0-9]+.[0-9][0-9]").Groups[0].Value; String LatestPricefor10xPE = System.Text.RegularExpressions.Regex.Match(LatestPricefor10xPE1, @"[0-9]+.[0-9][0-9]").Groups[0].Value; System.Net.WebClient wc3 = new System.Net.WebClient(); String LatestPricefor5xPE_Response = wc3.DownloadString("https://www.hbtc.com/api/v1/hobbit/repurchase/info"); String LatestPricefor5xPE1 = System.Text.RegularExpressions.Regex.Match(LatestPricefor5xPE_Response, @"fiveTimesPrice"":""+[0-9]+.[0-9][0-9]").Groups[0].Value; String LatestPricefor5xPE = System.Text.RegularExpressions.Regex.Match(LatestPricefor5xPE1, @"[0-9]+.[0-9][0-9]").Groups[0].Value; System.Net.WebClient wc4 = new System.Net.WebClient(); String LockedVolume_Response = wc4.DownloadString("https://www.hbtc.com/api/v1/hobbit/repurchase/info"); String LockedVolume1 = System.Text.RegularExpressions.Regex.Match(LockedVolume_Response, @"lockTotal"":""+[0-9]+").Groups[0].Value; String LockedVolume = System.Text.RegularExpressions.Regex.Match(LockedVolume1, @"[0-9]+").Groups[0].Value; CultureInfo temp_culture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); double dist_usdt = Convert.ToDouble(Convert.ToString(hbc_price)) * Convert.ToDouble(Convert.ToString(Distributed)); decimal dist_usdt_out = Convert.ToDecimal(dist_usdt.ToString("0.##")); var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти на hbtc.com", CallbackData = "demo", Url = "https://www.hbtc.com/captain/daily_repo" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); await Bot.SendTextMessageAsync(message.Chat.Id, "<code>Accu.to be Distributed: " + Distributed + " HBC" + "\n" + "Accu.to be Distributed: ~ " + dist_usdt_out + " USDT" + "\n" + "Latest Price 10xPE: " + LatestPricefor10xPE + " USDT \n" + "Latest Price 5PE: " + LatestPricefor5xPE + " USDT \n" + "LockedVolume: " + LockedVolume + " HBC</code>", ParseMode.Html, false, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/hbc_usdt@HBTC_RU_BOT") { try { System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://api.hbtc.com/openapi/quote/v1/ticker/price"); String hbc_price1 = System.Text.RegularExpressions.Regex.Match(price_Response, @"HBCUSDT""+,""price"":""+[0-9]+.[0-9]+").Groups[0].Value; String hbc_price = System.Text.RegularExpressions.Regex.Match(hbc_price1, @"[0-9]+.[0-9]+").Groups[0].Value; var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре HBC/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/HBC/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); await Bot.SendTextMessageAsync(message.Chat.Id, "<code><b>HBC/USDT</b>" + "\n" + "Цена:" + hbc_price + " USDT</code>", ParseMode.Html, false, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/btc_usdt@HBTC_RU_BOT") { try { //new site api //[0-9]+.[0-9]+(?=,"lastVolume") System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://finviz.com/api/quote.ashx?&ticker=BTCUSD&instrument=crypto&timeframe=i5"); String btc_price = System.Text.RegularExpressions.Regex.Match(price_Response, @"[0-9]+.[0-9]+(?=,""lastVolume"")").Groups[0].Value; //https://finviz.com/api/quote.ashx?&ticker=BTCUSD&instrument=crypto&timeframe=i5 //htbc site api /* * System.Net.WebClient wc = new System.Net.WebClient(); * String price_Response = wc.DownloadString("https://api.hbtc.com/openapi/quote/v1/ticker/price"); * String btc_price1 = System.Text.RegularExpressions.Regex.Match(price_Response, @"BTCUSDT""+,""price"":""+[0-9]+.[0-9]+").Groups[0].Value; * String btc_price = System.Text.RegularExpressions.Regex.Match(btc_price1, @"[0-9]+.[0-9]+").Groups[0].Value; */ System.Net.WebClient wc1 = new System.Net.WebClient(); String rev_Response = wc1.DownloadString("https://finviz.com/crypto_charts.ashx"); String rev_1 = System.Text.RegularExpressions.Regex.Match(rev_Response, @"&rev=[0-9]+").Groups[0].Value; String rev = System.Text.RegularExpressions.Regex.Match(rev_1, @"[0-9]+").Groups[0].Value; //photo rev // [0-9]+(?=" width="320") var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре BTC/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/BTC/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); //await Bot.SendTextMessageAsync(message.Chat.Id, "<code><b>BTC/USDT</b>" + "\n" + "Цена:" + btc_price + " USDT</code>", ParseMode.Html, false, false, 0, inlineKeyboardMarkup); await Bot.SendPhotoAsync(message.Chat.Id, photo : "https://finviz.com/fx_image.ashx?btcusd_m5_s.png&rev=" + rev, " <code><b>BTC/USDT</b>" + "\n" + "Цена:" + btc_price + " USDT</code>", ParseMode.Html, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/bch_usdt@HBTC_RU_BOT") { try { //new site api //[0-9]+.[0-9]+(?=,"lastVolume") System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://finviz.com/api/quote.ashx?&ticker=BCHUSD&instrument=crypto&timeframe=i5"); String BCH_price = System.Text.RegularExpressions.Regex.Match(price_Response, @"[0-9]+.[0-9]+(?=,""lastVolume"")").Groups[0].Value; //htbc site api /* * System.Net.WebClient wc = new System.Net.WebClient(); * String price_Response = wc.DownloadString("https://api.hbtc.com/openapi/quote/v1/ticker/price"); * String btc_price1 = System.Text.RegularExpressions.Regex.Match(price_Response, @"BTCUSDT""+,""price"":""+[0-9]+.[0-9]+").Groups[0].Value; * String btc_price = System.Text.RegularExpressions.Regex.Match(btc_price1, @"[0-9]+.[0-9]+").Groups[0].Value; */ System.Net.WebClient wc1 = new System.Net.WebClient(); String rev_Response = wc1.DownloadString("https://finviz.com/crypto_charts.ashx"); String rev_1 = System.Text.RegularExpressions.Regex.Match(rev_Response, @"&rev=[0-9]+").Groups[0].Value; String rev = System.Text.RegularExpressions.Regex.Match(rev_1, @"[0-9]+").Groups[0].Value; //photo rev // [0-9]+(?=" width="320") var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре BCH/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/BCH/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); //await Bot.SendTextMessageAsync(message.Chat.Id, "<code><b>BTC/USDT</b>" + "\n" + "Цена:" + btc_price + " USDT</code>", ParseMode.Html, false, false, 0, inlineKeyboardMarkup); await Bot.SendPhotoAsync(message.Chat.Id, photo : "https://finviz.com/fx_image.ashx?bchusd_m5_s.png&rev=" + rev, " <code><b>BCH/USDT</b>" + "\n" + "Цена:" + BCH_price + " USDT</code>", ParseMode.Html, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/eth_usdt@HBTC_RU_BOT") { try { System.Net.WebClient wc1 = new System.Net.WebClient(); String rev_Response = wc1.DownloadString("https://finviz.com/crypto_charts.ashx"); String rev_1 = System.Text.RegularExpressions.Regex.Match(rev_Response, @"&rev=[0-9]+").Groups[0].Value; String rev = System.Text.RegularExpressions.Regex.Match(rev_1, @"[0-9]+").Groups[0].Value; System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://finviz.com/api/quote.ashx?&ticker=ETHUSD&instrument=crypto&timeframe=i5"); String ETH_price = System.Text.RegularExpressions.Regex.Match(price_Response, @"[0-9]+.[0-9]+(?=,""lastVolume"")").Groups[0].Value; //https://finviz.com/api/quote.ashx?&ticker=BTCUSD&instrument=crypto&timeframe=i5 var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре ETH/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/ETH/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); await Bot.SendPhotoAsync(message.Chat.Id, photo : "https://finviz.com/fx_image.ashx?ethusd_m5_s.png&rev=" + rev, " <code><b>ETH/USDT</b>" + "\n" + "Цена:" + ETH_price + " USDT</code>", ParseMode.Html, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/ltc_usdt@HBTC_RU_BOT") { try { System.Net.WebClient wc1 = new System.Net.WebClient(); String rev_Response = wc1.DownloadString("https://finviz.com/crypto_charts.ashx"); String rev_1 = System.Text.RegularExpressions.Regex.Match(rev_Response, @"&rev=[0-9]+").Groups[0].Value; String rev = System.Text.RegularExpressions.Regex.Match(rev_1, @"[0-9]+").Groups[0].Value; System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://finviz.com/api/quote.ashx?&ticker=LTCUSD&instrument=crypto&timeframe=i5"); String ltc_price = System.Text.RegularExpressions.Regex.Match(price_Response, @"[0-9]+.[0-9]+(?=,""lastVolume"")").Groups[0].Value; var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре LTC/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/LTC/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); await Bot.SendPhotoAsync(message.Chat.Id, photo : "https://finviz.com/fx_image.ashx?ltcusd_m5_s.png&rev=" + rev, " <code><b>LTC/USDT</b>" + "\n" + "Цена:" + ltc_price + " USDT</code>", ParseMode.Html, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/eos_usdt@HBTC_RU_BOT") { try { System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://api.hbtc.com/openapi/quote/v1/ticker/price"); String EOS_price1 = System.Text.RegularExpressions.Regex.Match(price_Response, @"EOSUSDT""+,""price"":""+[0-9]+.[0-9]+").Groups[0].Value; String EOS_price = System.Text.RegularExpressions.Regex.Match(EOS_price1, @"[0-9]+.[0-9]+").Groups[0].Value; var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре EOS/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/EOS/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); await Bot.SendTextMessageAsync(message.Chat.Id, "<code><b>EOS/USDT</b>" + "\n" + "Цена:" + EOS_price + " USDT</code>", ParseMode.Html, false, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Text == "/xrp_usdt@HBTC_RU_BOT") { try { System.Net.WebClient wc1 = new System.Net.WebClient(); String rev_Response = wc1.DownloadString("https://finviz.com/crypto_charts.ashx"); String rev_1 = System.Text.RegularExpressions.Regex.Match(rev_Response, @"&rev=[0-9]+").Groups[0].Value; String rev = System.Text.RegularExpressions.Regex.Match(rev_1, @"[0-9]+").Groups[0].Value; System.Net.WebClient wc = new System.Net.WebClient(); String price_Response = wc.DownloadString("https://finviz.com/api/quote.ashx?&ticker=XRPUSD&instrument=crypto&timeframe=i5"); String xrp_price = System.Text.RegularExpressions.Regex.Match(price_Response, @"[0-9]+.[0-9]+(?=,""lastVolume"")").Groups[0].Value; var inlineKeyboardMarkup = new InlineKeyboardMarkup(new[] { new [] { new InlineKeyboardButton { Text = "Перейти к паре XRP/USDT", CallbackData = "demo", Url = "https://www.hbtc.co/exchange/XRP/USDT" } } }); await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); await Bot.SendPhotoAsync(message.Chat.Id, photo : "https://finviz.com/fx_image.ashx?xrpusd_m5_s.png&rev=" + rev, " <code><b>XRP/USDT</b>" + "\n" + "Цена:" + xrp_price + " USDT</code>", ParseMode.Html, false, 0, inlineKeyboardMarkup); } catch { } } if (message.Type == MessageType.ChatMemberLeft) { try { await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); } catch { } return; } var entities = message.Entities.Where(t => t.Type == MessageEntityType.Url || t.Type == MessageEntityType.Mention); foreach (var entity in entities) { if (entity.Type == MessageEntityType.Url) { try { //40103694 - @off_fov //571522545 - @ProAggressive //320968789 - @timcheg1 //273228404 - @hydranik //435567580 - Никита //352345393 - @i_am_zaytsev //430153320 - @KingOfMlnD //579784 - @kamiyar //536915847 - @m1Bean //460657014 - @DenisSenatorov if (message.From.Username == @"off_fov" || message.From.Username == @"bar1nn" || message.From.Username == @"doretos" || message.From.Username == @"ProAggressive" || message.From.Username == @"Mira_miranda") { return; } else { await Bot.DeleteMessageAsync(message.Chat.Id, message.MessageId); if (update.Message.From.Username != null) { await Bot.SendTextMessageAsync(message.Chat.Id, "@" + message.From.Username + ", Ссылки запрещены!"); return; } else { await Bot.SendTextMessageAsync(message.Chat.Id, message.From.FirstName + ", Ссылки запрещены!"); return; } } } catch { } return; } } } catch { } }; Bot.StartReceiving(); // запускаем прием обновлений } } catch (Telegram.Bot.Exceptions.ApiRequestException ex) { Console.WriteLine(ex.Message); // если ключ не подошел - пишем об этом в консоль отладки } }