geekbot/Geekbot.net/Commands/Randomness/Dad/DadJokes.cs

33 lines
927 B
C#
Raw Normal View History

2018-04-28 19:27:41 +02:00
using System;
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.Dad
2018-04-28 19:27:41 +02:00
{
public class DadJokes : ModuleBase
{
private readonly IErrorHandler _errorHandler;
public DadJokes(IErrorHandler errorHandler)
{
_errorHandler = errorHandler;
}
[Command("dad", RunMode = RunMode.Async)]
[Summary("A random dad joke")]
public async Task Say()
{
try
{
2020-07-15 02:52:13 +02:00
var response = await HttpAbstractions.Get<DadJokeResponseDto>(new Uri("https://icanhazdadjoke.com/"));
await ReplyAsync(response.Joke);
2018-04-28 19:27:41 +02:00
}
catch (Exception e)
{
await _errorHandler.HandleCommandException(e, Context);
2018-04-28 19:27:41 +02:00
}
}
}
}