Use greetings.dev instead of hardcoded greetings
This commit is contained in:
parent
580a514ce5
commit
c94d73736d
4 changed files with 37 additions and 1605 deletions
11
Geekbot.net/Commands/Randomness/Greetings/GreetingBaseDto.cs
Normal file
11
Geekbot.net/Commands/Randomness/Greetings/GreetingBaseDto.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace Geekbot.net.Commands.Randomness.Greetings
|
||||
{
|
||||
public class GreetingBaseDto
|
||||
{
|
||||
public string Language { get; set; }
|
||||
public string LanguageNative { get; set; }
|
||||
public string LanguageCode { get; set; }
|
||||
public string Script { get; set; }
|
||||
public GreetingDto Primary { get; set; }
|
||||
}
|
||||
}
|
|
@ -3,8 +3,8 @@ namespace Geekbot.net.Commands.Randomness.Greetings
|
|||
public class GreetingDto
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string Dialect { get; set; } = null;
|
||||
public string Romanization { get; set; } = null;
|
||||
public string Dialect { get; set; }
|
||||
public string Romanization { get; set; }
|
||||
public string[] Use { get; set; }
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,12 @@
|
|||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Commands.Randomness.Cat;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Geekbot.net.Commands.Randomness.Greetings
|
||||
{
|
||||
|
@ -23,20 +26,20 @@ namespace Geekbot.net.Commands.Randomness.Greetings
|
|||
{
|
||||
try
|
||||
{
|
||||
var greeting = GreetingProvider.Greetings[new Random().Next(GreetingProvider.GreetingCount - 1)];
|
||||
var greeting = await GetRandomGreeting();
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.Title = greeting.Text;
|
||||
eb.Title = greeting.Primary.Text;
|
||||
eb.AddInlineField("Language", greeting.Language);
|
||||
|
||||
if (greeting.Dialect != null)
|
||||
if (greeting.Primary.Dialect != null)
|
||||
{
|
||||
eb.AddInlineField("Dialect", greeting.Dialect);
|
||||
eb.AddInlineField("Dialect", greeting.Primary.Dialect);
|
||||
}
|
||||
|
||||
if (greeting.Romanization != null)
|
||||
if (greeting.Primary.Romanization != null)
|
||||
{
|
||||
eb.AddInlineField("Roman", greeting.Romanization);
|
||||
eb.AddInlineField("Roman", greeting.Primary.Romanization);
|
||||
}
|
||||
|
||||
await ReplyAsync(string.Empty, false, eb.Build());
|
||||
|
@ -46,5 +49,18 @@ namespace Geekbot.net.Commands.Randomness.Greetings
|
|||
await _errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<GreetingBaseDto> GetRandomGreeting()
|
||||
{
|
||||
using var client = new HttpClient
|
||||
{
|
||||
BaseAddress = new Uri("https://api.greetings.dev")
|
||||
};
|
||||
var response = await client.GetAsync("/v1/greeting");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<GreetingBaseDto>(stringResponse);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue