From 214830a5f0807b8695cbb8825e2206b9725dbd87 Mon Sep 17 00:00:00 2001 From: pakkographic <41129374+pakkographic@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:05:35 +0200 Subject: [PATCH] fix(typings): channel permission events --- lib/gateway/events/ChannelHandler.ts | 147 ++++++++++++++++++++++----- lib/types/channels.d.ts | 16 ++- lib/types/events.d.ts | 6 +- 3 files changed, 138 insertions(+), 31 deletions(-) diff --git a/lib/gateway/events/ChannelHandler.ts b/lib/gateway/events/ChannelHandler.ts index ffcffe9..17db6b7 100644 --- a/lib/gateway/events/ChannelHandler.ts +++ b/lib/gateway/events/ChannelHandler.ts @@ -20,6 +20,7 @@ import type { GatewayEvent_ServerChannelUpdated } from "../../Constants"; import type { AnyChannel } from "../../types"; +import { Permissions } from "guildedapi-types.ts/v1"; /** Internal component, emitting channel events. */ export class ChannelHandler extends GatewayEventHandler{ @@ -40,29 +41,77 @@ export class ChannelHandler extends GatewayEventHandler{ this.client.emit("channelArchive", ChannelComponent); } async channelCategoryRolePermissionCreated(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise { - const ChannelComponent = data.channelCategoryRolePermission; - this.client.emit("channelCategoryRolePermissionCreated", ChannelComponent); + this.client.emit( + "channelCategoryRolePermissionCreated", + { + permission: (data.channelCategoryRolePermission.permissions as never as Array), + createdAt: data.channelCategoryRolePermission.createdAt, + updatedAt: data.channelCategoryRolePermission.updatedAt, + roleID: data.channelCategoryRolePermission.roleId, + categoryID: data.channelCategoryRolePermission.categoryId, + guildID: data.serverId + }); } async channelCategoryRolePermissionDeleted(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise { - const ChannelComponent = data.channelCategoryRolePermission; - this.client.emit("channelCategoryRolePermissionDeleted", ChannelComponent); + this.client.emit( + "channelCategoryRolePermissionDeleted", + { + permission: (data.channelCategoryRolePermission.permissions as never as Array), + createdAt: data.channelCategoryRolePermission.createdAt, + updatedAt: data.channelCategoryRolePermission.updatedAt, + roleID: data.channelCategoryRolePermission.roleId, + categoryID: data.channelCategoryRolePermission.categoryId, + guildID: data.serverId + }); } async channelCategoryRolePermissionUpdated(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise { - const ChannelComponent = data.channelCategoryRolePermission; - this.client.emit("channelCategoryRolePermissionUpdated", ChannelComponent); + this.client.emit( + "channelCategoryRolePermissionUpdated", + { + permission: (data.channelCategoryRolePermission.permissions as never as Array), + createdAt: data.channelCategoryRolePermission.createdAt, + updatedAt: data.channelCategoryRolePermission.updatedAt, + roleID: data.channelCategoryRolePermission.roleId, + categoryID: data.channelCategoryRolePermission.categoryId, + guildID: data.serverId + }); } async channelCategoryUserPermissionCreated(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise { - const ChannelComponent = data.channelCategoryUserPermission; - this.client.emit("channelCategoryUserPermissionCreated", ChannelComponent); + this.client.emit( + "channelCategoryUserPermissionCreated", + { + permission: (data.channelCategoryUserPermission.permissions as never as Array), + createdAt: data.channelCategoryUserPermission.createdAt, + updatedAt: data.channelCategoryUserPermission.updatedAt, + categoryID: data.channelCategoryUserPermission.categoryId, + userID: data.channelCategoryUserPermission.userId, + guildID: data.serverId + }); } async channelCategoryUserPermissionDeleted(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise { - const ChannelComponent = data.channelCategoryUserPermission; - this.client.emit("channelCategoryUserPermissionDeleted", ChannelComponent); + this.client.emit( + "channelCategoryUserPermissionDeleted", + { + permission: (data.channelCategoryUserPermission.permissions as never as Array), + createdAt: data.channelCategoryUserPermission.createdAt, + updatedAt: data.channelCategoryUserPermission.updatedAt, + categoryID: data.channelCategoryUserPermission.categoryId, + userID: data.channelCategoryUserPermission.userId, + guildID: data.serverId + }); } async channelCategoryUserPermissionUpdated(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise { - const ChannelComponent = data.channelCategoryUserPermission; - this.client.emit("channelCategoryUserPermissionUpdated", ChannelComponent); + this.client.emit( + "channelCategoryUserPermissionUpdated", + { + permission: (data.channelCategoryUserPermission.permissions as never as Array), + createdAt: data.channelCategoryUserPermission.createdAt, + updatedAt: data.channelCategoryUserPermission.updatedAt, + categoryID: data.channelCategoryUserPermission.categoryId, + userID: data.channelCategoryUserPermission.userId, + guildID: data.serverId + }); } async channelCreate(data: GatewayEvent_ServerChannelCreated): Promise { if (this.client.params.waitForCaching) @@ -84,16 +133,42 @@ export class ChannelHandler extends GatewayEventHandler{ this.client.emit("channelRestore", ChannelComponent); } async channelRolePermissionCreated(data: GatewayEvent_ChannelRolePermissionCreated): Promise { - const ChannelComponent = data.channelRolePermission; - this.client.emit("channelRolePermissionCreated", ChannelComponent); + this.client.emit( + "channelRolePermissionCreated", + { + permission: (data.channelRolePermission.permissions as never as Array), + createdAt: data.channelRolePermission.createdAt, + updatedAt: data.channelRolePermission.updatedAt, + roleID: data.channelRolePermission.roleId, + channelID: data.channelRolePermission.channelId, + guildID: data.serverId + } + ); } async channelRolePermissionDeleted(data: GatewayEvent_ChannelRolePermissionCreated): Promise { - const ChannelComponent = data.channelRolePermission; - this.client.emit("channelRolePermissionDeleted", ChannelComponent); + this.client.emit( + "channelRolePermissionDeleted", + { + permission: (data.channelRolePermission.permissions as never as Array), + createdAt: data.channelRolePermission.createdAt, + updatedAt: data.channelRolePermission.updatedAt, + roleID: data.channelRolePermission.roleId, + channelID: data.channelRolePermission.channelId, + guildID: data.serverId + }); } async channelRolePermissionUpdated(data: GatewayEvent_ChannelRolePermissionCreated): Promise { - const ChannelComponent = data.channelRolePermission; - this.client.emit("channelRolePermissionUpdated", ChannelComponent); + const channelRolePermission = data.channelRolePermission; + this.client.emit( + "channelRolePermissionUpdated", + { + permission: (data.channelRolePermission.permissions as never as Array), + createdAt: data.channelRolePermission.createdAt, + updatedAt: data.channelRolePermission.updatedAt, + roleID: data.channelRolePermission.roleId, + channelID: data.channelRolePermission.channelId, + guildID: data.serverId + }); } async channelUpdate(data: GatewayEvent_ServerChannelUpdated): Promise { if (this.client.params.waitForCaching) @@ -108,16 +183,40 @@ export class ChannelHandler extends GatewayEventHandler{ async channelUserPermissionCreated(data: GatewayEvent_ChannelUserPermissionCreated): Promise { - const ChannelComponent = data.channelUserPermission; - this.client.emit("channelUserPermissionCreated", ChannelComponent); + this.client.emit( + "channelUserPermissionCreated", + { + channelID: data.channelUserPermission.channelId, + createdAt: data.channelUserPermission.createdAt, + updatedAt: data.channelUserPermission.updatedAt, + userID: data.channelUserPermission.userId, + guildID: data.serverId, + permission: data.channelUserPermission as never as Array + }); } async channelUserPermissionDeleted(data: GatewayEvent_ChannelUserPermissionDeleted): Promise { - const ChannelComponent = data.channelUserPermission; - this.client.emit("channelUserPermissionDeleted", ChannelComponent); + this.client.emit( + "channelUserPermissionDeleted", + { + channelID: data.channelUserPermission.channelId, + createdAt: data.channelUserPermission.createdAt, + updatedAt: data.channelUserPermission.updatedAt, + userID: data.channelUserPermission.userId, + guildID: data.serverId, + permission: data.channelUserPermission as never as Array + }); } async channelUserPermissionUpdated(data: GatewayEvent_ChannelUserPermissionUpdated): Promise { - const ChannelComponent = data.channelUserPermission; - this.client.emit("channelUserPermissionUpdated", ChannelComponent); + this.client.emit( + "channelUserPermissionUpdated", + { + channelID: data.channelUserPermission.channelId, + createdAt: data.channelUserPermission.createdAt, + updatedAt: data.channelUserPermission.updatedAt, + userID: data.channelUserPermission.userId, + guildID: data.serverId, + permission: data.channelUserPermission as never as Array + }); } } diff --git a/lib/types/channels.d.ts b/lib/types/channels.d.ts index 6a372fe..bdf5957 100644 --- a/lib/types/channels.d.ts +++ b/lib/types/channels.d.ts @@ -234,6 +234,8 @@ export interface ChannelRolePermission { roleID: number; /** The ID of the channel */ channelID: string; + /** ID of the Guild **/ + guildID: string; } export interface ChannelUserPermission { @@ -243,9 +245,11 @@ export interface ChannelUserPermission { /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ updatedAt?: string; /** The ID of the role */ - userID: number; + userID: string; /** The ID of the channel */ channelID: string; + /** ID of the Guild **/ + guildID: string; } export interface ChannelCategoryUserPermission { @@ -255,9 +259,11 @@ export interface ChannelCategoryUserPermission { /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ updatedAt?: string; /** The ID of the role */ - userID: number; + userID: string; /** The ID of the channel */ - categoryID: string; + categoryID: number; + /** ID of the Guild **/ + guildID: string; } export interface ChannelCategoryRolePermission { @@ -269,7 +275,9 @@ export interface ChannelCategoryRolePermission { /** The ID of the role */ roleID: number; /** The ID of the channel */ - categoryID: string; + categoryID: number; + /** ID of the Guild **/ + guildID: string; } export type AnyTextableChannel = TextChannel; diff --git a/lib/types/events.d.ts b/lib/types/events.d.ts index 1521f8a..6b145b9 100644 --- a/lib/types/events.d.ts +++ b/lib/types/events.d.ts @@ -122,11 +122,11 @@ export interface ClientEvents { /** @event Emitted when a channel user permission is deleted. */ channelUserPermissionDeleted: [channelUserPermission: ChannelUserPermission]; /** @event Emitted when a channel category role permission is created. */ - channelCategoryRolePermissionCreated: [channelCategoryUserPermission: ChannelCategoryRolePermission]; + channelCategoryRolePermissionCreated: [channelCategoryRolePermission: ChannelCategoryRolePermission]; /** @event Emitted when a channel category role permission is updated. */ - channelCategoryRolePermissionUpdated: [channelCategoryUserPermission: ChannelCategoryRolePermission]; + channelCategoryRolePermissionUpdated: [channelCategoryRolePermission: ChannelCategoryRolePermission]; /** @event Emitted when a channel category role permission is deleted. */ - channelCategoryRolePermissionDeleted: [channelCategoryUserPermission: ChannelCategoryRolePermission]; + channelCategoryRolePermissionDeleted: [channelCategoryRolePermission: ChannelCategoryRolePermission]; /** @event Emitted when a channel category user permission is created. */ channelCategoryUserPermissionCreated: [channelCategoryUserPermission: ChannelCategoryUserPermission]; /** @event Emitted when a channel category user permission is updated. */