1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-29 02:29:55 +03:00

Remora.Discord part 1 out of ∞

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-05-16 00:11:11 +05:00
parent 02949656bf
commit 201a1ce079
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
24 changed files with 141 additions and 1588 deletions

35
Extensions.cs Normal file
View file

@ -0,0 +1,35 @@
using System.Globalization;
using Microsoft.Extensions.Configuration;
using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Results;
namespace Boyfriend;
public static class Extensions {
private static readonly Dictionary<string, CultureInfo> CultureInfoCache = new() {
{ "en", new CultureInfo("en-US") },
{ "ru", new CultureInfo("ru-RU") },
{ "mctaylors-ru", new CultureInfo("tt-RU") }
};
public static Result<bool> GetConfigBool(this IGuild guild, string key) {
var value = Boyfriend.GuildConfiguration.GetValue<bool?>($"GuildConfigs:{guild.ID}:{key}");
return value is not null ? Result<bool>.FromSuccess(value.Value) : Result<bool>.FromError(new NotFoundError());
}
public static Result<IChannel> GetChannel(this IGuildCreate.IAvailableGuild guild, string key) {
var value = Boyfriend.GuildConfiguration.GetValue<ulong?>($"GuildConfigs:{guild.ID}:{key}");
if (value is null) return Result<IChannel>.FromError(new NotFoundError());
var match = guild.Channels.SingleOrDefault(channel => channel!.ID.Equals(value.Value), null);
return match is not null
? Result<IChannel>.FromSuccess(match)
: Result<IChannel>.FromError(new NotFoundError());
}
public static CultureInfo GetCulture(this IGuild guild) {
var value = Boyfriend.GuildConfiguration.GetValue<string?>($"GuildConfigs:{guild.ID}:Language");
return value is not null ? CultureInfoCache[value] : CultureInfoCache["en"];
}
}