From 0415300243877ddbcb501c0a26b1ff65618a1da7 Mon Sep 17 00:00:00 2001 From: pat <73502164+nyapat@users.noreply.github.com> Date: Fri, 10 Jun 2022 06:42:53 -0500 Subject: [PATCH] feat(vcs): add missing property and methods (#8002) --- .../src/structures/BaseGuildTextChannel.js | 12 ++-------- .../discord.js/src/structures/DMChannel.js | 10 ++++++++- .../src/structures/ThreadChannel.js | 4 +++- .../discord.js/src/structures/VoiceChannel.js | 10 +++++++++ .../structures/interfaces/TextBasedChannel.js | 22 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 17 +++++++++----- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/packages/discord.js/src/structures/BaseGuildTextChannel.js b/packages/discord.js/src/structures/BaseGuildTextChannel.js index a7f274b97..06e5473bc 100644 --- a/packages/discord.js/src/structures/BaseGuildTextChannel.js +++ b/packages/discord.js/src/structures/BaseGuildTextChannel.js @@ -89,16 +89,6 @@ class BaseGuildTextChannel extends GuildChannel { return this.edit({ defaultAutoArchiveDuration }, reason); } - /** - * Sets whether this channel is flagged as NSFW. - * @param {boolean} [nsfw=true] Whether the channel should be considered NSFW - * @param {string} [reason] Reason for changing the channel's NSFW flag - * @returns {Promise} - */ - setNSFW(nsfw = true, reason) { - return this.edit({ nsfw }, reason); - } - /** * Sets the type of this channel (only conversion between text and news is supported) * @param {string} type The new channel type @@ -186,6 +176,8 @@ class BaseGuildTextChannel extends GuildChannel { bulkDelete() {} fetchWebhooks() {} createWebhook() {} + setRateLimitPerUser() {} + setNSFW() {} } TextBasedChannel.applyToClass(BaseGuildTextChannel, true); diff --git a/packages/discord.js/src/structures/DMChannel.js b/packages/discord.js/src/structures/DMChannel.js index b7b35290f..81da5e8b8 100644 --- a/packages/discord.js/src/structures/DMChannel.js +++ b/packages/discord.js/src/structures/DMChannel.js @@ -114,8 +114,16 @@ class DMChannel extends Channel { // Doesn't work on DM channels; bulkDelete() {} // Doesn't work on DM channels; fetchWebhooks() {} // Doesn't work on DM channels; createWebhook() {} + // Doesn't work on DM channels; setRateLimitPerUser() {} + // Doesn't work on DM channels; setNSFW() {} } -TextBasedChannel.applyToClass(DMChannel, true, ['bulkDelete', 'fetchWebhooks', 'createWebhook']); +TextBasedChannel.applyToClass(DMChannel, true, [ + 'bulkDelete', + 'fetchWebhooks', + 'createWebhook', + 'setRateLimitPerUser', + 'setNSFW', +]); module.exports = DMChannel; diff --git a/packages/discord.js/src/structures/ThreadChannel.js b/packages/discord.js/src/structures/ThreadChannel.js index 2f51fa313..717af2c31 100644 --- a/packages/discord.js/src/structures/ThreadChannel.js +++ b/packages/discord.js/src/structures/ThreadChannel.js @@ -537,8 +537,10 @@ class ThreadChannel extends Channel { createMessageComponentCollector() {} awaitMessageComponent() {} bulkDelete() {} + // Doesn't work on Thread channels; setRateLimitPerUser() {} + // Doesn't work on Thread channels; setNSFW() {} } -TextBasedChannel.applyToClass(ThreadChannel, true); +TextBasedChannel.applyToClass(ThreadChannel, true, ['setRateLimitPerUser', 'setNSFW']); module.exports = ThreadChannel; diff --git a/packages/discord.js/src/structures/VoiceChannel.js b/packages/discord.js/src/structures/VoiceChannel.js index f8220d446..1141d5931 100644 --- a/packages/discord.js/src/structures/VoiceChannel.js +++ b/packages/discord.js/src/structures/VoiceChannel.js @@ -47,6 +47,14 @@ class VoiceChannel extends BaseGuildVoiceChannel { if ('messages' in data) { for (const message of data.messages) this.messages._add(message); } + + if ('rate_limit_per_user' in data) { + /** + * The rate limit per user (slowmode) for this channel in seconds + * @type {number} + */ + this.rateLimitPerUser = data.rate_limit_per_user; + } } /** @@ -129,6 +137,8 @@ class VoiceChannel extends BaseGuildVoiceChannel { bulkDelete() {} fetchWebhooks() {} createWebhook() {} + setRateLimitPerUser() {} + setNSFW() {} /** * Sets the RTC region of the channel. diff --git a/packages/discord.js/src/structures/interfaces/TextBasedChannel.js b/packages/discord.js/src/structures/interfaces/TextBasedChannel.js index 793ffbdf1..2510ae054 100644 --- a/packages/discord.js/src/structures/interfaces/TextBasedChannel.js +++ b/packages/discord.js/src/structures/interfaces/TextBasedChannel.js @@ -367,6 +367,26 @@ class TextBasedChannel { return this.guild.channels.createWebhook(this.id, name, options); } + /** + * Sets the rate limit per user (slowmode) for this channel. + * @param {number} rateLimitPerUser The new rate limit in seconds + * @param {string} [reason] Reason for changing the channel's rate limit + * @returns {Promise} + */ + setRateLimitPerUser(rateLimitPerUser, reason) { + return this.edit({ rateLimitPerUser }, reason); + } + + /** + * Sets whether this channel is flagged as NSFW. + * @param {boolean} [nsfw=true] Whether the channel should be considered NSFW + * @param {string} [reason] Reason for changing the channel's NSFW flag + * @returns {Promise} + */ + setNSFW(nsfw = true, reason) { + return this.edit({ nsfw }, reason); + } + static applyToClass(structure, full = false, ignore = []) { const props = ['send']; if (full) { @@ -381,6 +401,8 @@ class TextBasedChannel { 'awaitMessageComponent', 'fetchWebhooks', 'createWebhook', + 'setRateLimitPerUser', + 'setNSFW', ); } for (const prop of props) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index f13528dbd..65a790c55 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -514,6 +514,7 @@ export class BaseGuildEmoji extends Emoji { export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) { protected constructor(guild: Guild, data?: RawGuildChannelData, client?: Client, immediatePatch?: boolean); public defaultAutoArchiveDuration?: ThreadAutoArchiveDuration; + public rateLimitPerUser: number | null; public nsfw: boolean; public threads: ThreadManager; public topic: string | null; @@ -523,7 +524,6 @@ export class BaseGuildTextChannel extends TextBasedChannelMixin(GuildChannel) { defaultAutoArchiveDuration: ThreadAutoArchiveDuration, reason?: string, ): Promise; - public setNSFW(nsfw?: boolean, reason?: string): Promise; public setTopic(topic: string | null, reason?: string): Promise; public setType(type: Pick, reason?: string): Promise; public setType(type: Pick, reason?: string): Promise; @@ -1036,7 +1036,13 @@ export class DataResolver extends null { public static resolveGuildTemplateCode(data: GuildTemplateResolvable): string; } -export class DMChannel extends TextBasedChannelMixin(Channel, ['bulkDelete', 'fetchWebhooks', 'createWebhook']) { +export class DMChannel extends TextBasedChannelMixin(Channel, [ + 'bulkDelete', + 'fetchWebhooks', + 'createWebhook', + 'setRateLimitPerUser', + 'setNSFW', +]) { private constructor(client: Client, data?: RawDMChannelData); public recipientId: Snowflake; public get recipient(): User | null; @@ -2449,7 +2455,6 @@ export class TextChannel extends BaseGuildTextChannel { public rateLimitPerUser: number; public threads: ThreadManager; public type: ChannelType.GuildText; - public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; } export type AnyThreadChannel = PublicThreadChannel | PrivateThreadChannel; @@ -2464,7 +2469,7 @@ export interface PrivateThreadChannel extends ThreadChannel { type: ChannelType.GuildPrivateThread; } -export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhooks', 'createWebhook']) { +export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhooks', 'createWebhook', 'setNSFW']) { private constructor(guild: Guild, data?: RawThreadChannelData, client?: Client, fromInteraction?: boolean); public archived: boolean | null; public get archivedAt(): Date | null; @@ -2513,7 +2518,6 @@ export class ThreadChannel extends TextBasedChannelMixin(Channel, ['fetchWebhook public setInvitable(invitable?: boolean, reason?: string): Promise; public setLocked(locked?: boolean, reason?: string): Promise; public setName(name: string, reason?: string): Promise; - public setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; public toString(): ChannelMention; } @@ -2696,6 +2700,7 @@ export class VoiceChannel extends TextBasedChannelMixin(BaseGuildVoiceChannel, [ public videoQualityMode: VideoQualityMode | null; public get speakable(): boolean; public type: ChannelType.GuildVoice; + public rateLimitPerUser: number | null; public setBitrate(bitrate: number, reason?: string): Promise; public setUserLimit(userLimit: number, reason?: string): Promise; public setVideoQualityMode(videoQualityMode: VideoQualityMode, reason?: string): Promise; @@ -3465,6 +3470,8 @@ export interface TextBasedChannelFields extends PartialTextBasedChannelFields { createWebhook(name: string, options?: ChannelWebhookCreateOptions): Promise; fetchWebhooks(): Promise>; sendTyping(): Promise; + setRateLimitPerUser(rateLimitPerUser: number, reason?: string): Promise; + setNSFW(nsfw?: boolean, reason?: string): Promise; } export function PartialWebhookMixin(Base?: Constructable): Constructable;