geekbot/Geekbot.net/Commands/Randomness/Chuck/ChuckNorrisJokes.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2018-04-28 19:27:41 +02:00
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Discord.Commands;
2020-07-15 02:52:13 +02:00
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
2018-04-28 19:27:41 +02:00
namespace Geekbot.net.Commands.Randomness.Chuck
2018-04-28 19:27:41 +02:00
{
public class ChuckNorrisJokes : ModuleBase
{
private readonly IErrorHandler _errorHandler;
public ChuckNorrisJokes(IErrorHandler errorHandler)
{
_errorHandler = errorHandler;
}
[Command("chuck", RunMode = RunMode.Async)]
[Summary("A random chuck norris joke")]
public async Task Say()
{
try
{
try
2018-04-28 19:27:41 +02:00
{
2020-07-15 02:52:13 +02:00
var response = await HttpAbstractions.Get<ChuckNorrisJokeResponseDto>(new Uri("https://api.chucknorris.io/jokes/random"));
await ReplyAsync(response.Value);
}
catch (HttpRequestException)
{
await ReplyAsync("Api down...");
2018-04-28 19:27:41 +02:00
}
}
catch (Exception e)
{
await _errorHandler.HandleCommandException(e, Context);
2018-04-28 19:27:41 +02:00
}
}
}
}