Adds dog fact
This commit is contained in:
parent
4b3ce14075
commit
0d538ad703
|
@ -1,22 +1,20 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace DeukBot4.APIHandlers
|
namespace DeukBot4.APIHandlers
|
||||||
{
|
{
|
||||||
public static class CatFactsApi
|
public static class AnimalFactsApi
|
||||||
{
|
{
|
||||||
private const string URL = "http://api.levi506.net/";
|
private const string URL = "https://api.levi506.net/";
|
||||||
|
|
||||||
public static async Task<string> GetRandomCatFact()
|
public static async Task<string> GetRandomCatFact(string animal)
|
||||||
{
|
{
|
||||||
var client = new HttpClient {BaseAddress = new Uri(URL)};
|
var client = new HttpClient {BaseAddress = new Uri(URL)};
|
||||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
var response = await client.GetAsync("fact/animal/cat"); // Blocking call!
|
var response = await client.GetAsync("/v1/fact/animal/" + animal); // Blocking call!
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
<LangVersion>7.1</LangVersion>
|
<LangVersion>7.1</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="2.0.0-beta2-00999" />
|
<PackageReference Include="Discord.Net" Version="2.0.0-beta2-01018" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="Npgsql" Version="4.0.3" />
|
<PackageReference Include="Npgsql" Version="4.0.3" />
|
||||||
<PackageReference Include="StackExchange.Redis" Version="1.2.6" />
|
<PackageReference Include="StackExchange.Redis" Version="2.0.513" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -114,12 +114,20 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("catfact", PermissionLevel.Everyone)]
|
[Command("catfact", PermissionLevel.Everyone)]
|
||||||
[CommandHelp("Returns a random cat fact", "Returns a random cat fact, powered by https://catfact.ninja/")]
|
[CommandHelp("Returns a random cat fact", "Returns a random cat fact")]
|
||||||
public async Task RandomCatFact(CommandRequest request)
|
public async Task RandomCatFact(CommandRequest request)
|
||||||
{
|
{
|
||||||
await request.SendSimpleEmbed("Cat Fact", await CatFactsApi.GetRandomCatFact());
|
await request.SendSimpleEmbed("Cat Fact", await AnimalFactsApi.GetRandomCatFact("cat"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Command("dogfact", PermissionLevel.Everyone)]
|
||||||
|
[CommandHelp("Returns a random dog fact", "Returns a random cat fact")]
|
||||||
|
public async Task RandomDogFact(CommandRequest request)
|
||||||
|
{
|
||||||
|
await request.SendSimpleEmbed("Dog Fact", await AnimalFactsApi.GetRandomCatFact("dog"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Command("catpic", PermissionLevel.Everyone)]
|
[Command("catpic", PermissionLevel.Everyone)]
|
||||||
[CommandHelp("Returns a random cat picture", "Returns a random cat picture")]
|
[CommandHelp("Returns a random cat picture", "Returns a random cat picture")]
|
||||||
[CommandParameters(ParameterMatcher.ParameterType.Remainder)]
|
[CommandParameters(ParameterMatcher.ParameterType.Remainder)]
|
||||||
|
|
Loading…
Reference in New Issue