Adding Initial API support, updating readme

This commit is contained in:
Runebaas 2017-10-02 21:57:48 +02:00
parent 6732506dae
commit 92015d8880
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
27 changed files with 78 additions and 33 deletions

View 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 Dog : ModuleBase
{
[Command("dog", RunMode = RunMode.Async)]
[Summary("Return a random image of a dog.")]
public async Task Say()
{
using (var client = new HttpClient())
{
try
{
client.BaseAddress = new Uri("http://random.dog");
var response = await client.GetAsync("/woof.json");
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var dogFile = JsonConvert.DeserializeObject<DogResponse>(stringResponse);
await ReplyAsync(dogFile.url);
}
catch (HttpRequestException e)
{
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
}
}
}
}
public class DogResponse
{
public string url { get; set; }
}
}