From fba1f7c6621575778c26a378b4d313febe894a42 Mon Sep 17 00:00:00 2001 From: bsian03 Date: Sun, 18 Apr 2021 22:53:42 +0100 Subject: [PATCH] Support welcome screen endpoints (#1179) --- index.d.ts | 11 +++++++++-- lib/Client.js | 37 +++++++++++++++++++++++++++++++++++++ lib/rest/Endpoints.js | 1 + lib/structures/Guild.js | 25 +++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index ac1ce7cb6..643e7c867 100644 --- a/index.d.ts +++ b/index.d.ts @@ -695,6 +695,9 @@ declare namespace Eris { description: string; welcomeChannels: WelcomeChannel[]; } + interface WelcomeScreenOptions extends WelcomeScreen { + enabled: boolean; + } interface Widget { channel_id?: string; enabled: boolean; @@ -1553,7 +1556,8 @@ declare namespace Eris { editGuildTemplate(guildID: string, code: string, options: GuildTemplateOptions): Promise; editGuildVanity(guildID: string, code: string): Promise; editGuildVoiceState(guildID: string, options: VoiceStateOptions, userID?: string): Promise; - editGuildWidget(guildID: string, options: Widget): Promise + editGuildWelcomeScreen(guildID: string, options: WelcomeScreenOptions): Promise; + editGuildWidget(guildID: string, options: Widget): Promise; editMessage(channelID: string, messageID: string, content: MessageContent): Promise; editNickname(guildID: string, nick: string, reason?: string): Promise; editRole(guildID: string, roleID: string, options: RoleOptions, reason?: string): Promise; // TODO not all options are available? @@ -1608,6 +1612,7 @@ declare namespace Eris { getGuildTemplates(guildID: string): Promise; getGuildVanity(guildID: string): Promise; getGuildWebhooks(guildID: string): Promise; + getGuildWelcomeScreen(guildID: string): Promise; getGuildWidget(guildID: string): Promise; getInvite(inviteID: string, withCounts?: false): Promise>; getInvite(inviteID: string, withCounts: true): Promise>; @@ -1933,8 +1938,9 @@ declare namespace Eris { editRole(roleID: string, options: RoleOptions): Promise; editTemplate(code: string, options: GuildTemplateOptions): Promise; editVanity(code: string): Promise; - editVoiceState(options: VoiceStateOptions, userID?: string): Promise; + editWelcomeScreen(options: WelcomeScreenOptions): Promise; editWidget(options: Widget): Promise; + editVoiceState(options: VoiceStateOptions, userID?: string): Promise; fetchAllMembers(timeout?: number): Promise; fetchMembers(options?: FetchMembersOptions): Promise; getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise; @@ -1956,6 +1962,7 @@ declare namespace Eris { getVanity(): Promise; getVoiceRegions(): Promise; getWebhooks(): Promise; + getWelcomeScreen(): Promise; getWidget(): Promise; kickMember(userID: string, reason?: string): Promise; leave(): Promise; diff --git a/lib/Client.js b/lib/Client.js index 362d91189..f0b0cb7b7 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1139,6 +1139,34 @@ class Client extends EventEmitter { }); } + /** + * Edit a guild welcome screen + * @arg {String} guildID The ID of the guild + * @arg {Object} [options] The properties to edit + * @arg {String?} [options.description] The description in the welcome screen + * @arg {Boolean} [options.enabled] Whether the welcome screen is enabled + * @arg {Array} [options.welcomeChannels] The list of channels in the welcome screen as an array + * @arg {String} options.welcomeChannels[].channelID The channel ID of the welcome channel + * @arg {String} options.welcomeChannels[].description The description of the welcome channel + * @arg {String?} options.welcomeChannels[].emojiID The emoji ID of the welcome channel + * @arg {String?} options.welcomeChannels[].emojiName The emoji name of the welcome channel + * @returns {Promise} + */ + editGuildWelcomeScreen(guildID, options) { + return this.requestHandler.request("PATCH", Endpoints.GUILD_WELCOME_SCREEN(guildID), true, { + description: options.description, + enabled: options.enabled, + welcome_channels: options.welcomeChannels.map((c) => { + return { + channel_id: c.channelID, + description: c.description, + emoji_id: c.emojiID, + emoji_name: c.emojiName + }; + }) + }); + } + /** * Modify a guild's widget * @arg {String} guildID The ID of the guild @@ -1734,6 +1762,15 @@ class Client extends EventEmitter { return this.requestHandler.request("GET", Endpoints.GUILD_WEBHOOKS(guildID), true); } + /** + * Get the welcome screen of a Community guild, shown to new members + * @param {String} guildID The ID of the guild to get the welcome screen for + * @returns {Promise} + */ + getGuildWelcomeScreen(guildID) { + return this.requestHandler.request("GET", Endpoints.GUILD_WELCOME_SCREEN(guildID), true); + } + /** * Get a guild's widget object * @arg {String} guildID The ID of the guild diff --git a/lib/rest/Endpoints.js b/lib/rest/Endpoints.js index 9de3c32c5..050444281 100644 --- a/lib/rest/Endpoints.js +++ b/lib/rest/Endpoints.js @@ -61,6 +61,7 @@ module.exports.GUILD_TEMPLATES = (guildID) module.exports.GUILD_TEMPLATE_GUILD = (guildID, code) => `/guilds/${guildID}/templates/${code}`; module.exports.GUILD_VOICE_REGIONS = (guildID) => `/guilds/${guildID}/regions`; module.exports.GUILD_WEBHOOKS = (guildID) => `/guilds/${guildID}/webhooks`; +module.exports.GUILD_WELCOME_SCREEN = (guildID) => `/guilds/${guildID}/welcome-screen`; module.exports.GUILD_WIDGET = (guildID) => `/guilds/${guildID}/widget`; module.exports.GUILD_VOICE_STATE = (guildID, user) => `/guilds/${guildID}/voice-states/${user}`; module.exports.GUILDS = "/guilds"; diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index 7bdc87537..90ad9dd7e 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -627,6 +627,23 @@ class Guild extends Base { return this._client.editGuildVoiceState.call(this._client, this.id, options, userID); } + /** + * Edit the guild welcome screen + * @arg {String} guildID The ID of the guild + * @arg {Object} [options] The properties to edit + * @arg {String?} [options.description] The description in the welcome screen + * @arg {Boolean} [options.enabled] Whether the welcome screen is enabled + * @arg {Array} [options.welcomeChannels] The list of channels in the welcome screen as an array + * @arg {String} options.welcomeChannels[].channelID The channel ID of the welcome channel + * @arg {String} options.welcomeChannels[].description The description of the welcome channel + * @arg {String?} options.welcomeChannels[].emojiID The emoji ID of the welcome channel + * @arg {String?} options.welcomeChannels[].emojiName The emoji name of the welcome channel + * @returns {Promise} + */ + editWelcomeScreen(options) { + return this._client.editGuildWelcomeScreen.call(this._client, this.id, options); + } + /** * Modify a guild's widget * @arg {Object} options The widget object to modify (https://discord.com/developers/docs/resources/guild#modify-guild-widget) @@ -820,6 +837,14 @@ class Guild extends Base { return this._client.getGuildWebhooks.call(this._client, this.id); } + /** + * Get the welcome screen of the Community guild, shown to new members + * @returns {Promise} + */ + getWelcomeScreen() { + return this._client.getGuildWelcomeScreen.call(this._client, this.id); + } + /** * Get a guild's widget object * @returns {Promise} A guild widget object