From 3f02f90d70f1855db303619555078a180cea49b9 Mon Sep 17 00:00:00 2001 From: runebaas Date: Wed, 28 Mar 2018 21:45:29 +0200 Subject: [PATCH] Enable cat command again --- Geekbot.net/Commands/Cat.cs | 115 ++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/Geekbot.net/Commands/Cat.cs b/Geekbot.net/Commands/Cat.cs index e096f20..1f97d5a 100644 --- a/Geekbot.net/Commands/Cat.cs +++ b/Geekbot.net/Commands/Cat.cs @@ -1,59 +1,58 @@ -using System; -using System.Net.Http; -using System.Threading.Tasks; -using Discord; -using Discord.Commands; -using Geekbot.net.Lib; -using Newtonsoft.Json; - -namespace Geekbot.net.Commands -{ - public class Cat : ModuleBase - { - private readonly IErrorHandler _errorHandler; - - public Cat(IErrorHandler errorHandler) - { - _errorHandler = errorHandler; - } - - [Command("cat", RunMode = RunMode.Async)] - [Remarks(CommandCategories.Randomness)] - [Summary("Return a random image of a cat.")] - public async Task Say() - { - try - { -// using (var client = new HttpClient()) -// { -// try -// { -// client.BaseAddress = new Uri("http://random.cat"); -// var response = await client.GetAsync("/meow.php"); -// response.EnsureSuccessStatusCode(); -// -// var stringResponse = await response.Content.ReadAsStringAsync(); -// var catFile = JsonConvert.DeserializeObject(stringResponse); -// var eb = new EmbedBuilder(); -// eb.ImageUrl = catFile.file; -// await ReplyAsync("", false, eb.Build()); -// } -// catch (HttpRequestException e) -// { -// await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}"); -// } -// } - await ReplyAsync("Command disabled for now because http://random.cat is down"); - } - catch (Exception e) - { - _errorHandler.HandleCommandException(e, Context); - } - } - - private class CatResponse - { - public string file { get; set; } - } - } +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Geekbot.net.Lib; +using Newtonsoft.Json; + +namespace Geekbot.net.Commands +{ + public class Cat : ModuleBase + { + private readonly IErrorHandler _errorHandler; + + public Cat(IErrorHandler errorHandler) + { + _errorHandler = errorHandler; + } + + [Command("cat", RunMode = RunMode.Async)] + [Remarks(CommandCategories.Randomness)] + [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(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) + { + _errorHandler.HandleCommandException(e, Context); + } + } + + private class CatResponse + { + public string file { get; set; } + } + } } \ No newline at end of file