From 9cf221aa82b0cfb9634e2e2d5ee99abd71902980 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:36:10 +0000 Subject: [PATCH] fix: follow announcement helper --- packages/rest/src/manager.ts | 69 +++++++++++++++++++++++++++++++++++ packages/types/src/discord.ts | 22 +++++------ 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 264413acd..157e99df4 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -1,3 +1,24 @@ +/** + * TODO: missing helpers + * followAnnouncements + * createForumThread + * createStageInstance + * deleteStageInstance + * editStageInstance + * getStageInstance + * addThreadMember + * getActiveThreads + * getPrivateArchivedThreads + * getPrivateJoinedArchivedThreads + * getPublicArchivedThreads + * getThreadMember + * getThreadMembers + * joinThread + * leaveThread + * removeThreadMember + * startThreadWithMessage + * startThreadWithoutMessage + */ import type { BigString, Camelize, @@ -10,6 +31,8 @@ import type { DiscordCreateMessage, DiscordCreateWebhook, DiscordEmoji, + DiscordFollowAnnouncementChannel, + DiscordFollowedChannel, DiscordGetGatewayBot, DiscordInviteMetadata, DiscordMessage, @@ -93,6 +116,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return `/channels/${channelId}` }, + follow: (channelId) => { + return `/channels/${channelId}/followers` + }, + invites: (channelId) => { return `/channels/${channelId}/invites` }, @@ -467,6 +494,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.editChannel(id, options) }, + async follow(sourceChannelId, targetChannelId) { + return await rest.followAnnouncement(sourceChannelId, targetChannelId) + }, + permissions: { async edit(channelId, options) { return await rest.editChannelPermissionOverrides(channelId, options) @@ -620,6 +651,12 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.patch(rest.routes.guilds.channels(guildId), channelPositions) }, + async followAnnouncement(sourceChannelId, targetChannelId) { + return await rest.post(rest.routes.channels.follow(sourceChannelId), { + webhook_channel_id: targetChannelId, + } as DiscordFollowAnnouncementChannel) + }, + async getChannelInvites(channelId) { return await rest.get(rest.routes.channels.invites(channelId)) }, @@ -832,6 +869,8 @@ export interface RestManager { webhooks: (channelId: BigString) => string /** Route for a specific channel. */ channel: (channelId: BigString) => string + /** Route for following a specific channel. */ + follow: (channelId: BigString) => string /** Route for a specific channel's invites. */ invites: (channelId: BigString) => string /** Route for a specific message */ @@ -969,6 +1008,21 @@ export interface RestManager { * - Fires a _Channel Update_ gateway event. */ edit: (channelId: BigString, options: ModifyChannel) => Promise> + /** + * Follows an announcement channel, allowing messages posted within it to be cross-posted into the target channel. + * + * @param sourceChannelId - The ID of the announcement channel to follow. + * @param targetChannelId - The ID of the target channel - the channel to cross-post to. + * @returns An instance of {@link DiscordFollowedChannel}. + * + * @remarks + * Requires the `MANAGE_WEBHOOKS` permission in the __target channel__. + * + * Fires a _Webhooks Update_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/channel#follow-announcement-channel} + */ + follow: (sourceChannelId: BigString, targetChannelId: BigString) => Promise> /** Permission related helpers in a channel */ permissions: { /** @@ -1478,6 +1532,21 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions} */ editChannelPositions: (guildId: BigString, channelPositions: ModifyGuildChannelPositions[]) => Promise + /** + * Follows an announcement channel, allowing messages posted within it to be cross-posted into the target channel. + * + * @param sourceChannelId - The ID of the announcement channel to follow. + * @param targetChannelId - The ID of the target channel - the channel to cross-post to. + * @returns An instance of {@link DiscordFollowedChannel}. + * + * @remarks + * Requires the `MANAGE_WEBHOOKS` permission in the __target channel__. + * + * Fires a _Webhooks Update_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/channel#follow-announcement-channel} + */ + followAnnouncement: (sourceChannelId: BigString, targetChannelId: BigString) => Promise> /** * Gets the list of invites for a channel. * diff --git a/packages/types/src/discord.ts b/packages/types/src/discord.ts index 7b0669ed2..cc156ed93 100644 --- a/packages/types/src/discord.ts +++ b/packages/types/src/discord.ts @@ -2088,13 +2088,13 @@ export interface DiscordGuildPreview { // category_ids: number[] // } -// /** https://discord.com/developers/docs/resources/channel#followed-channel-object */ -// export interface DiscordFollowedChannel { -// /** Source message id */ -// channel_id: string -// /** Created target webhook id */ -// webhook_id: string -// } +/** https://discord.com/developers/docs/resources/channel#followed-channel-object */ +export interface DiscordFollowedChannel { + /** Source message id */ + channel_id: string + /** Created target webhook id */ + webhook_id: string +} /** https://discord.com/developers/docs/topics/gateway#payloads-gateway-payload-structure */ export interface DiscordGatewayPayload { @@ -2965,10 +2965,10 @@ export interface DiscordCreateMessage { // invitable?: boolean // } -// export interface DiscordFollowAnnouncementChannel { -// /** The id of the channel to send announcements to. */ -// webhook_channel_id: string -// } +export interface DiscordFollowAnnouncementChannel { + /** The id of the channel to send announcements to. */ + webhook_channel_id: string +} export interface DiscordEditChannelPermissionOverridesOptions { /** Permission bit set */