Skip to content

Commit

Permalink
fix: missed enums and typings from #7290 (#7331)
Browse files Browse the repository at this point in the history
  • Loading branch information
IRONM00N committed Jan 25, 2022
1 parent 6725038 commit 47633f0
Show file tree
Hide file tree
Showing 17 changed files with 337 additions and 179 deletions.
25 changes: 7 additions & 18 deletions packages/discord.js/src/managers/GuildScheduledEventManager.js
@@ -1,11 +1,7 @@
'use strict';

const { Collection } = require('@discordjs/collection');
const {
GuildScheduledEventPrivacyLevel,
GuildScheduledEventEntityType,
GuildScheduledEventStatus,
} = require('discord-api-types/v9');
const { GuildScheduledEventEntityType } = require('discord-api-types/v9');
const CachedManager = require('./CachedManager');
const { TypeError, Error } = require('../errors');
const { GuildScheduledEvent } = require('../structures/GuildScheduledEvent');
Expand Down Expand Up @@ -44,24 +40,24 @@ class GuildScheduledEventManager extends CachedManager {
* @property {string} name The name of the guild scheduled event
* @property {DateResolvable} scheduledStartTime The time to schedule the event at
* @property {DateResolvable} [scheduledEndTime] The time to end the event at
* <warn>This is required if `entityType` is `GuildScheduledEventEntityType.External`</warn>
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.External}</warn>
* @property {PrivacyLevel|number} privacyLevel The privacy level of the guild scheduled event
* @property {GuildScheduledEventEntityType|number} entityType The scheduled entity type of the event
* @property {string} [description] The description of the guild scheduled event
* @property {GuildVoiceChannelResolvable} [channel] The channel of the guild scheduled event
* <warn>This is required if `entityType` is `GuildScheduledEventEntityType.StageInstance` or
* `GuildScheduledEventEntityType.Voice`</warn>
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.StageInstance} or
* {@link GuildScheduledEventEntityType.Voice}</warn>
* @property {GuildScheduledEventEntityMetadataOptions} [entityMetadata] The entity metadata of the
* guild scheduled event
* <warn>This is required if `entityType` is `GuildScheduledEventEntityType.External`</warn>
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.External}</warn>
* @property {string} [reason] The reason for creating the guild scheduled event
*/

/**
* Options used to set entity metadata of a guild scheduled event.
* @typedef {Object} GuildScheduledEventEntityMetadataOptions
* @property {string} [location] The location of the guild scheduled event
* <warn>This is required if `entityType` is `GuildScheduledEventEntityType.External`</warn>
* <warn>This is required if `entityType` is {@link GuildScheduledEventEntityType.External}</warn>
*/

/**
Expand All @@ -83,9 +79,6 @@ class GuildScheduledEventManager extends CachedManager {
reason,
} = options;

if (typeof privacyLevel === 'string') privacyLevel = GuildScheduledEventPrivacyLevel[privacyLevel];
if (typeof entityType === 'string') entityType = GuildScheduledEventEntityType[entityType];

let entity_metadata, channel_id;
if (entityType === GuildScheduledEventEntityType.External) {
channel_id = typeof channel === 'undefined' ? channel : null;
Expand Down Expand Up @@ -177,7 +170,7 @@ class GuildScheduledEventManager extends CachedManager {
* @property {GuildScheduledEventEntityMetadataOptions} [entityMetadata] The entity metadata of the
* guild scheduled event
* <warn>This can be modified only if `entityType` of the `GuildScheduledEvent` to be edited is
* `GuildScheduledEventEntityType.External`</warn>
* {@link GuildScheduledEventEntityType.External}</warn>
* @property {string} [reason] The reason for editing the guild scheduled event
*/

Expand Down Expand Up @@ -205,10 +198,6 @@ class GuildScheduledEventManager extends CachedManager {
reason,
} = options;

if (typeof privacyLevel === 'string') privacyLevel = GuildScheduledEventPrivacyLevel[privacyLevel];
if (typeof entityType === 'string') entityType = GuildScheduledEventEntityType[entityType];
if (typeof status === 'string') status = GuildScheduledEventStatus[status];

