mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-05 13:36:30 +03:00
Backfill member data when a guild is loaded or a new member joins it (#77)
This PR backfills member data when a guild is loaded or a new member joins it. The reason for that is some actions that happen on member tick (default role grant, nickname filtering) would only occur if a member had data related to them (due to being banned or setting a reminder). In addition, the `.editorconfig` was updated with new inspections provided by a new release of Rider, 2023.2 See explanations for some changes in comments. --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
d023033ed4
commit
e9f7825e4a
10 changed files with 61 additions and 35 deletions
|
@ -71,15 +71,7 @@ public sealed class GuildDataService : IHostedService
|
|||
var memberDataPath = $"{guildId}/MemberData";
|
||||
var settingsPath = $"{guildId}/Settings.json";
|
||||
var scheduledEventsPath = $"{guildId}/ScheduledEvents.json";
|
||||
if (!Directory.Exists(idString))
|
||||
{
|
||||
Directory.CreateDirectory(idString);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(memberDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(memberDataPath);
|
||||
}
|
||||
Directory.CreateDirectory(idString);
|
||||
|
||||
if (!File.Exists(settingsPath))
|
||||
{
|
||||
|
@ -101,9 +93,9 @@ public sealed class GuildDataService : IHostedService
|
|||
eventsStream, cancellationToken: ct);
|
||||
|
||||
var memberData = new Dictionary<ulong, MemberData>();
|
||||
foreach (var dataPath in Directory.GetFiles(memberDataPath))
|
||||
foreach (var dataFileInfo in Directory.CreateDirectory(memberDataPath).GetFiles())
|
||||
{
|
||||
await using var dataStream = File.OpenRead(dataPath);
|
||||
await using var dataStream = dataFileInfo.OpenRead();
|
||||
var data = await JsonSerializer.DeserializeAsync<MemberData>(dataStream, cancellationToken: ct);
|
||||
if (data is null)
|
||||
{
|
||||
|
@ -123,10 +115,8 @@ public sealed class GuildDataService : IHostedService
|
|||
jsonSettings ?? new JsonObject(), settingsPath,
|
||||
await events ?? new Dictionary<ulong, ScheduledEventData>(), scheduledEventsPath,
|
||||
memberData, memberDataPath);
|
||||
while (!_datas.ContainsKey(guildId))
|
||||
{
|
||||
_datas.TryAdd(guildId, finalData);
|
||||
}
|
||||
|
||||
_datas.TryAdd(guildId, finalData);
|
||||
|
||||
return finalData;
|
||||
}
|
||||
|
@ -138,7 +128,7 @@ public sealed class GuildDataService : IHostedService
|
|||
|
||||
public async Task<MemberData> GetMemberData(Snowflake guildId, Snowflake userId, CancellationToken ct = default)
|
||||
{
|
||||
return (await GetData(guildId, ct)).GetMemberData(userId);
|
||||
return (await GetData(guildId, ct)).GetOrCreateMemberData(userId);
|
||||
}
|
||||
|
||||
public ICollection<Snowflake> GetGuildIds()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue