Skip to content

Commit

Permalink
refactor: Use Base prefix for channel and interaction base classes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Jun 24, 2022
1 parent 65dc8d6 commit e24970e
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 112 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Client extends BaseClient {
this.guilds = new GuildManager(this);

/**
* All of the {@link Channel}s that the client is currently handling, mapped by their ids -
* All of the {@link BaseChannel}s that the client is currently handling, mapped by their ids -
* as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
* is a member of. Note that DM channels will not be initially cached, and thus not be present
* in the Manager without their explicit fetching or use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class InteractionCreateAction extends Action {
/**
* Emitted when an interaction is created.
* @event Client#interactionCreate
* @param {Interaction} interaction The interaction which was created
* @param {BaseInteraction} interaction The interaction which was created
*/
client.emit(Events.InteractionCreate, interaction);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports.ButtonBuilder = require('./structures/ButtonBuilder');
exports.ButtonComponent = require('./structures/ButtonComponent');
exports.ButtonInteraction = require('./structures/ButtonInteraction');
exports.CategoryChannel = require('./structures/CategoryChannel');
exports.Channel = require('./structures/Channel').Channel;
exports.BaseChannel = require('./structures/BaseChannel').BaseChannel;
exports.ChatInputCommandInteraction = require('./structures/ChatInputCommandInteraction');
exports.ClientApplication = require('./structures/ClientApplication');
exports.ClientPresence = require('./structures/ClientPresence');
Expand All @@ -121,7 +121,7 @@ exports.GuildScheduledEvent = require('./structures/GuildScheduledEvent').GuildS
exports.GuildTemplate = require('./structures/GuildTemplate');
exports.Integration = require('./structures/Integration');
exports.IntegrationApplication = require('./structures/IntegrationApplication');
exports.Interaction = require('./structures/Interaction');
exports.BaseInteraction = require('./structures/BaseInteraction');
exports.InteractionCollector = require('./structures/InteractionCollector');
exports.InteractionResponse = require('./structures/InteractionResponse');
exports.InteractionWebhook = require('./structures/InteractionWebhook');
Expand Down
12 changes: 6 additions & 6 deletions packages/discord.js/src/managers/ChannelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const process = require('node:process');
const { Routes } = require('discord-api-types/v10');
const CachedManager = require('./CachedManager');
const { Channel } = require('../structures/Channel');
const { BaseChannel } = require('../structures/BaseChannel');
const { createChannel } = require('../util/Channels');
const { ThreadChannelTypes } = require('../util/Constants');
const Events = require('../util/Events');
Expand All @@ -16,7 +16,7 @@ let cacheWarningEmitted = false;
*/
class ChannelManager extends CachedManager {
constructor(client, iterable) {
super(client, Channel, iterable);
super(client, BaseChannel, iterable);
const defaultCaching =
this._cache.constructor.name === 'Collection' ||
this._cache.maxSize === undefined ||
Expand All @@ -32,7 +32,7 @@ class ChannelManager extends CachedManager {

/**
* The cache of Channels
* @type {Collection<Snowflake, Channel>}
* @type {Collection<Snowflake, BaseChannel>}
* @name ChannelManager#cache
*/

Expand Down Expand Up @@ -75,7 +75,7 @@ class ChannelManager extends CachedManager {
* Data that can be resolved to give a Channel object. This can be:
* * A Channel object
* * A Snowflake
* @typedef {Channel|Snowflake} ChannelResolvable
* @typedef {BaseChannel|Snowflake} ChannelResolvable
*/

/**
Expand All @@ -84,7 +84,7 @@ class ChannelManager extends CachedManager {
* @memberof ChannelManager
* @instance
* @param {ChannelResolvable} channel The channel resolvable to resolve
* @returns {?Channel}
* @returns {?BaseChannel}
*/

/**
Expand All @@ -107,7 +107,7 @@ class ChannelManager extends CachedManager {
* Obtains a channel from Discord, or the channel cache if it's already available.
* @param {Snowflake} id The channel's id
* @param {FetchChannelOptions} [options] Additional options for this fetch
* @returns {Promise<?Channel>}
* @returns {Promise<?BaseChannel>}
* @example
* // Fetch a channel by its id
* client.channels.fetch('222109930545610754')
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/structures/AutocompleteInteraction.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const { InteractionResponseType, Routes } = require('discord-api-types/v10');
const BaseInteraction = require('./BaseInteraction');
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
const Interaction = require('./Interaction');
const { ErrorCodes } = require('../errors');

/**
* Represents an autocomplete interaction.
* @extends {Interaction}
* @extends {BaseInteraction}
*/
class AutocompleteInteraction extends Interaction {
class AutocompleteInteraction extends BaseInteraction {
constructor(client, data) {
super(client, data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { ThreadChannelTypes } = require('../util/Constants');
* @extends {Base}
* @abstract
*/
class Channel extends Base {
class BaseChannel extends Base {
constructor(client, data, immediatePatch = true) {
super(client);

Expand Down Expand Up @@ -81,7 +81,7 @@ class Channel extends Base {

/**
* Deletes this channel.
* @returns {Promise<Channel>}
* @returns {Promise<BaseChannel>}
* @example
* // Delete the channel
* channel.delete()
Expand All @@ -96,7 +96,7 @@ class Channel extends Base {
/**
* Fetches this channel.
* @param {boolean} [force=true] Whether to skip the cache check and request the API
* @returns {Promise<Channel>}
* @returns {Promise<BaseChannel>}
*/
fetch(force = true) {
return this.client.channels.fetch(this.id, { force });
Expand Down Expand Up @@ -139,7 +139,7 @@ class Channel extends Base {
}
}

exports.Channel = Channel;
exports.BaseChannel = BaseChannel;

/**
* @external APIChannel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const PermissionsBitField = require('../util/PermissionsBitField');
/**
* Represents an interaction.
* @extends {Base}
* @abstract
*/
class Interaction extends Base {
class BaseInteraction extends Base {
constructor(client, data) {
super(client);

Expand All @@ -28,7 +29,7 @@ class Interaction extends Base {
/**
* The interaction's token
* @type {string}
* @name Interaction#token
* @name BaseInteraction#token
* @readonly
*/
Object.defineProperty(this, 'token', { value: data.token });
Expand Down Expand Up @@ -246,4 +247,4 @@ class Interaction extends Base {
}
}

module.exports = Interaction;
module.exports = BaseInteraction;
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

const { Collection } = require('@discordjs/collection');
const Attachment = require('./Attachment');
const Interaction = require('./Interaction');
const BaseInteraction = require('./BaseInteraction');
const InteractionWebhook = require('./InteractionWebhook');
const InteractionResponses = require('./interfaces/InteractionResponses');

/**
* Represents a command interaction.
* @extends {Interaction}
* @extends {BaseInteraction}
* @implements {InteractionResponses}
* @abstract
*/
class CommandInteraction extends Interaction {
class CommandInteraction extends BaseInteraction {
constructor(client, data) {
super(client, data);

Expand Down Expand Up @@ -86,7 +86,7 @@ class CommandInteraction extends Interaction {
* @property {Collection<Snowflake, User>} [users] The resolved users
* @property {Collection<Snowflake, GuildMember|APIGuildMember>} [members] The resolved guild members
* @property {Collection<Snowflake, Role|APIRole>} [roles] The resolved roles
* @property {Collection<Snowflake, Channel|APIChannel>} [channels] The resolved channels
* @property {Collection<Snowflake, BaseChannel|APIChannel>} [channels] The resolved channels
* @property {Collection<Snowflake, Message|APIMessage>} [messages] The resolved messages
* @property {Collection<Snowflake, Attachment>} [attachments] The resolved attachments
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/structures/DMChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

const { userMention } = require('@discordjs/builders');
const { ChannelType } = require('discord-api-types/v10');
const { Channel } = require('./Channel');
const { BaseChannel } = require('./BaseChannel');
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const MessageManager = require('../managers/MessageManager');
const Partials = require('../util/Partials');

/**
* Represents a direct message channel between two users.
* @extends {Channel}
* @extends {BaseChannel}
* @implements {TextBasedChannel}
*/
class DMChannel extends Channel {
class DMChannel extends BaseChannel {
constructor(client, data) {
super(client, data);

Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/structures/DirectoryChannel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const { Channel } = require('./Channel');
const { BaseChannel } = require('./BaseChannel');

/**
* Represents a channel that displays a directory of guilds.
* @extends {Channel}
* @extends {BaseChannel}
*/
class DirectoryChannel extends Channel {
class DirectoryChannel extends BaseChannel {
constructor(guild, data, client) {
super(client, data);

Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/GuildAuditLogsEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Targets = {
* * An application command
* * An object with an id key if target was deleted or fake entity
* * An object where the keys represent either the new value or the old value
* @typedef {?(Object|Guild|Channel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration|StageInstance|Sticker|
* @typedef {?(Object|Guild|BaseChannel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration|StageInstance|Sticker|
* GuildScheduledEvent|ApplicationCommand)} AuditLogEntryTarget
*/

Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/structures/GuildChannel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { PermissionFlagsBits } = require('discord-api-types/v10');
const { Channel } = require('./Channel');
const { BaseChannel } = require('./BaseChannel');
const { Error, ErrorCodes } = require('../errors');
const PermissionOverwriteManager = require('../managers/PermissionOverwriteManager');
const { VoiceBasedChannelTypes } = require('../util/Constants');
Expand All @@ -14,10 +14,10 @@ const PermissionsBitField = require('../util/PermissionsBitField');
* - {@link CategoryChannel}
* - {@link NewsChannel}
* - {@link StageChannel}
* @extends {Channel}
* @extends {BaseChannel}
* @abstract
*/
class GuildChannel extends Channel {
class GuildChannel extends BaseChannel {
constructor(guild, data, client, immediatePatch = true) {
super(guild?.client ?? client, data, false);

Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/InteractionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ class InteractionCollector extends Collector {

/**
* Handles an incoming interaction for possible collection.
* @param {Interaction} interaction The interaction to possibly collect
* @param {BaseInteraction} interaction The interaction to possibly collect
* @returns {?Snowflake}
* @private
*/
collect(interaction) {
/**
* Emitted whenever an interaction is collected.
* @event InteractionCollector#collect
* @param {Interaction} interaction The interaction that was collected
* @param {BaseInteraction} interaction The interaction that was collected
*/
if (this.interactionType && interaction.type !== this.interactionType) return null;
if (this.componentType && interaction.componentType !== this.componentType) return null;
Expand All @@ -159,14 +159,14 @@ class InteractionCollector extends Collector {

/**
* Handles an interaction for possible disposal.
* @param {Interaction} interaction The interaction that could be disposed of
* @param {BaseInteraction} interaction The interaction that could be disposed of
* @returns {?Snowflake}
*/
dispose(interaction) {
/**
* Emitted whenever an interaction is disposed of.
* @event InteractionCollector#dispose
* @param {Interaction} interaction The interaction that was disposed of
* @param {BaseInteraction} interaction The interaction that was disposed of
*/
if (this.type && interaction.type !== this.type) return null;
if (this.componentType && interaction.componentType !== this.componentType) return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/InteractionResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const { ErrorCodes } = require('../errors');
*/
class InteractionResponse {
/**
* @param {Interaction} interaction The interaction associated with this response
* @param {BaseInteraction} interaction The interaction associated with this response
* @param {Snowflake?} id The interaction id associated with the original response
* @private
*/
constructor(interaction, id) {
/**
* The interaction associated with the interaction response
* @type {Interaction}
* @type {BaseInteraction}
*/
this.interaction = interaction;
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Invite.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class Invite extends Base {
if ('channel' in data) {
/**
* The channel this invite is for
* @type {?Channel}
* @type {?BaseChannel}
*/
this.channel =
this.client.channels._add(data.channel, this.guild, { cache: false }) ??
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const Interaction = require('./Interaction');
const BaseInteraction = require('./BaseInteraction');
const InteractionWebhook = require('./InteractionWebhook');
const InteractionResponses = require('./interfaces/InteractionResponses');
const { lazy } = require('../util/Util');
Expand All @@ -9,10 +9,10 @@ const getMessage = lazy(() => require('./Message').Message);

/**
* Represents a message component interaction.
* @extends {Interaction}
* @extends {BaseInteraction}
* @implements {InteractionResponses}
*/
class MessageComponentInteraction extends Interaction {
class MessageComponentInteraction extends BaseInteraction {
constructor(client, data) {
super(client, data);

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/MessageMentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class MessageMentions {

/**
* Cached channels for {@link MessageMentions#channels}
* @type {?Collection<Snowflake, Channel>}
* @type {?Collection<Snowflake, BaseChannel>}
* @private
*/
this._channels = null;
Expand Down Expand Up @@ -179,7 +179,7 @@ class MessageMentions {
/**
* Any channels that were mentioned
* <info>Order as they appear first in the message content</info>
* @type {Collection<Snowflake, Channel>}
* @type {Collection<Snowflake, BaseChannel>}
* @readonly
*/
get channels() {
Expand Down
Loading

0 comments on commit e24970e

Please sign in to comment.