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:
parent
2688d5f5e7
commit
c689a3a394
2 changed files with 14 additions and 9 deletions
|
@ -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]) { }
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue