remove the !corona command

This commit is contained in:
Daan Boerlage 2022-07-22 18:00:12 +02:00
parent c1b5a4d449
commit 15e1d10839
Signed by: daan
GPG key ID: FCE070E1E4956606
3 changed files with 0 additions and 148 deletions

View file

@ -1,19 +0,0 @@
using System.Text.Json.Serialization;
namespace Geekbot.Bot.Commands.Utils.Corona
{
public record CoronaApiCountryResponseDto
{
[JsonPropertyName("country")]
public string Country { get; init; }
[JsonPropertyName("cases")]
public decimal Cases { get; init; }
[JsonPropertyName("deaths")]
public decimal Deaths { get; init; }
[JsonPropertyName("recovered")]
public decimal Recovered { get; init; }
}
}

View file

@ -1,119 +0,0 @@
using System.Text;
using Discord;
using Discord.Commands;
using Geekbot.Core;
using Geekbot.Core.Converters;
using Geekbot.Core.ErrorHandling;
using Geekbot.Core.Extensions;
using Geekbot.Core.GuildSettingsManager;
using Localization = Geekbot.Core.Localization;
namespace Geekbot.Bot.Commands.Utils.Corona
{
public class CoronaStats : GeekbotCommandBase
{
public CoronaStats(IErrorHandler errorHandler, IGuildSettingsManager guildSettingsManager) : base(errorHandler, guildSettingsManager)
{
}
[Command("corona", RunMode = RunMode.Async)]
[Summary("Get the latest worldwide corona statistics")]
public async Task Summary([Summary("CountryCode")] string countryCode = null)
{
try
{
var summary = await GetCoronaInfo(countryCode);
if (summary == null)
{
await Context.Channel.SendMessageAsync($"`{countryCode}` is not a valid country code");
return;
}
var activeCases = summary.Cases - (summary.Recovered + summary.Deaths);
string CalculatePercentage(decimal i) => (i / summary.Cases).ToString("#0.##%");
var activePercent = CalculatePercentage(activeCases);
var recoveredPercentage = CalculatePercentage(summary.Recovered);
var deathsPercentage = CalculatePercentage(summary.Deaths);
var numberFormat = "#,#";
var totalFormatted = summary.Cases.ToString(numberFormat);
var activeFormatted = activeCases.ToString(numberFormat);
var recoveredFormatted = summary.Recovered.ToString(numberFormat);
var deathsFormatted = summary.Deaths.ToString(numberFormat);
var embedTitleBuilder = new StringBuilder();
embedTitleBuilder.Append(Localization.Corona.ConfirmedCases);
if (!string.IsNullOrEmpty(summary.Country))
{
embedTitleBuilder.Append(" - ");
embedTitleBuilder.Append(EmojiConverter.CountryCodeToEmoji(summary.Country));
}
var eb = new EmbedBuilder
{
Author = new EmbedAuthorBuilder
{
Name = embedTitleBuilder.ToString(),
IconUrl = "https://www.redcross.org/content/dam/icons/disasters/virus/Virus-1000x1000-R-Pl.png"
},
Footer = new EmbedFooterBuilder
{
Text = $"{Localization.Corona.Source}: covid19-api.org",
},
Color = Color.Red
};
eb.AddField(Localization.Corona.Total, totalFormatted);
eb.AddInlineField(Localization.Corona.Active, $"{activeFormatted} ({activePercent})");
eb.AddInlineField(Localization.Corona.Recovered, $"{recoveredFormatted} ({recoveredPercentage})");
eb.AddInlineField(Localization.Corona.Deaths, $"{deathsFormatted} ({deathsPercentage})");
await Context.Channel.SendMessageAsync(String.Empty, false, eb.Build());
}
catch (Exception e)
{
await ErrorHandler.HandleCommandException(e, Context);
}
}
private async Task<CoronaTotalDto> GetCoronaInfo(string countryCode = null)
{
var allCountries = await HttpAbstractions.Get<List<CoronaApiCountryResponseDto>>(new Uri("https://covid19-api.org/api/status"));
if (string.IsNullOrEmpty(countryCode))
{
return allCountries.Aggregate(
new CoronaTotalDto(),
(accumulate, source) =>
{
accumulate.Cases += source.Cases;
accumulate.Deaths += source.Deaths;
accumulate.Recovered += source.Recovered;
return accumulate;
}
);
}
if (countryCode.Length != 2)
{
return null;
}
var upcasedCountryCode = countryCode.ToUpper();
var countryStats = allCountries.Find(x => x.Country == upcasedCountryCode);
if (countryStats == null)
{
return null;
}
return new CoronaTotalDto()
{
Country = upcasedCountryCode,
Cases = countryStats.Cases,
Deaths = countryStats.Deaths,
Recovered = countryStats.Recovered,
};
}
}
}

View file

@ -1,10 +0,0 @@
namespace Geekbot.Bot.Commands.Utils.Corona
{
public record CoronaTotalDto
{
public string Country { get; set; }
public decimal Cases { get; set; }
public decimal Deaths { get; set; }
public decimal Recovered { get; set; }
}
}