Adding Initial API support, updating readme
This commit is contained in:
parent
6732506dae
commit
92015d8880
27 changed files with 78 additions and 33 deletions
39
Geekbot.net/Commands/Cat.cs
Normal file
39
Geekbot.net/Commands/Cat.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Geekbot.net.Commands
|
||||
{
|
||||
public class Cat : ModuleBase
|
||||
{
|
||||
[Command("cat", RunMode = RunMode.Async)]
|
||||
[Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
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<CatResponse>(stringResponse);
|
||||
await ReplyAsync(catFile.file);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CatResponse
|
||||
{
|
||||
public string file { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue