private static async void _imageTimer_Elapsed(object sender, ElapsedEventArgs e) { _imageTimer.Stop(); var image = new FileToSend(); foreach (var chat in chatIds) { try { using (var img = GoogleImage.GetGoogleRandomImage()) { image.Filename = "random.jpg"; image.Content = img; var msg = await _bot.SendPhotoAsync(chat, image); } } catch { await _bot.SendTextMessageAsync(chat, "Братан, гугл не отвечает"); } } NewImageTimerInterval(); _imageTimer.Start(); }
private async static Task RandomImageCommand(Message message) { var pars = message.Text.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); if (pars.Length <= 1) { try { var imageToSend = new FileToSend(); using (var img = GoogleImage.GetGoogleRandomImage(out string selectedTopic)) { imageToSend.Filename = "random.jpg"; imageToSend.Content = img; var msg = await _bot.SendPhotoAsync( message.Chat.Id, imageToSend, $"Изображение на тему: {selectedTopic}"); } } catch (Exception e) { await _bot.SendTextMessageAsync(message.Chat.Id, "Братан, гугл не отвечает"); } return; } var image = new FileToSend(); var searchstring = pars.Where((s, i) => i != 0).Aggregate("", (res, p) => res += " " + p); try { using (var img = GoogleImage.GetGoogleRandomImage(searchstring)) { image.Filename = "random.jpg"; image.Content = img; var msg = await _bot.SendPhotoAsync(message.Chat.Id, image); } } catch (Exception e) { await _bot.SendTextMessageAsync(message.Chat.Id, "Братан, гугл не отвечает"); } }