fix: follow announcement helper

This commit is contained in:
Skillz4Killz
2023-01-10 17:36:10 +00:00
parent dcf3b8250b
commit 9cf221aa82
2 changed files with 80 additions and 11 deletions

View File

@@ -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<DiscordFollowedChannel>(rest.routes.channels.follow(sourceChannelId), {
webhook_channel_id: targetChannelId,
} as DiscordFollowAnnouncementChannel)
},
async getChannelInvites(channelId) {
return await rest.get<DiscordInviteMetadata[]>(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<Camelize<DiscordChannel>>
/**
* 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<Camelize<DiscordFollowedChannel>>
/** 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<void>
/**
* 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<Camelize<DiscordFollowedChannel>>
/**
* Gets the list of invites for a channel.
*

View File

@@ -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 */