Add kanye command
This commit is contained in:
parent
0ae9dcce67
commit
3d493fa531
2 changed files with 61 additions and 0 deletions
53
Geekbot.net/Commands/Randomness/Kanye/Kanye.cs
Normal file
53
Geekbot.net/Commands/Randomness/Kanye/Kanye.cs
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Commands.Randomness.Dad;
|
||||||
|
using Geekbot.net.Lib.ErrorHandling;
|
||||||
|
using Microsoft.AspNetCore.Hosting.Internal;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Geekbot.net.Commands.Randomness.Kanye
|
||||||
|
{
|
||||||
|
public class Kanye : ModuleBase
|
||||||
|
{
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
public Kanye(IErrorHandler errorHandler)
|
||||||
|
{
|
||||||
|
_errorHandler = errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("kanye", RunMode = RunMode.Async)]
|
||||||
|
[Summary("A random kayne west quote")]
|
||||||
|
public async Task Say()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var client = new HttpClient())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
|
||||||
|
var response = await client.GetAsync("https://api.kanye.rest/");
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||||
|
var data = JsonConvert.DeserializeObject<KanyeResponseDto>(stringResponse);
|
||||||
|
await ReplyAsync(data.Quote);
|
||||||
|
}
|
||||||
|
catch (HttpRequestException)
|
||||||
|
{
|
||||||
|
await ReplyAsync("Api down...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
await _errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace Geekbot.net.Commands.Randomness.Kanye
|
||||||
|
{
|
||||||
|
public class KanyeResponseDto
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Quote { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue