1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

Move all GuildData to one folder (#110)

Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Macintxsh 2023-09-22 15:33:14 +03:00 committed by GitHub
parent 1e8b7e5373
commit 81099fad4c
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23

View file

@ -73,11 +73,14 @@ public sealed class GuildDataService : IHostedService
private async Task<GuildData> InitializeData(Snowflake guildId, CancellationToken ct = default)
{
var idString = $"{guildId}";
var memberDataPath = $"{guildId}/MemberData";
var settingsPath = $"{guildId}/Settings.json";
var scheduledEventsPath = $"{guildId}/ScheduledEvents.json";
Directory.CreateDirectory(idString);
var path = $"GuildData/{guildId}";
var memberDataPath = $"{path}/MemberData";
var settingsPath = $"{path}/Settings.json";
var scheduledEventsPath = $"{path}/ScheduledEvents.json";
MigrateGuildData(guildId, path);
Directory.CreateDirectory(path);
if (!File.Exists(settingsPath))
{
@ -127,6 +130,19 @@ public sealed class GuildDataService : IHostedService
return finalData;
}
private void MigrateGuildData(Snowflake guildId, string newPath)
{
var oldPath = $"{guildId}";
if (Directory.Exists(oldPath))
{
Directory.CreateDirectory($"{newPath}/..");
Directory.Move(oldPath, newPath);
_logger.LogInformation("Moved guild data to separate folder: \"{OldPath}\" -> \"{NewPath}\"", oldPath, newPath);
}
}
public async Task<JsonNode> GetSettings(Snowflake guildId, CancellationToken ct = default)
{
return (await GetData(guildId, ct)).Settings;