mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
fix: update guild cache on GUILD_UPDATE event
This commit is contained in:
parent
8a9148cd32
commit
47e501da81
1 changed files with 13 additions and 5 deletions
|
|
@ -15,7 +15,18 @@ public class MemoryDiscordCache: IDiscordCache
|
|||
|
||||
public ValueTask SaveGuild(Guild guild)
|
||||
{
|
||||
SaveGuildRaw(guild);
|
||||
if (!_guilds.ContainsKey(guild.Id))
|
||||
{
|
||||
_guilds[guild.Id] = new CachedGuild(guild);
|
||||
}
|
||||
else
|
||||
{
|
||||
var channels = _guilds[guild.Id].Channels;
|
||||
_guilds[guild.Id] = new CachedGuild(guild)
|
||||
{
|
||||
Channels = channels,
|
||||
};
|
||||
}
|
||||
|
||||
foreach (var role in guild.Roles)
|
||||
// Don't call SaveRole because that updates guild state
|
||||
|
|
@ -169,11 +180,8 @@ public class MemoryDiscordCache: IDiscordCache
|
|||
return Task.FromResult(guild.Channels.Keys.Select(c => _channels[c]));
|
||||
}
|
||||
|
||||
private CachedGuild SaveGuildRaw(Guild guild) =>
|
||||
_guilds.GetOrAdd(guild.Id, (_, g) => new CachedGuild(g), guild);
|
||||
|
||||
private record CachedGuild(Guild Guild)
|
||||
{
|
||||
public readonly ConcurrentDictionary<ulong, bool> Channels = new();
|
||||
public ConcurrentDictionary<ulong, bool> Channels { get; init; } = new();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue