From 01708e38c04846e60b8ca5306d3d9a7c4fa78b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= <41128238+raphckrman@users.noreply.github.com> Date: Fri, 29 Sep 2023 18:21:30 +0200 Subject: [PATCH 1/3] Channel user/role permission overrides and hide link previews! --- lib/gateway/GatewayHandler.ts | 199 +++++++----- lib/gateway/events/ChannelHandler.ts | 84 ++++- lib/gateway/events/GuildHandler.ts | 21 +- lib/gateway/events/MessageHandler.ts | 17 + lib/rest/endpoints.ts | 8 + lib/routes/Channels.ts | 294 +++++++++++++++++- .../ChannelCategoryRolePermission.ts | 65 ++++ .../ChannelCategoryUserPermission.ts | 65 ++++ lib/structures/ChannelRolePermission.ts | 65 ++++ lib/structures/ChannelUserPermission.ts | 65 ++++ lib/structures/GuildCategory.ts | 86 ++++- lib/structures/Message.ts | 32 +- lib/structures/TextChannel.ts | 83 ++++- lib/types/channel.d.ts | 52 ++++ lib/types/events.d.ts | 39 +++ lib/types/json.d.ts | 55 +++- 16 files changed, 1126 insertions(+), 104 deletions(-) create mode 100644 lib/structures/ChannelCategoryRolePermission.ts create mode 100644 lib/structures/ChannelCategoryUserPermission.ts create mode 100644 lib/structures/ChannelRolePermission.ts create mode 100644 lib/structures/ChannelUserPermission.ts diff --git a/lib/gateway/GatewayHandler.ts b/lib/gateway/GatewayHandler.ts index d688e208..0c8c567e 100644 --- a/lib/gateway/GatewayHandler.ts +++ b/lib/gateway/GatewayHandler.ts @@ -94,7 +94,20 @@ import type { GatewayEvent_UserStatusDeleted, GatewayEvent_RoleCreated, GatewayEvent_RoleUpdated, - GatewayEvent_RoleDeleted + GatewayEvent_RoleDeleted, + GatewayEvent_ChannelMessagePinned, + GatewayEvent_ChannelMessageUnpinned, + GatewayEvent_ChannelRolePermissionCreated, + GatewayEvent_ChannelRolePermissionUpdated, + GatewayEvent_ChannelRolePermissionDeleted, + GatewayEvent_ChannelUserPermissionCreated, + GatewayEvent_CategoryCreated, + GatewayEvent_CategoryDeleted, + GatewayEvent_CategoryUpdated, + GatewayEvent_ChannelRestored, + GatewayEvent_ChannelArchived, + GatewayEvent_ChannelCategoryUserPermissionCreated, + GatewayEvent_ChannelCategoryRolePermissionCreated } from "../Constants"; /** Gateway handler filters every ws events. */ @@ -113,99 +126,119 @@ export class GatewayHandler { readonly toHandlerMap: Record void> = { // Messages - ChatMessageCreated: data => this.messageHandler.messageCreate(data as GatewayEvent_ChatMessageCreated), - ChatMessageUpdated: data => this.messageHandler.messageUpdate(data as GatewayEvent_ChatMessageUpdated), - ChatMessageDeleted: data => this.messageHandler.messageDelete(data as GatewayEvent_ChatMessageDeleted), - ChannelMessageReactionCreated: data => this.messageHandler.messageReactionAdd(data as GatewayEvent_ChannelMessageReactionCreated), - ChannelMessageReactionDeleted: data => this.messageHandler.messageReactionRemove(data as GatewayEvent_ChannelMessageReactionDeleted), - ChannelMessageReactionManyDeleted: data => this.messageHandler.messageReactionBulkRemove(data as GatewayEvent_ChannelMessageReactionManyDeleted), + ChatMessageCreated: data => this.messageHandler.messageCreate(data as GatewayEvent_ChatMessageCreated), + ChatMessageUpdated: data => this.messageHandler.messageUpdate(data as GatewayEvent_ChatMessageUpdated), + ChatMessageDeleted: data => this.messageHandler.messageDelete(data as GatewayEvent_ChatMessageDeleted), + ChannelMessageReactionCreated: data => this.messageHandler.messageReactionAdd(data as GatewayEvent_ChannelMessageReactionCreated), + ChannelMessageReactionDeleted: data => this.messageHandler.messageReactionRemove(data as GatewayEvent_ChannelMessageReactionDeleted), + ChannelMessageReactionManyDeleted: data => this.messageHandler.messageReactionBulkRemove(data as GatewayEvent_ChannelMessageReactionManyDeleted), + ChannelMessagePinned: data => this.messageHandler.messagePin(data as GatewayEvent_ChannelMessagePinned), + ChannelMessageUnpinned: data => this.messageHandler.messageUnpin(data as GatewayEvent_ChannelMessageUnpinned), // Channels - ServerChannelCreated: data => this.channelHandler.channelCreate(data as GatewayEvent_ServerChannelCreated), - ServerChannelUpdated: data => this.channelHandler.channelUpdate(data as GatewayEvent_ServerChannelUpdated), - ServerChannelDeleted: data => this.channelHandler.channelDelete(data as GatewayEvent_ServerChannelDeleted), + ServerChannelCreated: data => this.channelHandler.channelCreate(data as GatewayEvent_ServerChannelCreated), + ServerChannelUpdated: data => this.channelHandler.channelUpdate(data as GatewayEvent_ServerChannelUpdated), + ServerChannelDeleted: data => this.channelHandler.channelDelete(data as GatewayEvent_ServerChannelDeleted), + ChannelRolePermissionCreated: data => this.channelHandler.channelRolePermissionCreated(data as GatewayEvent_ChannelRolePermissionCreated), + ChannelRolePermissionUpdated: data => this.channelHandler.channelRolePermissionUpdated(data as GatewayEvent_ChannelRolePermissionUpdated), + ChannelRolePermissionDeleted: data => this.channelHandler.channelRolePermissionDeleted(data as GatewayEvent_ChannelRolePermissionDeleted), + ChannelUserPermissionCreated: data => this.channelHandler.channelUserPermissionCreated(data as GatewayEvent_ChannelUserPermissionCreated), + ChannelUserPermissionUpdated: data => this.channelHandler.channelUserPermissionUpdated(data as GatewayEvent_ChannelUserPermissionCreated), + ChannelUserPermissionDeleted: data => this.channelHandler.channelUserPermissionDeleted(data as GatewayEvent_ChannelUserPermissionCreated), + ChannelArchived: data => this.channelHandler.channelArchive(data as GatewayEvent_ChannelArchived), + ChannelRestored: data => this.channelHandler.channelRestore(data as GatewayEvent_ChannelRestored), + ChannelCategoryUserPermissionCreated: data => this.channelHandler.channelCategoryUserPermissionCreated(data as GatewayEvent_ChannelCategoryUserPermissionCreated), + ChannelCategoryUserPermissionUpdated: data => this.channelHandler.channelCategoryUserPermissionCreated(data as GatewayEvent_ChannelCategoryUserPermissionCreated), + ChannelCategoryUserPermissionDeleted: data => this.channelHandler.channelCategoryUserPermissionCreated(data as GatewayEvent_ChannelCategoryUserPermissionCreated), + ChannelCategoryRolePermissionCreated: data => this.channelHandler.channelCategoryRolePermissionCreated(data as GatewayEvent_ChannelCategoryRolePermissionCreated), + ChannelCategoryRolePermissionUpdated: data => this.channelHandler.channelCategoryRolePermissionUpdated(data as GatewayEvent_ChannelCategoryRolePermissionCreated), + ChannelCategoryRolePermissionDeleted: data => this.channelHandler.channelCategoryRolePermissionDeleted(data as GatewayEvent_ChannelCategoryRolePermissionCreated), // Forum Topics - ForumTopicCreated: data => this.forumThreadHandler.forumThreadCreate(data as GatewayEvent_ForumTopicCreated), - ForumTopicUpdated: data => this.forumThreadHandler.forumThreadUpdate(data as GatewayEvent_ForumTopicUpdated), - ForumTopicDeleted: data => this.forumThreadHandler.forumThreadDelete(data as GatewayEvent_ForumTopicDeleted), - ForumTopicPinned: data => this.forumThreadHandler.forumThreadPin(data as GatewayEvent_ForumTopicPinned), - ForumTopicUnpinned: data => this.forumThreadHandler.forumThreadUnpin(data as GatewayEvent_ForumTopicUnpinned), - ForumTopicLocked: data => this.forumThreadHandler.forumThreadLock(data as GatewayEvent_ForumTopicLocked), - ForumTopicUnlocked: data => this.forumThreadHandler.forumThreadUnlock(data as GatewayEvent_ForumTopicUnlocked), - ForumTopicReactionCreated: data => this.forumThreadHandler.forumThreadReactionAdd(data as GatewayEvent_ForumTopicReactionCreated), - ForumTopicReactionDeleted: data => this.forumThreadHandler.forumThreadReactionRemove(data as GatewayEvent_ForumTopicReactionDeleted), - ForumTopicCommentCreated: data => this.forumThreadHandler.forumThreadCommentCreate(data as GatewayEvent_ForumTopicCommentCreated), - ForumTopicCommentUpdated: data => this.forumThreadHandler.forumThreadCommentUpdate(data as GatewayEvent_ForumTopicCommentUpdated), - ForumTopicCommentDeleted: data => this.forumThreadHandler.forumThreadCommentDelete(data as GatewayEvent_ForumTopicCommentDeleted), - ForumTopicCommentReactionCreated: data => this.forumThreadHandler.forumThreadCommentReactionAdd(data as GatewayEvent_ForumTopicCommentReactionCreated), - ForumTopicCommentReactionDeleted: data => this.forumThreadHandler.forumThreadCommentReactionRemove(data as GatewayEvent_ForumTopicCommentReactionDeleted), + ForumTopicCreated: data => this.forumThreadHandler.forumThreadCreate(data as GatewayEvent_ForumTopicCreated), + ForumTopicUpdated: data => this.forumThreadHandler.forumThreadUpdate(data as GatewayEvent_ForumTopicUpdated), + ForumTopicDeleted: data => this.forumThreadHandler.forumThreadDelete(data as GatewayEvent_ForumTopicDeleted), + ForumTopicPinned: data => this.forumThreadHandler.forumThreadPin(data as GatewayEvent_ForumTopicPinned), + ForumTopicUnpinned: data => this.forumThreadHandler.forumThreadUnpin(data as GatewayEvent_ForumTopicUnpinned), + ForumTopicLocked: data => this.forumThreadHandler.forumThreadLock(data as GatewayEvent_ForumTopicLocked), + ForumTopicUnlocked: data => this.forumThreadHandler.forumThreadUnlock(data as GatewayEvent_ForumTopicUnlocked), + ForumTopicReactionCreated: data => this.forumThreadHandler.forumThreadReactionAdd(data as GatewayEvent_ForumTopicReactionCreated), + ForumTopicReactionDeleted: data => this.forumThreadHandler.forumThreadReactionRemove(data as GatewayEvent_ForumTopicReactionDeleted), + ForumTopicCommentCreated: data => this.forumThreadHandler.forumThreadCommentCreate(data as GatewayEvent_ForumTopicCommentCreated), + ForumTopicCommentUpdated: data => this.forumThreadHandler.forumThreadCommentUpdate(data as GatewayEvent_ForumTopicCommentUpdated), + ForumTopicCommentDeleted: data => this.forumThreadHandler.forumThreadCommentDelete(data as GatewayEvent_ForumTopicCommentDeleted), + ForumTopicCommentReactionCreated: data => this.forumThreadHandler.forumThreadCommentReactionAdd(data as GatewayEvent_ForumTopicCommentReactionCreated), + ForumTopicCommentReactionDeleted: data => this.forumThreadHandler.forumThreadCommentReactionRemove(data as GatewayEvent_ForumTopicCommentReactionDeleted), // Guilds - ServerMemberBanned: data => this.guildHandler.guildBanAdd(data as GatewayEvent_ServerMemberBanned), - ServerMemberUnbanned: data => this.guildHandler.guildBanRemove(data as GatewayEvent_ServerMemberUnbanned), - ServerMemberJoined: data => this.guildHandler.guildMemberAdd(data as GatewayEvent_ServerMemberJoined), - ServerMemberRemoved: data => this.guildHandler.guildMemberRemove(data as GatewayEvent_ServerMemberRemoved), - ServerMemberUpdated: data => this.guildHandler.guildMemberUpdate(data as GatewayEvent_ServerMemberUpdated), - ServerRolesUpdated: data => this.guildHandler.guildMemberRoleUpdate(data as GatewayEvent_ServerRolesUpdated), - ServerMemberSocialLinkCreated: data => this.guildHandler.guildMemberSocialLinkCreate(data as GatewayEvent_ServerMemberSocialLinkCreated), - ServerMemberSocialLinkUpdated: data => this.guildHandler.guildMemberSocialLinkUpdate(data as GatewayEvent_ServerMemberSocialLinkUpdated), - ServerMemberSocialLinkDeleted: data => this.guildHandler.guildMemberSocialLinkDelete(data as GatewayEvent_ServerMemberSocialLinkDeleted), - BotServerMembershipCreated: data => this.guildHandler.guildCreate(data as GatewayEvent_BotServerMembershipCreated), - BotServerMembershipDeleted: data => this.guildHandler.guildDelete(data as GatewayEvent_BotServerMembershipDeleted), + ServerMemberBanned: data => this.guildHandler.guildBanAdd(data as GatewayEvent_ServerMemberBanned), + ServerMemberUnbanned: data => this.guildHandler.guildBanRemove(data as GatewayEvent_ServerMemberUnbanned), + ServerMemberJoined: data => this.guildHandler.guildMemberAdd(data as GatewayEvent_ServerMemberJoined), + ServerMemberRemoved: data => this.guildHandler.guildMemberRemove(data as GatewayEvent_ServerMemberRemoved), + ServerMemberUpdated: data => this.guildHandler.guildMemberUpdate(data as GatewayEvent_ServerMemberUpdated), + ServerRolesUpdated: data => this.guildHandler.guildMemberRoleUpdate(data as GatewayEvent_ServerRolesUpdated), + ServerMemberSocialLinkCreated: data => this.guildHandler.guildMemberSocialLinkCreate(data as GatewayEvent_ServerMemberSocialLinkCreated), + ServerMemberSocialLinkUpdated: data => this.guildHandler.guildMemberSocialLinkUpdate(data as GatewayEvent_ServerMemberSocialLinkUpdated), + ServerMemberSocialLinkDeleted: data => this.guildHandler.guildMemberSocialLinkDelete(data as GatewayEvent_ServerMemberSocialLinkDeleted), + BotServerMembershipCreated: data => this.guildHandler.guildCreate(data as GatewayEvent_BotServerMembershipCreated), + BotServerMembershipDeleted: data => this.guildHandler.guildDelete(data as GatewayEvent_BotServerMembershipDeleted), // Guild groups - GroupCreated: data => this.guildHandler.guildGroupCreate(data as GatewayEvent_GroupCreated), - GroupUpdated: data => this.guildHandler.guildGroupUpdate(data as GatewayEvent_GroupUpdated), - GroupDeleted: data => this.guildHandler.guildGroupDelete(data as GatewayEvent_GroupDeleted), + GroupCreated: data => this.guildHandler.guildGroupCreate(data as GatewayEvent_GroupCreated), + GroupUpdated: data => this.guildHandler.guildGroupUpdate(data as GatewayEvent_GroupUpdated), + GroupDeleted: data => this.guildHandler.guildGroupDelete(data as GatewayEvent_GroupDeleted), // Guild roles - RoleCreated: data => this.guildHandler.guildRoleCreate(data as GatewayEvent_RoleCreated), - RoleUpdated: data => this.guildHandler.guildRoleUpdate(data as GatewayEvent_RoleUpdated), - RoleDeleted: data => this.guildHandler.guildRoleDelete(data as GatewayEvent_RoleDeleted), + RoleCreated: data => this.guildHandler.guildRoleCreate(data as GatewayEvent_RoleCreated), + RoleUpdated: data => this.guildHandler.guildRoleUpdate(data as GatewayEvent_RoleUpdated), + RoleDeleted: data => this.guildHandler.guildRoleDelete(data as GatewayEvent_RoleDeleted), // Webhooks - ServerWebhookCreated: data => this.webhookHandler.webhooksCreate(data as GatewayEvent_ServerWebhookCreated), - ServerWebhookUpdated: data => this.webhookHandler.webhooksUpdate(data as GatewayEvent_ServerWebhookUpdated), + ServerWebhookCreated: data => this.webhookHandler.webhooksCreate(data as GatewayEvent_ServerWebhookCreated), + ServerWebhookUpdated: data => this.webhookHandler.webhooksUpdate(data as GatewayEvent_ServerWebhookUpdated), // Docs - DocCreated: data => this.docHandler.docCreate(data as GatewayEvent_DocCreated), - DocUpdated: data => this.docHandler.docUpdate(data as GatewayEvent_DocUpdated), - DocDeleted: data => this.docHandler.docDelete(data as GatewayEvent_DocDeleted), - DocReactionCreated: data => this.docHandler.docReactionAdd(data as GatewayEvent_DocReactionCreated), - DocReactionDeleted: data => this.docHandler.docReactionRemove(data as GatewayEvent_DocReactionDeleted), - DocCommentCreated: data => this.docHandler.docCommentCreate(data as GatewayEvent_DocCommentCreated), - DocCommentUpdated: data => this.docHandler.docCommentUpdate(data as GatewayEvent_DocCommentUpdated), - DocCommentDeleted: data => this.docHandler.docCommentDelete(data as GatewayEvent_DocCommentDeleted), - DocCommentReactionCreated: data => this.docHandler.docCommentReactionAdd(data as GatewayEvent_DocCommentReactionCreated), - DocCommentReactionDeleted: data => this.docHandler.docCommentReactionRemove(data as GatewayEvent_DocCommentReactionDeleted), + DocCreated: data => this.docHandler.docCreate(data as GatewayEvent_DocCreated), + DocUpdated: data => this.docHandler.docUpdate(data as GatewayEvent_DocUpdated), + DocDeleted: data => this.docHandler.docDelete(data as GatewayEvent_DocDeleted), + DocReactionCreated: data => this.docHandler.docReactionAdd(data as GatewayEvent_DocReactionCreated), + DocReactionDeleted: data => this.docHandler.docReactionRemove(data as GatewayEvent_DocReactionDeleted), + DocCommentCreated: data => this.docHandler.docCommentCreate(data as GatewayEvent_DocCommentCreated), + DocCommentUpdated: data => this.docHandler.docCommentUpdate(data as GatewayEvent_DocCommentUpdated), + DocCommentDeleted: data => this.docHandler.docCommentDelete(data as GatewayEvent_DocCommentDeleted), + DocCommentReactionCreated: data => this.docHandler.docCommentReactionAdd(data as GatewayEvent_DocCommentReactionCreated), + DocCommentReactionDeleted: data => this.docHandler.docCommentReactionRemove(data as GatewayEvent_DocCommentReactionDeleted), // Calendars - CalendarEventCreated: data => this.calendarHandler.calendarEventCreate(data as GatewayEvent_CalendarEventCreated), - CalendarEventUpdated: data => this.calendarHandler.calendarEventUpdate(data as GatewayEvent_CalendarEventUpdated), - CalendarEventDeleted: data => this.calendarHandler.calendarEventDelete(data as GatewayEvent_CalendarEventDeleted), - CalendarEventReactionCreated: data => this.calendarHandler.calendarEventReactionAdd(data as GatewayEvent_CalendarEventReactionCreated), - CalendarEventReactionDeleted: data => this.calendarHandler.calendarEventReactionRemove(data as GatewayEvent_CalendarEventReactionDeleted), - CalendarEventCommentCreated: data => this.calendarHandler.calendarCommentCreate(data as GatewayEvent_CalendarEventCommentCreated), - CalendarEventCommentUpdated: data => this.calendarHandler.calendarCommentUpdate(data as GatewayEvent_CalendarEventCommentUpdated), - CalendarEventCommentDeleted: data => this.calendarHandler.calendarCommentDelete(data as GatewayEvent_CalendarEventCommentDeleted), - CalendarEventCommentReactionCreated: data => this.calendarHandler.calendarCommentReactionAdd(data as GatewayEvent_CalendarEventCommentReactionCreated), - CalendarEventCommentReactionDeleted: data => this.calendarHandler.calendarCommentReactionRemove(data as GatewayEvent_CalendarEventCommentReactionDeleted), - CalendarEventRsvpUpdated: data => this.calendarHandler.calendarRsvpUpdate(data as GatewayEvent_CalendarEventRsvpUpdated), - CalendarEventRsvpManyUpdated: () => this.calendarHandler.calendarRsvpManyUpdated(), - CalendarEventRsvpDeleted: data => this.calendarHandler.calendarRsvpDelete(data as GatewayEvent_CalendarEventRsvpDeleted), + CalendarEventCreated: data => this.calendarHandler.calendarEventCreate(data as GatewayEvent_CalendarEventCreated), + CalendarEventUpdated: data => this.calendarHandler.calendarEventUpdate(data as GatewayEvent_CalendarEventUpdated), + CalendarEventDeleted: data => this.calendarHandler.calendarEventDelete(data as GatewayEvent_CalendarEventDeleted), + CalendarEventReactionCreated: data => this.calendarHandler.calendarEventReactionAdd(data as GatewayEvent_CalendarEventReactionCreated), + CalendarEventReactionDeleted: data => this.calendarHandler.calendarEventReactionRemove(data as GatewayEvent_CalendarEventReactionDeleted), + CalendarEventCommentCreated: data => this.calendarHandler.calendarCommentCreate(data as GatewayEvent_CalendarEventCommentCreated), + CalendarEventCommentUpdated: data => this.calendarHandler.calendarCommentUpdate(data as GatewayEvent_CalendarEventCommentUpdated), + CalendarEventCommentDeleted: data => this.calendarHandler.calendarCommentDelete(data as GatewayEvent_CalendarEventCommentDeleted), + CalendarEventCommentReactionCreated: data => this.calendarHandler.calendarCommentReactionAdd(data as GatewayEvent_CalendarEventCommentReactionCreated), + CalendarEventCommentReactionDeleted: data => this.calendarHandler.calendarCommentReactionRemove(data as GatewayEvent_CalendarEventCommentReactionDeleted), + CalendarEventRsvpUpdated: data => this.calendarHandler.calendarRsvpUpdate(data as GatewayEvent_CalendarEventRsvpUpdated), + CalendarEventRsvpManyUpdated: () => this.calendarHandler.calendarRsvpManyUpdated(), + CalendarEventRsvpDeleted: data => this.calendarHandler.calendarRsvpDelete(data as GatewayEvent_CalendarEventRsvpDeleted), // Lists - ListItemCreated: data => this.listItemHandler.listItemCreate(data as GatewayEvent_ListItemCreated), - ListItemUpdated: data => this.listItemHandler.listItemUpdate(data as GatewayEvent_ListItemUpdated), - ListItemDeleted: data => this.listItemHandler.listItemDelete(data as GatewayEvent_ListItemDeleted), - ListItemCompleted: data => this.listItemHandler.listItemComplete(data as GatewayEvent_ListItemCompleted), - ListItemUncompleted: data => this.listItemHandler.listItemUncomplete(data as GatewayEvent_ListItemUncompleted), + ListItemCreated: data => this.listItemHandler.listItemCreate(data as GatewayEvent_ListItemCreated), + ListItemUpdated: data => this.listItemHandler.listItemUpdate(data as GatewayEvent_ListItemUpdated), + ListItemDeleted: data => this.listItemHandler.listItemDelete(data as GatewayEvent_ListItemDeleted), + ListItemCompleted: data => this.listItemHandler.listItemComplete(data as GatewayEvent_ListItemCompleted), + ListItemUncompleted: data => this.listItemHandler.listItemUncomplete(data as GatewayEvent_ListItemUncompleted), // Announcements (messages & comments) - AnnouncementCreated: data => this.announcementHandler.announcementCreate(data as GatewayEvent_AnnouncementCreated), - AnnouncementUpdated: data => this.announcementHandler.announcementUpdate(data as GatewayEvent_AnnouncementUpdated), - AnnouncementDeleted: data => this.announcementHandler.announcementDelete(data as GatewayEvent_AnnouncementDeleted), - AnnouncementCommentCreated: data => this.announcementHandler.announcementCommentCreate(data as GatewayEvent_AnnouncementCommentCreated), - AnnouncementCommentUpdated: data => this.announcementHandler.announcementCommentUpdate(data as GatewayEvent_AnnouncementCommentUpdated), - AnnouncementCommentDeleted: data => this.announcementHandler.announcementCommentDelete(data as GatewayEvent_AnnouncementCommentDeleted), - AnnouncementReactionCreated: data => this.announcementHandler.announcementReactionAdd(data as GatewayEvent_AnnouncementReactionCreated), - AnnouncementReactionDeleted: data => this.announcementHandler.announcementReactionRemove(data as GatewayEvent_AnnouncementReactionDeleted), - AnnouncementCommentReactionCreated: data => this.announcementHandler.announcementCommentReactionAdd(data as GatewayEvent_AnnouncementCommentReactionCreated), - AnnouncementCommentReactionDeleted: data => this.announcementHandler.announcementCommentReactionRemove(data as GatewayEvent_AnnouncementCommentReactionDeleted), + AnnouncementCreated: data => this.announcementHandler.announcementCreate(data as GatewayEvent_AnnouncementCreated), + AnnouncementUpdated: data => this.announcementHandler.announcementUpdate(data as GatewayEvent_AnnouncementUpdated), + AnnouncementDeleted: data => this.announcementHandler.announcementDelete(data as GatewayEvent_AnnouncementDeleted), + AnnouncementCommentCreated: data => this.announcementHandler.announcementCommentCreate(data as GatewayEvent_AnnouncementCommentCreated), + AnnouncementCommentUpdated: data => this.announcementHandler.announcementCommentUpdate(data as GatewayEvent_AnnouncementCommentUpdated), + AnnouncementCommentDeleted: data => this.announcementHandler.announcementCommentDelete(data as GatewayEvent_AnnouncementCommentDeleted), + AnnouncementReactionCreated: data => this.announcementHandler.announcementReactionAdd(data as GatewayEvent_AnnouncementReactionCreated), + AnnouncementReactionDeleted: data => this.announcementHandler.announcementReactionRemove(data as GatewayEvent_AnnouncementReactionDeleted), + AnnouncementCommentReactionCreated: data => this.announcementHandler.announcementCommentReactionAdd(data as GatewayEvent_AnnouncementCommentReactionCreated), + AnnouncementCommentReactionDeleted: data => this.announcementHandler.announcementCommentReactionRemove(data as GatewayEvent_AnnouncementCommentReactionDeleted), // Users - UserStatusCreated: data => this.userHandler.userStatusCreate(data as GatewayEvent_UserStatusCreated), - UserStatusDeleted: data => this.userHandler.userStatusDelete(data as GatewayEvent_UserStatusDeleted) + UserStatusCreated: data => this.userHandler.userStatusCreate(data as GatewayEvent_UserStatusCreated), + UserStatusDeleted: data => this.userHandler.userStatusDelete(data as GatewayEvent_UserStatusDeleted), + // Category + CategoryCreated: data => this.guildHandler.guildCategoryCreate(data as GatewayEvent_CategoryCreated), + CategoryUpdated: data => this.guildHandler.guildCategoryUpdate(data as GatewayEvent_CategoryUpdated), + CategoryDeleted: data => this.guildHandler.guildCategoryDelete(data as GatewayEvent_CategoryDeleted) }; async handleMessage(eventType: keyof GATEWAY_EVENTS, eventData: object): Promise { diff --git a/lib/gateway/events/ChannelHandler.ts b/lib/gateway/events/ChannelHandler.ts index 100b20e5..ef32d770 100644 --- a/lib/gateway/events/ChannelHandler.ts +++ b/lib/gateway/events/ChannelHandler.ts @@ -1,6 +1,18 @@ /** @module ChannelHandler */ import { GatewayEventHandler } from "./GatewayEventHandler"; -import { GatewayEvent_ServerChannelCreated, GatewayEvent_ServerChannelDeleted, GatewayEvent_ServerChannelUpdated } from "../../Constants"; +import { + GatewayEvent_ChannelArchived, + GatewayEvent_ChannelCategoryRolePermissionCreated, + GatewayEvent_ChannelCategoryUserPermissionCreated, + GatewayEvent_ChannelRestored, + GatewayEvent_ChannelRolePermissionCreated, + GatewayEvent_ChannelUserPermissionCreated, + GatewayEvent_ChannelUserPermissionDeleted, + GatewayEvent_ChannelUserPermissionUpdated, + GatewayEvent_ServerChannelCreated, + GatewayEvent_ServerChannelDeleted, + GatewayEvent_ServerChannelUpdated +} from "../../Constants"; import { AnyChannel } from "../../types/channel"; /** Internal component, emitting channel events. */ @@ -28,6 +40,76 @@ export class ChannelHandler extends GatewayEventHandler{ this.client.emit("channelDelete", ChannelComponent); } + async channelRolePermissionCreated(data: GatewayEvent_ChannelRolePermissionCreated): Promise { + const ChannelComponent = data.channelRolePermission; + this.client.emit("channelRolePermissionCreated", ChannelComponent); + } + + async channelRolePermissionUpdated(data: GatewayEvent_ChannelRolePermissionCreated): Promise { + const ChannelComponent = data.channelRolePermission; + this.client.emit("channelRolePermissionUpdated", ChannelComponent); + } + + async channelRolePermissionDeleted(data: GatewayEvent_ChannelRolePermissionCreated): Promise { + const ChannelComponent = data.channelRolePermission; + this.client.emit("channelRolePermissionDeleted", ChannelComponent); + } + + async channelUserPermissionCreated(data: GatewayEvent_ChannelUserPermissionCreated): Promise { + const ChannelComponent = data.channelUserPermission; + this.client.emit("channelUserPermissionCreated", ChannelComponent); + } + + async channelUserPermissionUpdated(data: GatewayEvent_ChannelUserPermissionUpdated): Promise { + const ChannelComponent = data.channelUserPermission; + this.client.emit("channelUserPermissionUpdated", ChannelComponent); + } + + async channelUserPermissionDeleted(data: GatewayEvent_ChannelUserPermissionDeleted): Promise { + const ChannelComponent = data.channelUserPermission; + this.client.emit("channelUserPermissionDeleted", ChannelComponent); + } + + async channelCategoryUserPermissionCreated(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise { + const ChannelComponent = data.channelCategoryUserPermission; + this.client.emit("channelCategoryUserPermissionCreated", ChannelComponent); + } + + async channelCategoryUserPermissionUpdated(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise { + const ChannelComponent = data.channelCategoryUserPermission; + this.client.emit("channelCategoryUserPermissionUpdated", ChannelComponent); + } + + async channelCategoryUserPermissionDeleted(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise { + const ChannelComponent = data.channelCategoryUserPermission; + this.client.emit("channelCategoryUserPermissionDeleted", ChannelComponent); + } + + async channelCategoryRolePermissionCreated(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise { + const ChannelComponent = data.channelCategoryRolePermission; + this.client.emit("channelCategoryRolePermissionCreated", ChannelComponent); + } + + async channelCategoryRolePermissionUpdated(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise { + const ChannelComponent = data.channelCategoryRolePermission; + this.client.emit("channelCategoryRolePermissionUpdated", ChannelComponent); + } + + async channelCategoryRolePermissionDeleted(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise { + const ChannelComponent = data.channelCategoryRolePermission; + this.client.emit("channelCategoryRolePermissionDeleted", ChannelComponent); + } + + async channelArchive(data: GatewayEvent_ChannelArchived): Promise { + const ChannelComponent = this.client.util.updateChannel(data.channel); + this.client.emit("channelArchive", ChannelComponent); + } + + async channelRestore(data: GatewayEvent_ChannelRestored): Promise { + const ChannelComponent = this.client.util.updateChannel(data.channel); + this.client.emit("channelRestore", ChannelComponent); + } + private async addGuildChannel(guildID: string, channelID: string): Promise { if (this.client.getChannel(guildID, channelID) !== undefined) return; const channel = await this.client.rest.channels.getChannel(channelID).catch(err => this.client.emit("warn", `Cannot register channel to cache due to: (${String(err)})`)); diff --git a/lib/gateway/events/GuildHandler.ts b/lib/gateway/events/GuildHandler.ts index 951ca43a..0d04493c 100644 --- a/lib/gateway/events/GuildHandler.ts +++ b/lib/gateway/events/GuildHandler.ts @@ -21,11 +21,13 @@ import { GatewayEvent_ServerMemberSocialLinkUpdated, GatewayEvent_ServerMemberUnbanned, GatewayEvent_ServerMemberUpdated, - GatewayEvent_ServerRolesUpdated + GatewayEvent_ServerRolesUpdated, + GatewayEvent_CategoryCreated } from "../../Constants"; import { MemberUpdateInfo } from "../../structures/MemberUpdateInfo"; import { MemberRemoveInfo } from "../../structures/MemberRemoveInfo"; import { GuildGroup } from "../../structures/GuildGroup"; +import { GuildCategory } from "../../structures/GuildCategory"; /** Internal component, emitting guild events. */ export class GuildHandler extends GatewayEventHandler { @@ -127,6 +129,21 @@ export class GuildHandler extends GatewayEventHandler { const guild = this.client.guilds.get(data.serverId); const role = guild?.roles.update(new GuildRole(data.role, this.client)) ?? new GuildRole(data.role, this.client); guild?.roles.delete(data.role.id); - this.client.emit("guildRoleCreate", role); + this.client.emit("guildRoleDelete", role); + } + + guildCategoryCreate(data: GatewayEvent_CategoryCreated): void { + const category = new GuildCategory(data.category, this.client); + this.client.emit("guildCategoryCreate", category); + } + + guildCategoryUpdate(data: GatewayEvent_CategoryCreated): void { + const category = new GuildCategory(data.category, this.client); + this.client.emit("guildCategoryUpdate", category); + } + + guildCategoryDelete(data: GatewayEvent_CategoryCreated): void { + const category = new GuildCategory(data.category, this.client); + this.client.emit("guildCategoryDelete", category); } } diff --git a/lib/gateway/events/MessageHandler.ts b/lib/gateway/events/MessageHandler.ts index 72d731ca..2f5cb350 100644 --- a/lib/gateway/events/MessageHandler.ts +++ b/lib/gateway/events/MessageHandler.ts @@ -3,9 +3,11 @@ import { GatewayEventHandler } from "./GatewayEventHandler"; import { Message } from "../../structures/Message"; import { MessageReactionInfo } from "../../structures/MessageReactionInfo"; import { + GatewayEvent_ChannelMessagePinned, GatewayEvent_ChannelMessageReactionCreated, GatewayEvent_ChannelMessageReactionDeleted, GatewayEvent_ChannelMessageReactionManyDeleted, + GatewayEvent_ChannelMessageUnpinned, GatewayEvent_ChatMessageCreated, GatewayEvent_ChatMessageDeleted, GatewayEvent_ChatMessageUpdated @@ -75,6 +77,21 @@ export class MessageHandler extends GatewayEventHandler { this.client.emit("reactionBulkRemove", BulkRemoveInfo); } + async messagePin(data: GatewayEvent_ChannelMessagePinned): Promise { + if (this.client.params.waitForCaching) await this.addGuildChannel(data.serverId, data.message.channelId); + else void this.addGuildChannel(data.serverId, data.message.channelId); + const channel = this.client.getChannel(data.serverId, data.message.channelId); + const MessageComponent = channel?.messages?.update(data.message) ?? new Message(data.message, this.client); + this.client.emit("messagePin", MessageComponent); + } + + async messageUnpin(data: GatewayEvent_ChannelMessageUnpinned): Promise { + if (this.client.params.waitForCaching) await this.addGuildChannel(data.serverId, data.message.channelId); + else void this.addGuildChannel(data.serverId, data.message.channelId); + const channel = this.client.getChannel(data.serverId, data.message.channelId); + const MessageComponent = channel?.messages?.update(data.message) ?? new Message(data.message, this.client); + this.client.emit("messageUnpin", MessageComponent); + } private async addGuildChannel(guildID: string, channelID: string): Promise { if (this.client.getChannel(guildID, channelID) !== undefined) return; diff --git a/lib/rest/endpoints.ts b/lib/rest/endpoints.ts index 13032821..e2bd0dd5 100644 --- a/lib/rest/endpoints.ts +++ b/lib/rest/endpoints.ts @@ -25,6 +25,14 @@ export const CHANNEL_ANNOUNCEMENT_COMMENTS = (channelID: string, announcementID: export const CHANNEL_ANNOUNCEMENT_COMMENT = (channelID: string, announcementID: string, commentID: number) => `/channels/${channelID}/announcements/${announcementID}/comments/${commentID}`; export const CHANNEL_ANNOUNCEMENT_COMMENT_EMOTES = (channelID: string, announcementID: string, commentID: number) => `/channels/${channelID}/announcements/${announcementID}/comments/${commentID}/emotes`; export const CHANNEL_ANNOUNCEMENT_COMMENT_EMOTE = (channelID: string, announcementID: string, commentID: number, emoteID: number) => `/channels/${channelID}/announcements/${announcementID}/comments/${commentID}/emotes/${emoteID}`; +export const CHANNEL_ROLE_PERMISSION = (serverID: string, channelID: string, roleID: number) => `/servers/${serverID}/channels/${channelID}/permissions/roles/${roleID}`; +export const CHANNEL_ROLE_MANY_PERMISSION = (serverID: string, channelID: string) => `/servers/${serverID}/channels/${channelID}/permissions/roles`; +export const CHANNEL_USER_PERMISSION = (serverID: string, channelID: string, userID: string) => `/servers/${serverID}/channels/${channelID}/permissions/users/${userID}`; +export const CHANNEL_USER_MANY_PERMISSION = (serverID: string, channelID: string) => `/servers/${serverID}/channels/${channelID}/permissions/users`; +export const CHANNEL_CATEGORY_USER_PERMISSION = (serverID: string, categoryID: number, userID: string) => `/servers/${serverID}/categories/${categoryID}/permissions/users/${userID}`; +export const CHANNEL_CATEGORY_USER_MANY_PERMISSION = (serverID: string, categoryID: number) => `/servers/${serverID}/categories/${categoryID}/permissions/users`; +export const CHANNEL_CATEGORY_ROLE_PERMISSION = (serverID: string, categoryID: number, roleID: number) => `/servers/${serverID}/categories/${categoryID}/permissions/roles/${roleID}`; +export const CHANNEL_CATEGORY_ROLE_MANY_PERMISSION = (serverID: string, categoryID: number) => `/servers/${serverID}/categories/${categoryID}/permissions/roles`; export const MEMBER_NICKNAME = (guildID: string, memberID: string) => `/servers/${guildID}/members/${memberID}/nickname`; diff --git a/lib/routes/Channels.ts b/lib/routes/Channels.ts index 3aa41352..551d2523 100644 --- a/lib/routes/Channels.ts +++ b/lib/routes/Channels.ts @@ -64,7 +64,30 @@ import { POSTListItemBody, POSTListItemResponse, PUTCalendarEventRSVPResponse, - PUTDocResponse + PUTDocResponse, + POSTChannelRolePermissionBody, + POSTChannelRolePermissionResponse, + GETChannelRolePermissionResponse, + GETChannelRoleManyPermissionResponse, + PATCHChannelRolePermissionBody, + PATCHChannelRolePermissionResponse, + POSTChannelUserPermissionBody, + POSTChannelUserPermissionResponse, + GETChannelUserPermissionResponse, + GETChannelUserManyPermissionResponse, + PATCHChannelUserPermissionResponse, + POSTChannelCategoryRolePermissionBody, + POSTChannelCategoryRolePermissionResponse, + GETChannelCategoryRolePermissionResponse, + GETChannelCategoryRoleManyPermissionResponse, + PATCHChannelCategoryRolePermissionBody, + PATCHChannelCategoryRolePermissionResponse, + POSTChannelCategoryUserPermissionBody, + POSTChannelCategoryUserPermissionResponse, + GETChannelCategoryUserPermissionResponse, + GETChannelCategoryUserManyPermissionResponse, + PATCHChannelCategoryUserPermissionBody, + PATCHChannelCategoryUserPermissionResponse } from "../Constants"; import { AnyChannel, @@ -93,6 +116,10 @@ import { CreateDocCommentOptions, EditDocCommentOptions } from "../types/docComm import { DocComment } from "../structures/DocComment"; import { Announcement } from "../structures/Announcement"; import { AnnouncementComment } from "../structures/AnnouncementComment"; +import { ChannelUserPermission } from "../structures/ChannelUserPermission"; +import { ChannelRolePermission } from "../structures/ChannelRolePermission"; +import { ChannelCategoryRolePermission } from "../structures/ChannelCategoryRolePermission"; +import { ChannelCategoryUserPermission } from "../structures/ChannelCategoryUserPermission"; export class Channels { #manager: RESTManager; @@ -1114,4 +1141,269 @@ export class Channels { path: endpoints.CHANNEL_MESSAGE_PIN(channelID, messageID) }); } + + /** + * Create a channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param roleID ID of the role to create the permission for + * @param options Permission options + */ + async createChannelRolePermission(serverID: string, channelID: string, roleID: number, options: POSTChannelRolePermissionBody): Promise { + if (typeof options !== "object") throw new Error("doc options should be an object."); + return this.#manager.authRequest({ + method: "POST", + path: endpoints.CHANNEL_ROLE_PERMISSION(serverID, channelID, roleID), + json: options + }).then(data => new ChannelRolePermission(data.channelRolePermission, this.#manager.client)); + } + + /** + * Get channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param roleID ID of the role to get the permission for + */ + async getChannelRolePermission(serverID: string, channelID: string, roleID: number): Promise { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_ROLE_PERMISSION(serverID, channelID, roleID) + }).then(data => new ChannelRolePermission(data.channelRolePermission, this.#manager.client)); + } + + /** + * Get channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + */ + async getChannelRolesPermission(serverID: string, channelID: string): Promise> { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_ROLE_MANY_PERMISSION(serverID, channelID) + }).then(data => data.channelRolePermissions.map(d => new ChannelRolePermission(d, this.#manager.client))); + } + + /** + * Update a channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + */ + async editChannelRolePermission(serverID: string, channelID: string, roleID: number, options: PATCHChannelRolePermissionBody): Promise { + return this.#manager.authRequest({ + method: "PATCH", + path: endpoints.CHANNEL_ROLE_PERMISSION(serverID, channelID, roleID), + json: options + }).then(data => new ChannelRolePermission(data.channelRolePermission, this.#manager.client)); + } + + /** + * Delete a channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + */ + async deleteChannelRolePermission(serverID: string, channelID: string, roleID: number): Promise { + return this.#manager.authRequest({ + method: "DELETE", + path: endpoints.CHANNEL_ROLE_PERMISSION(serverID, channelID, roleID) + }); + } + + /** + * Create a channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param userID ID of the user to create the permission for + * @param options Permission options + */ + async createChannelUserPermission(serverID: string, channelID: string, userID: string, options: POSTChannelUserPermissionBody): Promise { + if (typeof options !== "object") throw new Error("doc options should be an object."); + return this.#manager.authRequest({ + method: "POST", + path: endpoints.CHANNEL_USER_PERMISSION(serverID, channelID, userID), + json: options + }).then(data => new ChannelUserPermission(data.channelUserPermission, this.#manager.client)); + } + + /** + * Get channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param userID ID of the user to get the permission + */ + async getChannelUserPermission(serverID: string, channelID: string, userID: string): Promise { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_USER_PERMISSION(serverID, channelID, userID) + }).then(data => new ChannelUserPermission(data.channelUserPermission, this.#manager.client)); + } + + /** + * Get channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param userID ID of the user to get the permission + */ + async getChannelUsersPermission(serverID: string, channelID: string): Promise> { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_USER_MANY_PERMISSION(serverID, channelID) + }).then(data => data.channelUserPermissions.map(d => new ChannelUserPermission(d, this.#manager.client))); + } + + /** + * Update a channel user permission. + * @param userID ID of the user + * @param channelID ID of the channel + */ + async editChannelUserPermission(serverID: string, channelID: string, userID: string, options: PATCHChannelRolePermissionBody): Promise { + return this.#manager.authRequest({ + method: "PATCH", + path: endpoints.CHANNEL_USER_PERMISSION(serverID, channelID, userID), + json: options + }).then(data => new ChannelUserPermission(data.channelUserPermission, this.#manager.client)); + } + + /** + * Delete a channel role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + */ + async deleteChannelUserPermission(serverID: string, channelID: string, userID: string): Promise { + return this.#manager.authRequest({ + method: "DELETE", + path: endpoints.CHANNEL_USER_PERMISSION(serverID, channelID, userID) + }); + } + + /** + * Create a channel category role permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param roleID ID of the role to create the permission for + * @param options Permission options + */ + async createChannelCategoryRolePermission(serverID: string, categoryID: number, roleID: number, options: POSTChannelCategoryRolePermissionBody): Promise { + if (typeof options !== "object") throw new Error("doc options should be an object."); + return this.#manager.authRequest({ + method: "POST", + path: endpoints.CHANNEL_CATEGORY_ROLE_PERMISSION(serverID, categoryID, roleID), + json: options + }).then(data => new ChannelCategoryRolePermission(data.channelCategoryRolePermission, this.#manager.client)); + } + + /** + * Get category role permission. + * @param serverID ID of the server where the channel is in + * @param categoryID ID of the channel + * @param roleID ID of the role to get the permission for + */ + async getChannelCategoryRolePermission(serverID: string, categoryID: number, roleID: number): Promise { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_CATEGORY_ROLE_PERMISSION(serverID, categoryID, roleID) + }).then(data => new ChannelCategoryRolePermission(data.channelCategoryRolePermission, this.#manager.client)); + } + + /** + * Get category roles permission. + * @param serverID ID of the server where the channel is in + * @param categoryID ID of the channel + */ + async getChannelCategoryRolesPermission(serverID: string, categoryID: number): Promise> { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_CATEGORY_ROLE_MANY_PERMISSION(serverID, categoryID) + }).then(data => data.channelCategoryRolePermissions.map(d => new ChannelCategoryRolePermission(d, this.#manager.client))); + } + + /** + * Update a category role permission. + * @param userID ID of the user + * @param categoryID ID of the category + */ + async editChannelCategoryRolePermission(serverID: string, categoryID: number, roleID: number, options: PATCHChannelCategoryRolePermissionBody): Promise { + return this.#manager.authRequest({ + method: "PATCH", + path: endpoints.CHANNEL_CATEGORY_ROLE_PERMISSION(serverID, categoryID, roleID), + json: options + }).then(data => new ChannelCategoryRolePermission(data.channelCategoryRolePermission, this.#manager.client)); + } + + /** + * Delete a channel role permission. + * @param serverID ID of the server where the channel is in + * @param categoryID ID of the category + */ + async deleteChannelCategoryRolePermission(serverID: string, categoryID: number, roleID: number): Promise { + return this.#manager.authRequest({ + method: "DELETE", + path: endpoints.CHANNEL_CATEGORY_ROLE_PERMISSION(serverID, categoryID, roleID) + }); + } + + /** + * Create a channel category user permission. + * @param serverID ID of the server where the channel is in + * @param channelID ID of the channel + * @param userID ID of the user to create the permission for + * @param options Permission options + */ + async createChannelCategoryUserPermission(serverID: string, categoryID: number, userID: string, options: POSTChannelCategoryUserPermissionBody): Promise { + if (typeof options !== "object") throw new Error("doc options should be an object."); + return this.#manager.authRequest({ + method: "POST", + path: endpoints.CHANNEL_CATEGORY_USER_PERMISSION(serverID, categoryID, userID), + json: options + }).then(data => new ChannelCategoryUserPermission(data.channelCategoryUserPermission, this.#manager.client)); + } + + /** + * Get category user permission. + * @param serverID ID of the server where the channel is in + * @param categoryID ID of the channel + * @param roleID ID of the role to get the permission for + */ + async getChannelCategoryUserPermission(serverID: string, categoryID: number, userID: string): Promise { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_CATEGORY_USER_PERMISSION(serverID, categoryID, userID) + }).then(data => new ChannelCategoryUserPermission(data.channelCategoryUserPermission, this.#manager.client)); + } + + /** + * Get category users permission. + * @param serverID ID of the server where the channel is in + * @param categoryID ID of the channel + */ + async getChannelCategoryUsersPermission(serverID: string, categoryID: number): Promise> { + return this.#manager.authRequest({ + method: "GET", + path: endpoints.CHANNEL_CATEGORY_USER_MANY_PERMISSION(serverID, categoryID) + }).then(data => data.channelCategoryUserPermissions.map(d => new ChannelCategoryUserPermission(d, this.#manager.client))); + } + + /** + * Update a category user permission. + * @param userID ID of the user + * @param categoryID ID of the category + */ + async editChannelCategoryUserPermission(serverID: string, categoryID: number, userID: string, options: PATCHChannelCategoryUserPermissionBody): Promise { + return this.#manager.authRequest({ + method: "PATCH", + path: endpoints.CHANNEL_CATEGORY_USER_PERMISSION(serverID, categoryID, userID), + json: options + }).then(data => new ChannelCategoryUserPermission(data.channelCategoryUserPermission, this.#manager.client)); + } + + /** + * Delete a channel role permission. + * @param serverID ID of the server where the channel is in + * @param categoryID ID of the category + */ + async deleteChannelCategoryUserPermission(serverID: string, categoryID: number, userID: string): Promise { + return this.#manager.authRequest({ + method: "DELETE", + path: endpoints.CHANNEL_CATEGORY_USER_PERMISSION(serverID, categoryID, userID) + }); + } } diff --git a/lib/structures/ChannelCategoryRolePermission.ts b/lib/structures/ChannelCategoryRolePermission.ts new file mode 100644 index 00000000..51deeb5d --- /dev/null +++ b/lib/structures/ChannelCategoryRolePermission.ts @@ -0,0 +1,65 @@ +/** @module ChannelCategoryRolePermission */ + +import { Client } from "./Client"; +import { Base } from "./Base"; +import { JSONChannelCategoryRolePermission } from "../types/json"; +import { APIChannelCategoryRolePermission } from "guildedapi-types.ts/v1"; + +/** Class representing a guild group. */ +export class ChannelCategoryRolePermission extends Base { + /** raw data */ + data: APIChannelCategoryRolePermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: Date | null; + /** The ID of the role */ + roleId: number; + /** The ID of the channel */ + categoryId: number; + + constructor(data: APIChannelCategoryRolePermission, client: Client) { + super(data.roleId, client); + this.data = data; + this.permissions = data.permissions; + this.createdAt = new Date(data.createdAt); + this.updatedAt = data.updatedAt ?? null; + this.roleId = data.roleId; + this.categoryId = data.categoryId; + this.update(data); + } + + override toJSON(): JSONChannelCategoryRolePermission { + return { + ...super.toJSON(), + data: this.data, + permissions: this.permissions, + createdAt: this.createdAt, + updatedAt: this.updatedAt ?? null, + roleId: this.roleId, + categoryId: this.categoryId + }; + } + + protected override update(data: APIChannelCategoryRolePermission): void { + if (data.roleId !== undefined) { + this.roleId = data.roleId; + } + if (data.permissions !== undefined) { + this.permissions = data.permissions; + } + if (data.createdAt !== undefined) { + this.createdAt = new Date(data.createdAt); + } + if (data.updatedAt !== undefined) { + this.updatedAt = data.updatedAt ?? null; + } + if (data.categoryId !== undefined) { + this.categoryId = data.categoryId; + } + if (data.roleId !== undefined) { + this.roleId = data.roleId; + } + } +} diff --git a/lib/structures/ChannelCategoryUserPermission.ts b/lib/structures/ChannelCategoryUserPermission.ts new file mode 100644 index 00000000..0e6a04a1 --- /dev/null +++ b/lib/structures/ChannelCategoryUserPermission.ts @@ -0,0 +1,65 @@ +/** @module ChannelCategoryUserPermission */ + +import { Client } from "./Client"; +import { Base } from "./Base"; +import { JSONChannelCategoryUserPermission } from "../types/json"; +import { APIChannelCategoryUserPermission } from "guildedapi-types.ts/v1"; + +/** Class representing a guild group. */ +export class ChannelCategoryUserPermission extends Base { + /** raw data */ + data: APIChannelCategoryUserPermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: Date | null; + /** The ID of the user */ + userId: string; + /** The ID of the channel */ + categoryId: number; + + constructor(data: APIChannelCategoryUserPermission, client: Client) { + super(data.userId, client); + this.data = data; + this.permissions = data.permissions; + this.createdAt = new Date(data.createdAt); + this.updatedAt = data.updatedAt ?? null; + this.userId = data.userId; + this.categoryId = data.categoryId; + this.update(data); + } + + override toJSON(): JSONChannelCategoryUserPermission { + return { + ...super.toJSON(), + data: this.data, + permissions: this.permissions, + createdAt: this.createdAt, + updatedAt: this.updatedAt ?? null, + userId: this.userId, + categoryId: this.categoryId + }; + } + + protected override update(data: APIChannelCategoryUserPermission): void { + if (data.userId !== undefined) { + this.userId = data.userId; + } + if (data.permissions !== undefined) { + this.permissions = data.permissions; + } + if (data.createdAt !== undefined) { + this.createdAt = new Date(data.createdAt); + } + if (data.updatedAt !== undefined) { + this.updatedAt = data.updatedAt ?? null; + } + if (data.categoryId !== undefined) { + this.categoryId = data.categoryId; + } + if (data.userId !== undefined) { + this.userId = data.userId; + } + } +} diff --git a/lib/structures/ChannelRolePermission.ts b/lib/structures/ChannelRolePermission.ts new file mode 100644 index 00000000..08e8c17e --- /dev/null +++ b/lib/structures/ChannelRolePermission.ts @@ -0,0 +1,65 @@ +/** @module ChannelRolePermission */ + +import { Client } from "./Client"; +import { Base } from "./Base"; +import { JSONChannelRolePermission } from "../types/json"; +import { APIChannelRolePermission } from "guildedapi-types.ts/v1"; + +/** Class representing a guild group. */ +export class ChannelRolePermission extends Base { + /** raw data */ + data: APIChannelRolePermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: Date | null; + /** The ID of the role */ + roleId: number; + /** The ID of the channel */ + channelId: string; + + constructor(data: APIChannelRolePermission, client: Client) { + super(data.roleId, client); + this.data = data; + this.permissions = data.permissions; + this.createdAt = new Date(data.createdAt); + this.updatedAt = data.updatedAt ?? null; + this.roleId = data.roleId; + this.channelId = data.channelId; + this.update(data); + } + + override toJSON(): JSONChannelRolePermission { + return { + ...super.toJSON(), + data: this.data, + permissions: this.permissions, + createdAt: this.createdAt, + updatedAt: this.updatedAt ?? null, + roleId: this.roleId, + channelId: this.channelId + }; + } + + protected override update(data: APIChannelRolePermission): void { + if (data.roleId !== undefined) { + this.roleId = data.roleId; + } + if (data.permissions !== undefined) { + this.permissions = data.permissions; + } + if (data.createdAt !== undefined) { + this.createdAt = new Date(data.createdAt); + } + if (data.updatedAt !== undefined) { + this.updatedAt = data.updatedAt ?? null; + } + if (data.channelId !== undefined) { + this.channelId = data.channelId; + } + if (data.roleId !== undefined) { + this.roleId = data.roleId; + } + } +} diff --git a/lib/structures/ChannelUserPermission.ts b/lib/structures/ChannelUserPermission.ts new file mode 100644 index 00000000..541796b4 --- /dev/null +++ b/lib/structures/ChannelUserPermission.ts @@ -0,0 +1,65 @@ +/** @module ChannelUserPermission */ + +import { Client } from "./Client"; +import { Base } from "./Base"; +import { JSONChannelUserPermission } from "../types/json"; +import { APIChannelUserPermission } from "guildedapi-types.ts/v1"; + +/** Class representing a guild group. */ +export class ChannelUserPermission extends Base { + /** raw data */ + data: APIChannelUserPermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: Date | null; + /** The ID of the user */ + userId: string; + /** The ID of the channel */ + channelId: string; + + constructor(data: APIChannelUserPermission, client: Client) { + super(data.userId, client); + this.data = data; + this.permissions = data.permissions; + this.createdAt = new Date(data.createdAt); + this.updatedAt = data.updatedAt ?? null; + this.userId = data.userId; + this.channelId = data.channelId; + this.update(data); + } + + override toJSON(): JSONChannelUserPermission { + return { + ...super.toJSON(), + data: this.data, + permissions: this.permissions, + createdAt: this.createdAt, + updatedAt: this.updatedAt ?? null, + userId: this.userId, + channelId: this.channelId + }; + } + + protected override update(data: APIChannelUserPermission): void { + if (data.userId !== undefined) { + this.userId = data.userId; + } + if (data.permissions !== undefined) { + this.permissions = data.permissions; + } + if (data.createdAt !== undefined) { + this.createdAt = new Date(data.createdAt); + } + if (data.updatedAt !== undefined) { + this.updatedAt = data.updatedAt ?? null; + } + if (data.channelId !== undefined) { + this.channelId = data.channelId; + } + if (data.userId !== undefined) { + this.userId = data.userId; + } + } +} diff --git a/lib/structures/GuildCategory.ts b/lib/structures/GuildCategory.ts index 6752633b..6fe4ca3e 100644 --- a/lib/structures/GuildCategory.ts +++ b/lib/structures/GuildCategory.ts @@ -2,9 +2,11 @@ import { Client } from "./Client"; import { Base } from "./Base"; +import { ChannelCategoryRolePermission } from "./ChannelCategoryRolePermission"; +import { ChannelCategoryUserPermission } from "./ChannelCategoryUserPermission"; import { JSONGuildCategory } from "../types/json"; import { PATCHUpdateCategoryBody } from "../Constants"; -import { APIGuildCategory } from "guildedapi-types.ts/v1"; +import { APIGuildCategory, POSTChannelCategoryRolePermissionBody, POSTChannelCategoryUserPermissionBody } from "guildedapi-types.ts/v1"; /** Class representing a guild group. */ export class GuildCategory extends Base { @@ -83,4 +85,86 @@ export class GuildCategory extends Base { async deleteCategory(): Promise { return this.client.rest.guilds.deleteCategory(this.serverId as string, this.id as number); } + + /** + * Create guild category role permission. + * @param roleID ID of the role + * @param options permissions to set + */ + async createRolePermission(roleID: number, options: POSTChannelCategoryRolePermissionBody): Promise { + return this.client.rest.channels.createChannelCategoryRolePermission(this.serverId as string, this.id as number, roleID, options); + } + + /** + * Create guild category role permissions. + * @param roleID ID of the role + */ + async getRolePermissions(roleID: number): Promise { + return this.client.rest.channels.getChannelCategoryRolePermission(this.serverId as string, this.id as number, roleID); + } + + /** + * Get guild category roles permissions. + */ + async getRolesPermissions(): Promise> { + return this.client.rest.channels.getChannelCategoryRolesPermission(this.serverId as string, this.id as number); + } + + /** + * Edit guild category role permission. + * @param roleID ID of the role + * @param options permissions to set + */ + async editRolePermissions(roleID: number, options: POSTChannelCategoryRolePermissionBody): Promise { + return this.client.rest.channels.editChannelCategoryRolePermission(this.serverId as string, this.id as number, roleID, options); + } + + /** + * Delete guild category role permissions. + * @param roleID ID of the role + */ + async deleteRolePermissions(roleID: number): Promise { + return this.client.rest.channels.deleteChannelCategoryRolePermission(this.serverId as string, this.id as number, roleID); + } + + /** + * Create guild category role permission. + * @param userID ID of the user + * @param options permissions to set + */ + async createUserPermissions(userID: string, options: POSTChannelCategoryUserPermissionBody): Promise { + return this.client.rest.channels.createChannelCategoryUserPermission(this.serverId as string, this.id as number, userID, options); + } + + /** + * Create guild category role permissions. + * @param userID ID of the user + */ + async getUserPermissions(userID: string): Promise { + return this.client.rest.channels.getChannelCategoryUserPermission(this.serverId as string, this.id as number, userID); + } + + /** + * Get guild category roles permissions. + */ + async getUsersPermissions(): Promise> { + return this.client.rest.channels.getChannelCategoryUsersPermission(this.serverId as string, this.id as number); + } + + /** + * Edit guild category role permission. + * @param userID ID of the user + * @param options permissions to set + */ + async editUserPermissions(userID: string, options: POSTChannelCategoryRolePermissionBody): Promise { + return this.client.rest.channels.editChannelCategoryUserPermission(this.serverId as string, this.id as number, userID, options); + } + + /** + * Delete guild category role permissions. + * @param userID ID of the user + */ + async deleteUserPermissions(userID: string): Promise { + return this.client.rest.channels.deleteChannelCategoryUserPermission(this.serverId as string, this.id as number, userID); + } } diff --git a/lib/structures/Message.ts b/lib/structures/Message.ts index 9e865e45..bc76307b 100644 --- a/lib/structures/Message.ts +++ b/lib/structures/Message.ts @@ -24,6 +24,8 @@ export class Message extends Base { channelID: string; /** Content of the message. */ content: string | null; + /** Links in content to prevent unfurling as a link preview when displaying in Guilded (min items 1; must have unique items true) */ + hiddenLinkPreviewUrls?: Array; /** Array of message embed. */ embeds?: Array | []; /** The IDs of the message replied by the message. */ @@ -58,6 +60,7 @@ export class Message extends Base { this.guildID = data.serverId ?? null; this.channelID = data.channelId; this.content = data.content ?? ""; + this.hiddenLinkPreviewUrls = data.hiddenLinkPreviewUrls ?? []; this.embeds = data.embeds ?? []; this.replyMessageIds = data.replyMessageIds ?? []; this.isPrivate = data.isPrivate ?? false; @@ -77,20 +80,21 @@ export class Message extends Base { override toJSON(): JSONMessage { return { ...super.toJSON(), - type: this.type, - guildID: this.guildID, - channelID: this.channelID, - content: this.content, - embeds: this.embeds, - replyMessageIds: this.replyMessageIds, - isPrivate: this.isPrivate, - isSilent: this.isSilent, - mentions: this.mentions, - createdAt: this.createdAt, - editedTimestamp: this.editedTimestamp, - memberID: this.memberID, - webhookID: this.webhookID, - deletedAt: this.deletedAt + type: this.type, + guildID: this.guildID, + channelID: this.channelID, + content: this.content, + hiddenLinkPreviewUrls: this.hiddenLinkPreviewUrls, + embeds: this.embeds, + replyMessageIds: this.replyMessageIds, + isPrivate: this.isPrivate, + isSilent: this.isSilent, + mentions: this.mentions, + createdAt: this.createdAt, + editedTimestamp: this.editedTimestamp, + memberID: this.memberID, + webhookID: this.webhookID, + deletedAt: this.deletedAt }; } diff --git a/lib/structures/TextChannel.ts b/lib/structures/TextChannel.ts index 38d43ad5..768660da 100644 --- a/lib/structures/TextChannel.ts +++ b/lib/structures/TextChannel.ts @@ -3,8 +3,17 @@ import { Client } from "./Client"; import { Message } from "./Message"; import { GuildChannel } from "./GuildChannel"; +import { ChannelUserPermission } from "./ChannelUserPermission"; +import { ChannelRolePermission } from "./ChannelRolePermission"; import { AnyTextableChannel, EditMessageOptions } from "../types/channel"; -import type { APIChatMessage, APIGuildChannel, APIMessageOptions } from "../Constants"; +import type { + APIChatMessage, + APIGuildChannel, + APIMessageOptions, + PATCHChannelRolePermissionBody, + POSTChannelRolePermissionBody, + POSTChannelUserPermissionBody +} from "../Constants"; import TypedCollection from "../util/TypedCollection"; import { JSONTextChannel } from "../types/json"; @@ -43,6 +52,78 @@ export class TextChannel extends GuildChannel { return this.client.rest.channels.deleteMessage(this.id, messageID); } + /** Create Channel Role Permissions + * @param roleID Role ID. + * @param options Channel Role Permissions options. + */ + async createRolePermissions(roleID: number, options: POSTChannelRolePermissionBody): Promise { + return this.client.rest.channels.createChannelRolePermission(this.guildID, this.id, roleID, options); + } + + /** Get Channel Role Permissions + * @param roleID Role ID. + */ + async getRolePermissions(roleID: number): Promise { + return this.client.rest.channels.getChannelRolePermission(this.guildID, this.id, roleID); + } + + /** Get Channel Role Permissions + */ + async getRolesPermissions(): Promise> { + return this.client.rest.channels.getChannelRolesPermission(this.guildID, this.id); + } + + /** Create Channel Role Permissions + * @param roleID Role ID. + * @param options Channel Role Permissions options. + */ + async editRolePermissions(roleID: number, options: PATCHChannelRolePermissionBody): Promise { + return this.client.rest.channels.editChannelRolePermission(this.guildID, this.id, roleID, options); + } + + /** Delete Channel Role Permissions + * @param roleID Role ID. + */ + async deleteRolePermissions(roleID: number): Promise { + return this.client.rest.channels.deleteChannelRolePermission(this.guildID, this.id, roleID); + } + + /** Create Channel User Permissions + * @param userID Member ID. + * @param options Channel Role Permissions options. + */ + async createUserPermissions(userID: string, options: POSTChannelUserPermissionBody): Promise { + return this.client.rest.channels.createChannelUserPermission(this.guildID, this.id, userID, options); + } + + /** Get Channel User Permissions + * @param userID user ID. + */ + async getUserPermissions(userID: string): Promise { + return this.client.rest.channels.getChannelUserPermission(this.guildID, this.id, userID); + } + + /** Get Channel Users Permissions + */ + async getUsersPermissions(): Promise> { + return this.client.rest.channels.getChannelUsersPermission(this.guildID, this.id); + } + + /** Edit Channel User Permissions + * @param userID user ID. + * @param options Channel Role Permissions options. + */ + async editUserPermissions(userID: string, options: PATCHChannelRolePermissionBody): Promise { + return this.client.rest.channels.editChannelUserPermission(this.guildID, this.id, userID, options); + } + + /** Delete Channel Role Permissions + * @param roleID Role ID. + */ + async deleteUserPermissions(userID: string): Promise { + return this.client.rest.channels.deleteChannelUserPermission(this.guildID, this.id, userID); + } + override toJSON(): JSONTextChannel { return { ...super.toJSON(), diff --git a/lib/types/channel.d.ts b/lib/types/channel.d.ts index f7e79a23..8c78c6e9 100644 --- a/lib/types/channel.d.ts +++ b/lib/types/channel.d.ts @@ -10,6 +10,8 @@ import type { APIEmbedField } from "guildedapi-types.ts/v1"; export interface CreateMessageOptions { /** The content of the message (min length 1; max length 4000) */ content?: string; + /** Links in content to prevent unfurling as a link preview when displaying in Guilded (min items 1; must have unique items true) */ + hiddenLinkPreviewUrls?: Array; /** Embeds */ embeds?: Array; /** Message IDs to reply to (min items 1; max items 5) */ @@ -23,6 +25,8 @@ export interface CreateMessageOptions { export interface EditMessageOptions { /** The content of the message (min length 1; max length 4000) */ content?: string; + /** Links in content to prevent unfurling as a link preview when displaying in Guilded (min items 1; must have unique items true) */ + hiddenLinkPreviewUrls?: Array; /** Embeds */ embeds?: Array; /** Message IDs to reply to (min items 1; max items 5) */ @@ -137,6 +141,54 @@ export interface ChannelMessageReactionBulkRemove { emote: APIEmote | null; } +export interface ChannelRolePermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + roleId: number; + /** The ID of the channel */ + channelId: string; +} + +export interface ChannelUserPermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + userId: number; + /** The ID of the channel */ + channelId: string; +} + +export interface ChannelCategoryUserPermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + userId: number; + /** The ID of the channel */ + categoryId: string; +} + +export interface ChannelCategoryRolePermission { + permission: Array; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: string; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt?: string; + /** The ID of the role */ + roleId: number; + /** The ID of the channel */ + categoryId: string; +} + export type AnyTextableChannel = TextChannel; export type AnyChannel = GuildChannel | TextChannel | ForumChannel | DocChannel | CalendarChannel | AnnouncementChannel; export type AnyGuildChannel = Exclude; diff --git a/lib/types/events.d.ts b/lib/types/events.d.ts index 866a5c2a..d3df953a 100644 --- a/lib/types/events.d.ts +++ b/lib/types/events.d.ts @@ -52,6 +52,7 @@ import { Announcement } from "../structures/Announcement"; import type { AnnouncementComment } from "../structures/AnnouncementComment"; import { GuildGroup } from "../structures/GuildGroup"; import { GuildRole } from "../structures/GuildRole"; +import { GuildCategory } from "../structures/GuildCategory"; import type { APIBotUser } from "guildedapi-types.ts/v1"; /** Every client events. */ @@ -71,6 +72,10 @@ export interface ClientEvents { messageUpdate: [message: Message, oldMessage: JSONMessage | null]; /** @event Emitted when a message coming from a "chat" channel is deleted. */ messageDelete: [message: PossiblyUncachedMessage]; + /** @event Emitted when a message coming from a "chat" channel is pinned. */ + messagePin: [message: Message]; + /** @event Emitted when a message coming from a "chat" channel is unpinned. */ + messageUnpin: [message: Message]; /** @event Emitted when a reaction is added to anything. */ reactionAdd: [reactionInfo: AnyReactionInfo]; /** @event Emitted when a reaction is removed from anything. */ @@ -83,6 +88,34 @@ export interface ClientEvents { channelUpdate: [channel: TextChannel, oldChannel: JSONTextChannel | null] | [channel: ForumChannel, oldChannel: JSONForumChannel | null] | [channel: CalendarChannel, oldChannel: JSONCalendarChannel | null] | [channel: DocChannel, oldChannel: JSONDocChannel | null] | [channel: GuildChannel, oldChannel: JSONGuildChannel | null] | [channel: Channel, oldChannel: JSONChannel | null]; /** @event Emitted when a guild channel is deleted. */ channelDelete: [channel: AnyChannel]; + /** @event Emitted when a channel role permission is created. */ + channelRolePermissionCreated: [channelRolePermission: ChannelRolePermission]; + /** @event Emitted when a channel role permission is updated. */ + channelRolePermissionUpdated: [channelRolePermission: ChannelRolePermission]; + /** @event Emitted when a channel role permission is deleted. */ + channelRolePermissionDeleted: [channelRolePermission: ChannelRolePermission]; + /** @event Emitted when a channel user permission is created. */ + channelUserPermissionCreated: [channelUserPermission: ChannelUserPermission]; + /** @event Emitted when a channel user permission is updated. */ + channelUserPermissionUpdated: [channelUserPermission: ChannelUserPermission]; + /** @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]; + /** @event Emitted when a channel category roke permission is updated. */ + channelCategoryRolePermissionUpdated: [channelCategoryUserPermission: ChannelCategoryRolePermission]; + /** @event Emitted when a channel category role permission is deleted. */ + channelCategoryRolePermissionDeleted: [channelCategoryUserPermission: ChannelCategoryRolePermission]; + /** @event Emitted when a channel category user permission is created. */ + channelCategoryUserPermissionCreated: [channelCategoryUserPermission: ChannelCategoryUserPermission]; + /** @event Emitted when a channel category user permission is updated. */ + channelCategoryUserPermissionUpdated: [channelCategoryUserPermission: ChannelCategoryUserPermission]; + /** @event Emitted when a channel category user permission is deleted. */ + channelCategoryUserPermissionDeleted: [channelCategoryUserPermission: ChannelCategoryUserPermission]; + /** @event Emitted when a guild channel is archived. */ + channelArchive: [channel: AnyChannel]; + /** @event Emitted when a guild channel is restored. */ + channelRestore: [channel: AnyChannel]; /** @event Emitted when a forum thread is created. */ forumThreadCreate: [thread: ForumThread]; /** @event Emitted when a forum thread is edited. */ @@ -191,6 +224,12 @@ export interface ClientEvents { userStatusCreate: [userStatus: UserStatusCreate]; /** @event Emitted when a user delete their user status. */ userStatusDelete: [userStatus: UserStatusDelete]; + /** @event Emitted when a category is created. */ + guildCategoryCreate: [category: GuildCategory]; + /** @event Emitted when a category is updated. */ + guildCategoryUpdate: [category: GuildCategory]; + /** @event Emitted when a category is deleted. */ + guildCategoryDelete: [category: GuildCategory]; /** @event Emitted on process exit. */ exit: [message: string]; } diff --git a/lib/types/json.d.ts b/lib/types/json.d.ts index 83832f3b..b8766182 100644 --- a/lib/types/json.d.ts +++ b/lib/types/json.d.ts @@ -2,7 +2,7 @@ import { Member } from "../structures/Member"; import { User } from "../structures/User"; import { Guild } from "../structures/Guild"; import { UserTypes } from "../Constants"; -import { APICalendarEvent, APICalendarEventComment } from "guildedapi-types.ts/v1"; +import { APICalendarEvent, APICalendarEventComment, APIChannelUserPermission } from "guildedapi-types.ts/v1"; export interface JSONBase { // createdAt: number; @@ -18,6 +18,8 @@ export interface JSONMessage extends JSONBase { channelID: string; /** Content of the message. */ content: string | null; + /** Links in content to prevent unfurling as a link preview when displaying in Guilded (min items 1; must have unique items true) */ + hiddenLinkPreviewUrls?: Array; /** Array of message embed. */ embeds?: Array | []; /** The IDs of the message replied by the message. */ @@ -527,3 +529,54 @@ export interface JSONGuildCategory extends JSONBase { name: string; } +export interface JSONChannelUserPermission extends JSONBase { + data: APIChannelUserPermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt: Date | null; + /** The ID of the user */ + userId: string; + /** The ID of the channel */ + channelId: string; +} + +export interface JSONChannelRolePermission extends JSONBase { + data: APIChannelRolePermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt: Date | null; + /** The ID of the user */ + roleId: number; + /** The ID of the channel */ + channelId: string; +} + +export interface JSONChannelCategoryRolePermission extends JSONBase { + data: APIChannelCategoryRolePermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt: Date | null; + /** The ID of the role */ + roleId: number; + /** The ID of the channel */ + categoryId: number; +} + +export interface JSONChannelCategoryUserPermission extends JSONBase { + data: APIChannelCategoryRolePermission; + permissions: Record; + /** The ISO 8601 timestamp that the permission override was created at */ + createdAt: Date; + /** The ISO 8601 timestamp that the permission override was updated at, if relevant */ + updatedAt: Date | null; + /** The ID of the user */ + userId: string; + /** The ID of the channel */ + categoryId: number; +} From 645380fad80ce9b48471eeb36f62cb0713f01150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= <41128238+raphckrman@users.noreply.github.com> Date: Fri, 29 Sep 2023 18:25:17 +0200 Subject: [PATCH 2/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4268ad9d..555ae7a2 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.9.4" }, "dependencies": { - "guildedapi-types.ts": "0.3.36", + "guildedapi-types.ts": "0.3.37", "undici": "^5.14.0", "ws": "^8.11.0" }, From c2fbbba9313ea572def838841731c3c1303ae586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl?= <41128238+raphckrman@users.noreply.github.com> Date: Fri, 29 Sep 2023 18:26:59 +0200 Subject: [PATCH 3/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 555ae7a2..c7c021a5 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "typescript": "^4.9.4" }, "dependencies": { - "guildedapi-types.ts": "0.3.37", + "guildedapi-types.ts": "0.3.38", "undici": "^5.14.0", "ws": "^8.11.0" },