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/Cat/Cat.cs
Normal file
54
Geekbot.net/Commands/Randomness/Cat/Cat.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.Cat
|
||||
{
|
||||
public class Cat : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Cat(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("cat", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Randomness)]
|
||||
[Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
client.BaseAddress = new Uri("https://aws.random.cat");
|
||||
var response = await client.GetAsync("/meow");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.ImageUrl = catFile.File;
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
catch
|
||||
{
|
||||
await ReplyAsync("Seems like the dog cought the cat (error occured)");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
Geekbot.net/Commands/Randomness/Cat/CatResponseDto.cs
Normal file
7
Geekbot.net/Commands/Randomness/Cat/CatResponseDto.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Geekbot.net.Commands.Randomness.Cat
|
||||
{
|
||||
internal class CatResponseDto
|
||||
{
|
||||
public string File { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue