mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-13 01:00:12 +00:00
refactor: move guildMember caching to IDiscordCache
This commit is contained in:
parent
99b81085ed
commit
24ac0725af
4 changed files with 32 additions and 16 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Myriad.Gateway;
|
||||
|
|
@ -51,6 +52,20 @@ namespace Myriad.Cache
|
|||
return default;
|
||||
}
|
||||
|
||||
public static ValueTask TryUpdateSelfMember(this IDiscordCache cache, Shard shard, IGatewayEvent evt)
|
||||
{
|
||||
if (evt is GuildCreateEvent gc)
|
||||
return cache.SaveSelfMember(gc.Id, gc.Members.FirstOrDefault(m => m.User.Id == shard.User?.Id)!);
|
||||
if (evt is MessageCreateEvent mc && mc.Member != null && mc.Author.Id == shard.User?.Id)
|
||||
return cache.SaveSelfMember(mc.GuildId!.Value, mc.Member);
|
||||
if (evt is GuildMemberAddEvent gma && gma.User.Id == shard.User?.Id)
|
||||
return cache.SaveSelfMember(gma.GuildId, gma);
|
||||
if (evt is GuildMemberUpdateEvent gmu && gmu.User.Id == shard.User?.Id)
|
||||
return cache.SaveSelfMember(gmu.GuildId, gmu);
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
private static async ValueTask SaveGuildCreate(this IDiscordCache cache, GuildCreateEvent guildCreate)
|
||||
{
|
||||
await cache.SaveGuild(guildCreate);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue