2018-05-03 00:56:06 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Geekbot.net.Lib.ErrorHandling;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.Commands.Randomness.Cat
|
|
|
|
|
{
|
|
|
|
|
public class Cat : ModuleBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
|
|
|
|
|
|
|
|
|
public Cat(IErrorHandler errorHandler)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler = errorHandler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command("cat", RunMode = RunMode.Async)]
|
|
|
|
|
[Summary("Return a random image of a cat.")]
|
|
|
|
|
public async Task Say()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var client = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
client.BaseAddress = new Uri("https://aws.random.cat");
|
|
|
|
|
var response = await client.GetAsync("/meow");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
|
|
|
|
|
var eb = new EmbedBuilder();
|
|
|
|
|
eb.ImageUrl = catFile.File;
|
|
|
|
|
await ReplyAsync("", false, eb.Build());
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
await ReplyAsync("Seems like the dog cought the cat (error occured)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2018-06-13 22:18:57 +02:00
|
|
|
|
await _errorHandler.HandleCommandException(e, Context);
|
2018-05-03 00:56:06 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-12 21:49:04 +02:00
|
|
|
|
}
|