1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-19 16:33:36 +03:00

split directory migration and language removal migration

This commit is contained in:
Octol1ttle 2024-04-02 00:09:47 +05:00
parent 2688d5f5e7
commit c689a3a394
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
2 changed files with 14 additions and 9 deletions

View file

@ -11,8 +11,7 @@ public sealed class LanguageOption : Option<CultureInfo>
private static readonly Dictionary<string, CultureInfo> CultureInfoCache = new()
{
{ "en", new CultureInfo("en-US") },
{ "ru", new CultureInfo("ru-RU") },
{ "mctaylors-ru", new CultureInfo("tt-RU") }
{ "ru", new CultureInfo("ru-RU") }
};
public LanguageOption(string name, string defaultValue) : base(name, CultureInfoCache[defaultValue]) { }

View file

@ -78,7 +78,7 @@ public sealed class GuildDataService : BackgroundService
var settingsPath = $"{path}/Settings.json";
var scheduledEventsPath = $"{path}/ScheduledEvents.json";
await MigrateGuildData(guildId, path, ct);
MigrateDataDirectory(guildId, path);
Directory.CreateDirectory(path);
@ -106,6 +106,11 @@ public sealed class GuildDataService : BackgroundService
dataLoadFailed = true;
}
if (jsonSettings is not null)
{
FixJsonSettings(jsonSettings);
}
await using var eventsStream = File.OpenRead(scheduledEventsPath);
Dictionary<ulong, ScheduledEventData>? events = null;
try
@ -155,7 +160,7 @@ public sealed class GuildDataService : BackgroundService
return finalData;
}
private async Task MigrateGuildData(Snowflake guildId, string newPath, CancellationToken ct)
private void MigrateDataDirectory(Snowflake guildId, string newPath)
{
var oldPath = $"{guildId}";
@ -167,13 +172,14 @@ public sealed class GuildDataService : BackgroundService
_logger.LogInformation("Moved guild data to separate folder: \"{OldPath}\" -> \"{NewPath}\"", oldPath,
newPath);
}
}
var settings = (await GetData(guildId, ct)).Settings;
if (GuildSettings.Language.Get(settings).Name is "tt-RU")
private static void FixJsonSettings(JsonNode settings)
{
GuildSettings.Language.Set(settings, "ru");
_logger.LogInformation("Switched from unsupported language in \"{GuildID}\": mctaylors-ru -> ru", guildId.Value);
var language = settings[GuildSettings.Language.Name]?.GetValue<string>();
if (language is "mctaylors-ru")
{
settings[GuildSettings.Language.Name] = "ru";
}
}