public async Task SendAnswer(BotClient client, NewMessage message) { if (!this.CanHandleMessage(client, message)) { return; } var request = WebRequest.Create("https://dog.ceo/api/breeds/image/random"); var response = request.GetResponseAsync(); await Task.WhenAll(response); var responseStream = response.Result.GetResponseStream(); if (responseStream != null && responseStream.CanRead) { using (var streamReader = new StreamReader(responseStream)) { var definition = new { status = "", message = "" }; var link = JsonConvert.DeserializeAnonymousType(streamReader.ReadToEnd(), definition).message; var attachment = new SlackAPI.Attachment(); attachment.fallback = "dog"; attachment.image_url = link; await client.PostTextMessageToChannelWithAttachment("", attachment, message.channel); } } }
public async Task SendAnswer(BotClient client, NewMessage message) { if (!CanHandleMessage(client, message)) { return; } var links = new List <string>(); var counter = 1; if (message.text.ToLowerInvariant().Contains("атака")) { counter = 5; } var responses = Enumerable.Range(0, counter).Select(i => { var request = WebRequest.Create("http://thecatapi.com/api/images/get"); return(request.GetResponseAsync()); }).ToArray(); await Task.WhenAll(responses); links.AddRange(responses.Select(r => r.Result.ResponseUri.OriginalString)); var att = new SlackAPI.Attachment(); att.fallback = "cat"; att.image_url = links.FirstOrDefault(); await client.PostTextMessageToChannelWithAttachment("", att, message.channel); //Attachments = new List<SlackAttachment>(links.Select(l => new SlackAttachment(){ImageUrl = l})) }
public override Task SendAnswer(BotClient client, NewMessage message) { if (!CanHandleMessage(client, message)) { return(null); } client.Kick(message.channel, message.user); var attachment = attachments.GetRandom(); return(client.PostTextMessageToChannelWithAttachment(attachment.title, attachment, message.channel)); }
public async Task SendAnswer(BotClient client, NewMessage message) { if (!this.CanHandleMessage(client, message)) { return; } var attachment = new SlackAPI.Attachment(); attachment.fallback = "dog"; attachment.image_url = kidImage; await client.PostTextMessageToChannelWithAttachment("", attachment, message.channel); }