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