Refaction all files into component based folders
This commit is contained in:
parent
55e152f4aa
commit
e3adf55742
102 changed files with 816 additions and 709 deletions
54
Geekbot.net/Commands/Randomness/Dog/Dog.cs
Normal file
54
Geekbot.net/Commands/Randomness/Dog/Dog.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Geekbot.net.Commands.Randomness.Dog
|
||||
{
|
||||
public class Dog : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Dog(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("dog", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Randomness)]
|
||||
[Summary("Return a random image of a dog.")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
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<DogResponseDto>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.ImageUrl = dogFile.Url;
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
Geekbot.net/Commands/Randomness/Dog/DogResponseDto.cs
Normal file
7
Geekbot.net/Commands/Randomness/Dog/DogResponseDto.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Geekbot.net.Commands.Randomness.Dog
|
||||
{
|
||||
internal class DogResponseDto
|
||||
{
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue