From 81099fad4c1c3653e2c84af6df9684480038aa88 Mon Sep 17 00:00:00 2001 From: Macintosh II <95250141+mctaylors@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:33:14 +0300 Subject: [PATCH] Move all GuildData to one folder (#110) Signed-off-by: Macintosh II Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com> Co-authored-by: Octol1ttle --- src/Services/GuildDataService.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Services/GuildDataService.cs b/src/Services/GuildDataService.cs index 296377a..e3c0b96 100644 --- a/src/Services/GuildDataService.cs +++ b/src/Services/GuildDataService.cs @@ -73,11 +73,14 @@ public sealed class GuildDataService : IHostedService private async Task 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 GetSettings(Snowflake guildId, CancellationToken ct = default) { return (await GetData(guildId, ct)).Settings;