Fixed code inconsistencies and adding support for logging to sentryio

This commit is contained in:
Runebaas 2017-10-26 00:55:04 +02:00
parent 2e083bc188
commit 9efac29956
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
18 changed files with 228 additions and 161 deletions

View file

@ -9,28 +9,42 @@ 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()
{
using (var client = new HttpClient())
try
{
try
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://random.cat");
var response = await client.GetAsync("/meow.php");
response.EnsureSuccessStatusCode();
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<CatResponse>(stringResponse);
await ReplyAsync(catFile.file);
}
catch (HttpRequestException e)
{
await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}");
var stringResponse = await response.Content.ReadAsStringAsync();
var catFile = JsonConvert.DeserializeObject<CatResponse>(stringResponse);
await ReplyAsync(catFile.file);
}
catch (HttpRequestException e)
{
await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}");
}
}
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
}
}
}