Skip to content

Commit

Permalink
feat!: decomplex emit type for rolesUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
zaida04 committed Mar 1, 2023
1 parent fecf36c commit ad416a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-boats-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"guilded.js": minor
---

feat!: decomplex rolesUpdate event types
13 changes: 6 additions & 7 deletions packages/guilded.js/lib/gateway/handler/ServerEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import { buildMemberKey } from "../../util";

export class ServerEventHandler extends GatewayEventHandler {
serverRolesUpdated(data: WSServerRolesUpdatedPayload): boolean {
const newMembers = [];
const oldMembers = [];
// update members cache
for (const m of data.d.memberRoleIds) {
const member = this.client.members.cache.get(buildMemberKey(data.d.serverId, m.userId));
if (!member) {
newMembers.push({ ...m, serverId: data.d.serverId });
continue;
if (member) {
oldMembers.push(member._clone());
member._update({ roleIds: m.roleIds });
}
oldMembers.push(member._clone());
newMembers.push(member._update({ roleIds: m.roleIds }));
}
return this.client.emit(constants.clientEvents.ROLES_UPATED, newMembers, oldMembers);

return this.client.emit(constants.clientEvents.ROLES_UPATED, { serverId: data.d.serverId, members: data.d.memberRoleIds }, oldMembers);
}
}
2 changes: 1 addition & 1 deletion packages/guilded.js/lib/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ export type ClientEvents = {
serverCreated: (server: { serverId: string }) => unknown;
webhookCreated: (webhook: Webhook) => unknown;
webhookUpdated: (webhook: Webhook, oldWebhook: Webhook | null) => unknown;
rolesUpdated: (members: (Member | (ServerMemberRoleIdsPayload & { serverId: string }))[], oldMembers: Member[]) => unknown;
rolesUpdated: (updatedMembers: { serverId: string, members: ServerMemberRoleIdsPayload[] }, oldMembers: Member[]) => unknown;
unknownGatewayEvent: (data: any) => unknown;
};

0 comments on commit ad416a2

Please sign in to comment.