From 021f0aab438e5849ab937b98441ced462645ef60 Mon Sep 17 00:00:00 2001 From: apacheli Date: Wed, 3 Jul 2024 14:36:40 -0500 Subject: [PATCH] handle GUILD_MEMBERS_CHUNK --- core/cache/cache_client.js | 22 +++++++++++++++++++--- package.json | 2 +- readme.md | 3 ++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/cache/cache_client.js b/core/cache/cache_client.js index 58b7613..7b65b34 100644 --- a/core/cache/cache_client.js +++ b/core/cache/cache_client.js @@ -1,5 +1,5 @@ import { createChannel, updateChannel } from "./channel.js"; -import { createEmoji, updateEmoji } from "./emoji.js"; +import { createEmoji } from "./emoji.js"; import { createGuild, updateGuild } from "./guild.js"; import { createMember, updateMember } from "./member.js"; import { createMessage, updateMessage } from "./message.js"; @@ -7,7 +7,7 @@ import { createPresence, updatePresence } from "./presence.js"; import { createRole, updateRole } from "./role.js"; import { createScheduledEvent, updateScheduledEvent } from "./scheduled_event.js"; import { createStage, updateStage } from "./stage.js"; -import { createSticker, updateSticker } from "./sticker.js"; +import { createSticker } from "./sticker.js"; import { createUser, updateUser } from "./user.js"; import { createVoice, updateVoice } from "./voice.js"; @@ -209,6 +209,22 @@ export class CacheClient { } case "GUILD_MEMBERS_CHUNK": { + if (!this.options?.types?.MEMBER) { + return; + } + const members = this.guilds.get(BigInt(data.guild_id)).members; + for (let i = 0, j = data.members.length; i < j; i++) { + const member = data.members[i]; + const userId = BigInt(member.user.id); + if (this.users.has(userId) === false) { + this.users.set(userId, createUser(userId, member.user)); + } + members.set(userId, createMember(userId, member)); + } + for (let i = 0, j = data.presences.length; i < j; i++) { + const presence = data.presences[i]; + this.users.get(BigInt(presence.user.id)).presence = createPresence(presence); + } break; } @@ -262,7 +278,7 @@ export class CacheClient { const userId = BigInt(data.user.id); let user = this.users.get(userId); if (user === undefined) { - if (data.user.username === undefined) { + if (!this.options?.types?.USER || data.user.username === undefined) { break; } user = createUser(userId, data.user); diff --git a/package.json b/package.json index f8d0a37..dec8218 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whirlybird", - "version": "0.0.2", + "version": "0.0.3", "main": "core/lib.js", "files": [ "core" diff --git a/readme.md b/readme.md index e379d4a..f818709 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,8 @@ A JavaScript library for making Discord bots. ## Core -- [`whirlybird/gcache`](core/cache) +- [`whirlybird/bot`](core/bot) +- [`whirlybird/cache`](core/cache) - [`whirlybird/gateway`](core/gateway) - [`whirlybird/interactions`](core/interactions) - [`whirlybird/rest`](core/rest)