From 1b522a7e8a353dd0ddc050c832f6f86fd90e458e Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 11 Jan 2023 00:46:35 +0000 Subject: [PATCH] integrations helpers --- packages/rest/src/manager.ts | 124 ++++++++++++++++++++++++++++++----- 1 file changed, 107 insertions(+), 17 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 3b8f950a1..3ac813de8 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -20,6 +20,7 @@ import type { DiscordFollowAnnouncementChannel, DiscordFollowedChannel, DiscordGetGatewayBot, + DiscordIntegration, DiscordInviteMetadata, DiscordListActiveThreads, DiscordListArchivedThreads, @@ -293,6 +294,12 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return url }, }, + integration(guildId, integrationId) { + return `/guilds/${guildId}/integrations/${integrationId}` + }, + integrations: (guildId) => { + return `/guilds/${guildId}/integrations?include_applications=true` + }, webhooks: (guildId) => { return `/guilds/${guildId}/webhooks` }, @@ -798,6 +805,16 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }, }, }, + + integrations: { + async get(guildId) { + return await rest.getIntegrations(guildId) + }, + + async delete(guildId, integrationId) { + return await rest.deleteIntegration(guildId, integrationId) + }, + }, }, webhooks: { @@ -930,6 +947,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.delete(rest.routes.guilds.emoji(guildId, id), { reason }) }, + async deleteIntegration(guildId, integrationId) { + return await rest.delete(rest.routes.guilds.integration(guildId, integrationId)) + }, + async deleteScheduledEvent(guildId, eventId) { return await rest.delete(rest.routes.guilds.events.event(guildId, eventId)) }, @@ -1067,6 +1088,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.get(rest.routes.guilds.webhooks(guildId)) }, + async getIntegrations(guildId) { + return await rest.get(rest.routes.guilds.integrations(guildId)) + }, + async getNitroStickerPacks() { return await rest.get(rest.routes.nitroStickerPacks()) }, @@ -1298,6 +1323,10 @@ export interface RestManager { emoji: (guildId: BigString, id: BigString) => string /** Route for handling non-specific emojis. */ emojis: (guildId: BigString) => string + /** Route for handling a specific integration. */ + integration: (guildId: BigString, integrationId: BigString) => string + /** Route for handling non-specific integrations. */ + integrations: (guildId: BigString) => string /** Route for handling non-specific webhooks in a guild */ webhooks: (guildId: BigString) => string } @@ -1578,7 +1607,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/channel#list-thread-members} */ - members: (channelId: BigString) => Promise>> + members: (channelId: BigString) => Promise> } /** * Adds the bot user to a thread. @@ -1693,7 +1722,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites} */ - invites: (channelId: BigString) => Promise>> + invites: (channelId: BigString) => Promise> /** Stage related helpers for a channel. */ stages: { /** @@ -1895,7 +1924,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild} */ - rules: (guildId: BigString) => Promise>> + rules: (guildId: BigString) => Promise> } } /** @@ -1909,7 +1938,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/guild#get-guild-channels} */ - channels: (guildId: BigString) => Promise>> + channels: (guildId: BigString) => Promise> /** * Gets the list of emojis for a guild. * @@ -1918,7 +1947,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/emoji#list-guild-emojis} */ - emojis: (guildId: BigString) => Promise>> + emojis: (guildId: BigString) => Promise> /** Methods related to a guild's scheduled events. */ events: { /** @@ -1993,7 +2022,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/guild-scheduled-event#list-scheduled-events-for-guild} */ - events: (guildId: BigString, options?: GetScheduledEvents) => Promise>> + events: (guildId: BigString, options?: GetScheduledEvents) => Promise> /** * Gets the list of subscribers to a scheduled event from a guild. * @@ -2016,6 +2045,38 @@ export interface RestManager { ) => Promise; member?: Camelize }>> } } + /** Methods related to a guild's integrations. */ + integrations: { + /** + * Gets the list of integrations attached to a guild. + * + * @param guildId - The ID of the guild to get the list of integrations from. + * @returns A collection of {@link Integration} objects assorted by integration ID. + * + * @remarks + * Requires the `MANAGE_GUILD` permission. + * + * @see {@link https://discord.com/developers/docs/resources/guild#get-guild-integrations} + */ + get: (guildId: BigString) => Promise> + /** + * Deletes an integration attached to a guild. + * + * @param guildId - The ID of the guild from which to delete the integration. + * @param integrationId - The ID of the integration to delete from the guild. + * + * @remarks + * Requires the `MANAGE_GUILD` permission. + * + * Deletes all webhooks associated with the integration, and kicks the associated bot if there is one. + * + * Fires a _Guild Integrations Update_ gateway event. + * Fires a _Integration Delete_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/guild#delete-guild-integration} + */ + delete: (guildId: BigString, integrationId: BigString) => Promise + } } /** Webhook related helper methods. */ webhooks: { @@ -2128,7 +2189,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/webhook#get-channel-webhooks} */ - channel: (channelId: BigString) => Promise>> + channel: (channelId: BigString) => Promise> /** * Gets the list of webhooks for a guild. * @@ -2140,7 +2201,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/webhook#get-guild-webhooks} */ - guild: (guildId: BigString) => Promise>> + guild: (guildId: BigString) => Promise> /** * Gets a webhook message by its ID. * @@ -2397,6 +2458,23 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/emoji#delete-guild-emoji} */ deleteEmoji: (guildId: BigString, id: BigString, reason?: string) => Promise + /** + * Deletes an integration attached to a guild. + * + * @param guildId - The ID of the guild from which to delete the integration. + * @param integrationId - The ID of the integration to delete from the guild. + * + * @remarks + * Requires the `MANAGE_GUILD` permission. + * + * Deletes all webhooks associated with the integration, and kicks the associated bot if there is one. + * + * Fires a _Guild Integrations Update_ gateway event. + * Fires a _Integration Delete_ gateway event. + * + * @see {@link https://discord.com/developers/docs/resources/guild#delete-guild-integration} + */ + deleteIntegration: (guildId: BigString, integrationId: BigString) => Promise /** * Deletes a scheduled event from a guild. * @@ -2733,7 +2811,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild} */ - getAutomodRules: (guildId: BigString) => Promise>> + getAutomodRules: (guildId: BigString) => Promise> /** * Gets a channel by its ID. * @@ -2759,7 +2837,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites} */ - getChannelInvites: (channelId: BigString) => Promise>> + getChannelInvites: (channelId: BigString) => Promise> /** * Gets the list of channels for a guild. * @@ -2771,7 +2849,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/guild#get-guild-channels} */ - getChannels: (guildId: BigString) => Promise>> + getChannels: (guildId: BigString) => Promise> /** * Gets a list of webhooks for a channel. * @@ -2783,7 +2861,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/webhook#get-channel-webhooks} */ - getChannelWebhooks: (channelId: BigString) => Promise>> + getChannelWebhooks: (channelId: BigString) => Promise> /** * Gets an emoji by its ID. * @@ -2802,7 +2880,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/emoji#list-guild-emojis} */ - getEmojis: (guildId: BigString) => Promise>> + getEmojis: (guildId: BigString) => Promise> /** Get the bots Gateway metadata that can help during the operation of large or sharded bots. */ getGatewayBot: () => Promise> /** @@ -2816,7 +2894,19 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/webhook#get-guild-webhooks} */ - getGuildWebhooks: (guildId: BigString) => Promise>> + getGuildWebhooks: (guildId: BigString) => Promise> + /** + * Gets the list of integrations attached to a guild. + * + * @param guildId - The ID of the guild to get the list of integrations from. + * @returns A collection of {@link Integration} objects assorted by integration ID. + * + * @remarks + * Requires the `MANAGE_GUILD` permission. + * + * @see {@link https://discord.com/developers/docs/resources/guild#get-guild-integrations} + */ + getIntegrations: (guildId: BigString) => Promise> /** * Returns the list of sticker packs available to Nitro subscribers. * @@ -2825,7 +2915,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs} */ - getNitroStickerPacks: () => Promise>> + getNitroStickerPacks: () => Promise> /** * Gets the list of private archived threads for a channel. * @@ -2899,7 +2989,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/guild-scheduled-event#list-scheduled-events-for-guild} */ - getScheduledEvents: (guildId: BigString, options?: GetScheduledEvents) => Promise>> + getScheduledEvents: (guildId: BigString, options?: GetScheduledEvents) => Promise> /** * Gets the list of subscribers to a scheduled event from a guild. * @@ -2952,7 +3042,7 @@ export interface RestManager { * * @see {@link https://discord.com/developers/docs/resources/channel#list-thread-members} */ - getThreadMembers: (channelId: BigString) => Promise>> + getThreadMembers: (channelId: BigString) => Promise> /** * Get a user's data from the api *