Skip to content

Commit

Permalink
handle GUILD_MEMBERS_CHUNK
Browse files Browse the repository at this point in the history
  • Loading branch information
apacheli committed Jul 3, 2024
1 parent 4f398bd commit 021f0aa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions core/cache/cache_client.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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";
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";

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whirlybird",
"version": "0.0.2",
"version": "0.0.3",
"main": "core/lib.js",
"files": [
"core"
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 021f0aa

Please sign in to comment.