let entity_metadata;
if (entityMetadata) {
entity_metadata = {
Expand Down
5 changes: 0 additions & 5 deletions packages/discord.js/src/managers/StageInstanceManager.js
@@ -1,6 +1,5 @@
'use strict';

const { GuildScheduledEventPrivacyLevel } = require('discord-api-types/v9');
const CachedManager = require('./CachedManager');
const { TypeError, Error } = require('../errors');
const { StageInstance } = require('../structures/StageInstance');
Expand Down Expand Up @@ -60,8 +59,6 @@ class StageInstanceManager extends CachedManager {
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
let { topic, privacyLevel } = options;

privacyLevel &&= typeof privacyLevel === 'number' ? privacyLevel : GuildScheduledEventPrivacyLevel[privacyLevel];

const data = await this.client.api['stage-instances'].post({
data: {
channel_id: channelId,
Expand Down Expand Up @@ -122,8 +119,6 @@ class StageInstanceManager extends CachedManager {

let { topic, privacyLevel } = options;

privacyLevel &&= typeof privacyLevel === 'number' ? privacyLevel : GuildScheduledEventPrivacyLevel[privacyLevel];

const data = await this.client.api('stage-instances', channelId).patch({
data: {
topic,
Expand Down
9 changes: 5 additions & 4 deletions packages/discord.js/src/managers/ThreadManager.js
Expand Up @@ -64,11 +64,12 @@ class ThreadManager extends CachedManager {
* @typedef {StartThreadOptions} ThreadCreateOptions
* @property {MessageResolvable} [startMessage] The message to start a thread from. <warn>If this is defined then type
* of thread gets automatically defined and cannot be changed. The provided `type` field will be ignored</warn>
* @property {ThreadChannelTypes|number} [type] The type of thread to create. Defaults to `GUILD_PUBLIC_THREAD` if
* created in a {@link TextChannel} <warn>When creating threads in a {@link NewsChannel} this is ignored and is always
* `GUILD_NEWS_THREAD`</warn>
* @property {ThreadChannelTypes|number} [type] The type of thread to create.
* Defaults to {@link ChannelType.GuildPublicThread} if created in a {@link TextChannel}
* <warn>When creating threads in a {@link NewsChannel} this is ignored and is always
* {@link ChannelType.GuildNewsThread}</warn>
* @property {boolean} [invitable] Whether non-moderators can add other non-moderators to the thread
* <info>Can only be set when type will be `GUILD_PRIVATE_THREAD`</info>
* <info>Can only be set when type will be {@link ChannelType.GuildPrivateThread}</info>
* @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the new channel in seconds
*/

Expand Down
24 changes: 12 additions & 12 deletions packages/discord.js/src/structures/ApplicationCommand.js
@@ -1,7 +1,7 @@
'use strict';

const { DiscordSnowflake } = require('@sapphire/snowflake');
const { ApplicationCommandOptionType, ChannelType } = require('discord-api-types/v9');
const { ApplicationCommandOptionType } = require('discord-api-types/v9');
const Base = require('./Base');
const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');

Expand Down Expand Up @@ -141,17 +141,19 @@ class ApplicationCommand extends Base {
* <warn>Note that providing a value for the `camelCase` counterpart for any `snake_case` property
* will discard the provided `snake_case` property.</warn>
* @typedef {Object} ApplicationCommandOptionData
* @property {ApplicationCommandOptionType|number} type The type of the option
* @property {ApplicationCommandOptionType} type The type of the option
* @property {string} name The name of the option
* @property {string} description The description of the option
* @property {boolean} [autocomplete] Whether the option is an autocomplete option
* @property {boolean} [required] Whether the option is required
* @property {ApplicationCommandOptionChoice[]} [choices] The choices of the option for the user to pick from
* @property {ApplicationCommandOptionData[]} [options] Additional options if this option is a subcommand (group)
* @property {ChannelType[]|number[]} [channelTypes] When the option type is channel,
* @property {ChannelType[]} [channelTypes] When the option type is channel,
* the allowed types of channels that can be selected
* @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option
* @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option
* @property {number} [minValue] The minimum value for an {@link ApplicationCommandOptionType.Integer} or
* {@link ApplicationCommandOptionType.Number} option
* @property {number} [maxValue] The maximum value for an {@link ApplicationCommandOptionType.Integer} or
* {@link ApplicationCommandOptionType.Number} option
*/

/**
Expand Down Expand Up @@ -349,8 +351,10 @@ class ApplicationCommand extends Base {
* @property {ApplicationCommandOption[]} [options] Additional options if this option is a subcommand (group)
* @property {ChannelType[]} [channelTypes] When the option type is channel,
* the allowed types of channels that can be selected
* @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option
* @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option
* @property {number} [minValue] The minimum value for an {@link ApplicationCommandOptionType.Integer} or
* {@link ApplicationCommandOptionType.Number} option
* @property {number} [maxValue] The maximum value for an {@link ApplicationCommandOptionType.Integer} or
* {@link ApplicationCommandOptionType.Number} option
*/

/**
Expand Down Expand Up @@ -384,11 +388,7 @@ class ApplicationCommand extends Base {
autocomplete: option.autocomplete,
choices: option.choices,
options: option.options?.map(o => this.transformOption(o, received)),
[channelTypesKey]: received
? option.channel_types?.map(type => ChannelType[type])
: option.channelTypes?.map(type => (typeof type === 'string' ? ChannelType[type] : type)) ??
// When transforming to API data, accept API data
option.channel_types,
[channelTypesKey]: option.channelTypes ?? option.channel_types,
[minValueKey]: option.minValue ?? option.min_value,
[maxValueKey]: option.maxValue ?? option.max_value,
};
Expand Down
5 changes: 3 additions & 2 deletions packages/discord.js/src/structures/BaseGuildTextChannel.js
Expand Up @@ -187,9 +187,10 @@ class BaseGuildTextChannel extends GuildChannel {
* @property {number} [maxUses=0] Maximum number of uses
* @property {boolean} [unique=false] Create a unique invite, or use an existing one with similar settings
* @property {UserResolvable} [targetUser] The user whose stream to display for this invite,
* required if `targetType` is `STREAM`, the user must be streaming in the channel
* required if `targetType` is {@link InviteTargetType.Stream}, the user must be streaming in the channel
* @property {ApplicationResolvable} [targetApplication] The embedded application to open for this invite,
* required if `targetType` is `EMBEDDED_APPLICATION`, the application must have the `EMBEDDED` flag
* required if `targetType` is {@link InviteTargetType.Stream}, the application must have the
* {@link InviteTargetType.EmbeddedApplication} flag
* @property {InviteTargetType} [targetType] The type of the target for this voice channel invite
* @property {string} [reason] The reason for creating the invite
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/src/structures/CategoryChannel.js
Expand Up @@ -45,7 +45,8 @@ class CategoryChannel extends GuildChannel {

/**
* Creates a new channel within this category.
* <info>You cannot create a channel of type `GUILD_CATEGORY` inside a CategoryChannel.</info>
* <info>You cannot create a channel of type {@link ChannelType.GuildCategory} inside a
* CategoryChannel.</info>
* @param {string} name The name of the new channel
* @param {CategoryCreateChannelOptions} options Options for creating the new channel
* @returns {Promise<GuildChannel>}
Expand Down
Expand Up @@ -28,7 +28,8 @@ class ContextMenuCommandInteraction extends CommandInteraction {
this.targetId = data.data.target_id;

/**
* The type of the target of the interaction; either `.User` or `.Message`
* The type of the target of the interaction; either {@link ApplicationCommandType.User}
* or {@link ApplicationCommandType.Message}
* @type {ApplicationCommandType.User|ApplicationCommandType.Message}
*/
this.targetType = data.data.type;
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Guild.js
Expand Up @@ -971,7 +971,7 @@ class Guild extends AnonymousGuild {

/**
* Edits the verification level of the guild.
* @param {VerificationLevel|number} verificationLevel The new verification level of the guild
* @param {VerificationLevel} verificationLevel The new verification level of the guild
* @param {string} [reason] Reason for changing the guild's verification level
* @returns {Promise<Guild>}
* @example
Expand Down
36 changes: 17 additions & 19 deletions packages/discord.js/src/structures/GuildScheduledEvent.js
@@ -1,11 +1,7 @@
'use strict';

const { DiscordSnowflake } = require('@sapphire/snowflake');
const {
GuildScheduledEventPrivacyLevel,
GuildScheduledEventStatus,
GuildScheduledEventEntityType,
} = require('discord-api-types/v9');
const { GuildScheduledEventStatus, GuildScheduledEventEntityType } = require('discord-api-types/v9');
const Base = require('./Base');
const { Error } = require('../errors');
const { Endpoints } = require('../util/Constants');
Expand Down Expand Up @@ -36,7 +32,8 @@ class GuildScheduledEvent extends Base {
_patch(data) {
if ('channel_id' in data) {
/**
* The channel id in which the scheduled event will be hosted, or `null` if entity type is `EXTERNAL`
* The channel id in which the scheduled event will be hosted,
* or `null` if entity type is {@link GuildScheduledEventEntityType.External}
* @type {?Snowflake}
*/
this.channelId = data.channel_id;
Expand Down Expand Up @@ -86,21 +83,21 @@ class GuildScheduledEvent extends Base {

/**
* The privacy level of the guild scheduled event
* @type {PrivacyLevel}
* @type {GuildScheduledEventPrivacyLevel}
*/
this.privacyLevel = GuildScheduledEventPrivacyLevel[data.privacy_level];
this.privacyLevel = data.privacy_level;

/**
* The status of the guild scheduled event
* @type {GuildScheduledEventStatus}
*/
this.status = GuildScheduledEventStatus[data.status];
this.status = data.status;

/**
* The type of hosting entity associated with the scheduled event
* @type {GuildScheduledEventEntityType}
*/
this.entityType = GuildScheduledEventEntityType[data.entity_type];
this.entityType = data.entity_type;

if ('entity_id' in data) {
/**
Expand Down Expand Up @@ -226,7 +223,8 @@ class GuildScheduledEvent extends Base {
* Options used to create an invite URL to a {@link GuildScheduledEvent}
* @typedef {CreateInviteOptions} CreateGuildScheduledEventInviteURLOptions
* @property {GuildInvitableChannelResolvable} [channel] The channel to create the invite in.
* <warn>This is required when the `entityType` of `GuildScheduledEvent` is `EXTERNAL`, gets ignored otherwise</warn>
* <warn>This is required when the `entityType` of `GuildScheduledEvent` is
* {@link GuildScheduledEventEntityType.External}, gets ignored otherwise</warn>
*/

/**
Expand Down Expand Up @@ -387,35 +385,35 @@ class GuildScheduledEvent extends Base {
}

/**
* Indicates whether this guild scheduled event has an `ACTIVE` status.
* Indicates whether this guild scheduled event has an {@link GuildScheduledEventStatus.Active} status.
* @returns {boolean}
*/
isActive() {
return GuildScheduledEventStatus[this.status] === GuildScheduledEventStatus.Active;
return this.status === GuildScheduledEventStatus.Active;
}

/**
* Indicates whether this guild scheduled event has a `CANCELED` status.
* Indicates whether this guild scheduled event has a {@link GuildScheduledEventStatus.Canceled} status.
* @returns {boolean}
*/
isCanceled() {
return GuildScheduledEventStatus[this.status] === GuildScheduledEventStatus.Canceled;
return this.status === GuildScheduledEventStatus.Canceled;
}

/**
* Indicates whether this guild scheduled event has a `COMPLETED` status.
* Indicates whether this guild scheduled event has a {@link GuildScheduledEventStatus.Completed} status.
* @returns {boolean}
*/
isCompleted() {
return GuildScheduledEventStatus[this.status] === GuildScheduledEventStatus.Completed;
return this.status === GuildScheduledEventStatus.Completed;
}

/**
* Indicates whether this guild scheduled event has a `SCHEDULED` status.
* Indicates whether this guild scheduled event has a {@link GuildScheduledEventStatus.Scheduled} status.
* @returns {boolean}
*/
isScheduled() {
return GuildScheduledEventStatus[this.status] === GuildScheduledEventStatus.Scheduled;
return this.status === GuildScheduledEventStatus.Scheduled;
}
}

Expand Down
13 changes: 4 additions & 9 deletions packages/discord.js/src/structures/InteractionCollector.js
@@ -1,14 +1,13 @@
'use strict';

const { Collection } = require('@discordjs/collection');
const { InteractionType, ComponentType } = require('discord-api-types/v9');
const Collector = require('./interfaces/Collector');
const { Events } = require('../util/Constants');

/**
* @typedef {CollectorOptions} InteractionCollectorOptions
* @property {TextBasedChannels} [channel] The channel to listen to interactions from
* @property {MessageComponentType} [componentType] The type of component to listen for
* @property {ComponentType} [componentType] The type of component to listen for
* @property {Guild} [guild] The guild to listen to interactions from
* @property {InteractionType} [interactionType] The type of interaction to listen for
* @property {number} [max] The maximum total amount of interactions to collect
Expand Down Expand Up @@ -64,17 +63,13 @@ class InteractionCollector extends Collector {
* The type of interaction to collect
* @type {?InteractionType}
*/
this.interactionType =
typeof options.interactionType === 'number'
? InteractionType[options.interactionType]
: options.interactionType ?? null;
this.interactionType = options.interactionType ?? null;

/**
* The type of component to collect
* @type {?MessageComponentType}
* @type {?ComponentType}
*/
this.componentType =
typeof options.componentType === 'number' ? ComponentType[options.componentType] : options.componentType ?? null;
this.componentType = options.componentType ?? null;

/**
* The users that have interacted with this collector
Expand Down
12 changes: 6 additions & 6 deletions packages/discord.js/src/structures/Message.js
Expand Up @@ -288,10 +288,10 @@ class Message extends Base {
* Reference data sent in a message that contains ids identifying the referenced message.
* This can be present in the following types of message:
* * Crossposted messages (IS_CROSSPOST {@link MessageFlags.FLAGS message flag})
* * CHANNEL_FOLLOW_ADD
* * CHANNEL_PINNED_MESSAGE
* * REPLY
* * THREAD_STARTER_MESSAGE
* * {@link MessageType.ChannelFollowAdd}
* * {@link MessageType.ChannelPinnedMessage}
* * {@link MessageType.Reply}
* * {@link MessageType.ThreadStarterMessage}
* @see {@link https://discord.com/developers/docs/resources/channel#message-types}
* @typedef {Object} MessageReference
* @property {Snowflake} channelId The channel's id the message was referenced
Expand Down Expand Up @@ -482,7 +482,7 @@ class Message extends Base {

/**
* @typedef {CollectorOptions} MessageComponentCollectorOptions
* @property {MessageComponentType} [componentType] The type of component to listen for
* @property {ComponentType} [componentType] The type of component to listen for
* @property {number} [max] The maximum total amount of interactions to collect
* @property {number} [maxComponents] The maximum number of components to collect
* @property {number} [maxUsers] The maximum number of users to interact
Expand Down Expand Up @@ -512,7 +512,7 @@ class Message extends Base {
* @typedef {Object} AwaitMessageComponentOptions
* @property {CollectorFilter} [filter] The filter applied to this collector
* @property {number} [time] Time to wait for an interaction before rejecting
* @property {MessageComponentType} [componentType] The type of component interaction to collect
* @property {ComponentType} [componentType] The type of component interaction to collect
*/

/**
Expand Down

0 comments on commit 47633f0

Please sign in to comment.