mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
nadekobot almost builds
This commit is contained in:
@@ -11,7 +11,10 @@ public class Localization : ILocalization, INService
|
||||
JsonConvert.DeserializeObject<Dictionary<string, CommandData>>(
|
||||
File.ReadAllText("./data/strings/commands/commands.en-US.json"));
|
||||
|
||||
public ConcurrentDictionary<ulong, CultureInfo> GuildCultureInfos { get; }
|
||||
private readonly ConcurrentDictionary<ulong, CultureInfo> _guildCultureInfos;
|
||||
|
||||
public IDictionary<ulong, CultureInfo> GuildCultureInfos
|
||||
=> _guildCultureInfos;
|
||||
|
||||
public CultureInfo DefaultCultureInfo
|
||||
=> _bss.Data.DefaultLocale;
|
||||
@@ -26,21 +29,22 @@ public class Localization : ILocalization, INService
|
||||
|
||||
var cultureInfoNames = bot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.Locale);
|
||||
|
||||
GuildCultureInfos = new(cultureInfoNames.ToDictionary(x => x.Key,
|
||||
x =>
|
||||
{
|
||||
CultureInfo cultureInfo = null;
|
||||
try
|
||||
{
|
||||
if (x.Value is null)
|
||||
return null;
|
||||
cultureInfo = new(x.Value);
|
||||
}
|
||||
catch { }
|
||||
_guildCultureInfos = new(cultureInfoNames
|
||||
.ToDictionary(x => x.Key,
|
||||
x =>
|
||||
{
|
||||
CultureInfo cultureInfo = null;
|
||||
try
|
||||
{
|
||||
if (x.Value is null)
|
||||
return null;
|
||||
cultureInfo = new(x.Value);
|
||||
}
|
||||
catch { }
|
||||
|
||||
return cultureInfo;
|
||||
})
|
||||
.Where(x => x.Value is not null));
|
||||
return cultureInfo;
|
||||
})
|
||||
.Where(x => x.Value is not null));
|
||||
}
|
||||
|
||||
public void SetGuildCulture(IGuild guild, CultureInfo ci)
|
||||
@@ -61,7 +65,7 @@ public class Localization : ILocalization, INService
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
GuildCultureInfos.AddOrUpdate(guildId, ci, (_, _) => ci);
|
||||
_guildCultureInfos.AddOrUpdate(guildId, ci, (_, _) => ci);
|
||||
}
|
||||
|
||||
public void RemoveGuildCulture(IGuild guild)
|
||||
@@ -69,7 +73,7 @@ public class Localization : ILocalization, INService
|
||||
|
||||
public void RemoveGuildCulture(ulong guildId)
|
||||
{
|
||||
if (GuildCultureInfos.TryRemove(guildId, out _))
|
||||
if (_guildCultureInfos.TryRemove(guildId, out _))
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
var gc = uow.GuildConfigsForId(guildId, set => set);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#nullable disable
|
||||
using System.Globalization;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace NadekoBot.Services;
|
||||
|
||||
@@ -80,7 +79,7 @@ public class BotStrings : IBotStrings
|
||||
Log.Warning("'{CommandName}' doesn't exist in 'en-US' command strings. Please report this",
|
||||
commandName);
|
||||
|
||||
return new()
|
||||
return new CommandStrings()
|
||||
{
|
||||
Args = new[] { "" },
|
||||
Desc = "?"
|
||||
@@ -99,15 +98,4 @@ public class BotStrings : IBotStrings
|
||||
|
||||
public void Reload()
|
||||
=> _stringsProvider.Reload();
|
||||
}
|
||||
|
||||
|
||||
public sealed class CommandStrings
|
||||
: ICommandStrings
|
||||
{
|
||||
[YamlMember(Alias = "desc")]
|
||||
public string Desc { get; set; }
|
||||
|
||||
[YamlMember(Alias = "args")]
|
||||
public string[] Args { get; set; }
|
||||
}
|
@@ -40,11 +40,11 @@ public class LocalFileStringsSource : IStringsSource
|
||||
return outputDict;
|
||||
}
|
||||
|
||||
public Dictionary<string, Dictionary<string, ICommandStrings>> GetCommandStrings()
|
||||
public Dictionary<string, Dictionary<string, CommandStrings>> GetCommandStrings()
|
||||
{
|
||||
var deserializer = new DeserializerBuilder().Build();
|
||||
|
||||
var outputDict = new Dictionary<string, Dictionary<string, CommandStrings>>().;
|
||||
var outputDict = new Dictionary<string, Dictionary<string, CommandStrings>>();
|
||||
foreach (var file in Directory.GetFiles(_commandsPath))
|
||||
{
|
||||
try
|
||||
|
@@ -27,7 +27,7 @@ public class MemoryBotStringsProvider : IBotStringsProvider
|
||||
commandStrings = _source.GetCommandStrings();
|
||||
}
|
||||
|
||||
public ICommandStrings GetCommandStrings(string localeName, string commandName)
|
||||
public CommandStrings GetCommandStrings(string localeName, string commandName)
|
||||
{
|
||||
if (commandStrings.TryGetValue(localeName, out var langStrings)
|
||||
&& langStrings.TryGetValue(commandName, out var strings))
|
||||
|
Reference in New Issue
Block a user