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:
parent
1e8b7e5373
commit
81099fad4c
1 changed files with 21 additions and 5 deletions
|
@ -73,11 +73,14 @@ public sealed class GuildDataService : IHostedService
|
||||||
|
|
||||||
private async Task<GuildData> InitializeData(Snowflake guildId, CancellationToken ct = default)
|
private async Task<GuildData> InitializeData(Snowflake guildId, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var idString = $"{guildId}";
|
var path = $"GuildData/{guildId}";
|
||||||
var memberDataPath = $"{guildId}/MemberData";
|
var memberDataPath = $"{path}/MemberData";
|
||||||
var settingsPath = $"{guildId}/Settings.json";
|
var settingsPath = $"{path}/Settings.json";
|
||||||
var scheduledEventsPath = $"{guildId}/ScheduledEvents.json";
|
var scheduledEventsPath = $"{path}/ScheduledEvents.json";
|
||||||
Directory.CreateDirectory(idString);
|
|
||||||
|
MigrateGuildData(guildId, path);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
if (!File.Exists(settingsPath))
|
if (!File.Exists(settingsPath))
|
||||||
{
|
{
|
||||||
|
@ -127,6 +130,19 @@ public sealed class GuildDataService : IHostedService
|
||||||
return finalData;
|
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)
|
public async Task<JsonNode> GetSettings(Snowflake guildId, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
return (await GetData(guildId, ct)).Settings;
|
return (await GetData(guildId, ct)).Settings;
|
||||||
|
|
Loading…
Reference in a new issue