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 CultureInfoCache = new() { { "en", new CultureInfo("en-US") }, { "ru", new CultureInfo("ru-RU") }, { "mctaylors-ru", new CultureInfo("tt-RU") } }; public static Result GetConfigBool(this IGuild guild, string key) { var value = Boyfriend.GuildConfiguration.GetValue($"GuildConfigs:{guild.ID}:{key}"); return value is not null ? Result.FromSuccess(value.Value) : Result.FromError(new NotFoundError()); } public static Result GetChannel(this IGuildCreate.IAvailableGuild guild, string key) { var value = Boyfriend.GuildConfiguration.GetValue($"GuildConfigs:{guild.ID}:{key}"); if (value is null) return Result.FromError(new NotFoundError()); var match = guild.Channels.SingleOrDefault(channel => channel!.ID.Equals(value.Value), null); return match is not null ? Result.FromSuccess(match) : Result.FromError(new NotFoundError()); } public static CultureInfo GetCulture(this IGuild guild) { var value = Boyfriend.GuildConfiguration.GetValue($"GuildConfigs:{guild.ID}:Language"); return value is not null ? CultureInfoCache[value] : CultureInfoCache["en"]; } }