Skip to content

Commit

Permalink
refactor: change xID to xId (#6036)
Browse files Browse the repository at this point in the history
* refactor: change `xID` to `xId`

* Update src/managers/MessageManager.js

Co-authored-by: Noel <buechler.noel@outlook.com>

Co-authored-by: Noel <buechler.noel@outlook.com>
  • Loading branch information
kyranet and iCrawl committed Jul 4, 2021
1 parent 281072b commit a7c6678
Show file tree
Hide file tree
Showing 95 changed files with 966 additions and 966 deletions.
20 changes: 10 additions & 10 deletions src/client/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ class Client extends BaseClient {
: null;

/**
* All of the {@link User} objects that have been cached at any point, mapped by their IDs
* All of the {@link User} objects that have been cached at any point, mapped by their ids
* @type {UserManager}
*/
this.users = new UserManager(this);

/**
* All of the guilds the client is currently handling, mapped by their IDs -
* All of the guilds the client is currently handling, mapped by their ids -
* as long as sharding isn't being used, this will be *every* guild the bot is a member of
* @type {GuildManager}
*/
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 Channel}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 Expand Up @@ -164,7 +164,7 @@ class Client extends BaseClient {
}

/**
* All custom emojis that the client has access to, mapped by their IDs
* All custom emojis that the client has access to, mapped by their ids
* @type {BaseGuildEmojiManager}
* @readonly
*/
Expand Down Expand Up @@ -273,7 +273,7 @@ class Client extends BaseClient {

/**
* Obtains a webhook from Discord.
* @param {Snowflake} id ID of the webhook
* @param {Snowflake} id The webhook's id
* @param {string} [token] Token for the webhook
* @returns {Promise<Webhook>}
* @example
Expand Down Expand Up @@ -352,7 +352,7 @@ class Client extends BaseClient {
* @returns {Promise<GuildPreview>}
*/
fetchGuildPreview(guild) {
const id = this.guilds.resolveID(guild);
const id = this.guilds.resolveId(guild);
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
return this.api
.guilds(id)
Expand All @@ -366,7 +366,7 @@ class Client extends BaseClient {
* @returns {Promise<Widget>}
*/
async fetchWidget(guild) {
const id = this.guilds.resolveID(guild);
const id = this.guilds.resolveId(guild);
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
const data = await this.api.guilds(id, 'widget.json').get();
return new Widget(this, data);
Expand Down Expand Up @@ -414,9 +414,9 @@ class Client extends BaseClient {
}

if (options.guild) {
const guildID = this.guilds.resolveID(options.guild);
if (!guildID) throw new TypeError('INVALID_TYPE', 'options.guild', 'GuildResolvable');
query.set('guild_id', guildID);
const guildId = this.guilds.resolveId(options.guild);
if (!guildId) throw new TypeError('INVALID_TYPE', 'options.guild', 'GuildResolvable');
query.set('guild_id', guildId);
}

if (options.additionalScopes) {
Expand Down
2 changes: 1 addition & 1 deletion src/client/WebhookClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Webhook = require('../structures/Webhook');
*/
class WebhookClient extends BaseClient {
/**
* @param {Snowflake} id ID of the webhook
* @param {Snowflake} id The webhook's id
* @param {string} token Token of the webhook
* @param {ClientOptions} [options] Options for the client
* @example
Expand Down
10 changes: 5 additions & 5 deletions src/client/actions/MessageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class MessageCreateAction extends Action {
const message = channel.messages.add(data);
const user = message.author;
const member = message.member;
channel.lastMessageID = data.id;
channel.lastMessageId = data.id;
if (user) {
user.lastMessageID = data.id;
user.lastMessageChannelID = channel.id;
user.lastMessageId = data.id;
user.lastMessageChannelId = channel.id;
}
if (member) {
member.lastMessageID = data.id;
member.lastMessageChannelID = channel.id;
member.lastMessageId = data.id;
member.lastMessageChannelId = channel.id;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/client/actions/MessageDeleteBulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MessageDeleteBulkAction extends Action {
/**
* Emitted whenever messages are deleted in bulk.
* @event Client#messageDeleteBulk
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their ID
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their id
*/
if (messages.size > 0) client.emit(Events.MESSAGE_BULK_DELETE, messages);
return { messages };
Expand Down
8 changes: 4 additions & 4 deletions src/client/voice/ClientVoiceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class ClientVoiceManager {
Object.defineProperty(this, 'client', { value: client });

/**
* Maps guild IDs to voice adapters created for use with @discordjs/voice.
* Maps guild ids to voice adapters created for use with @discordjs/voice.
* @type {Map<Snowflake, Object>}
*/
this.adapters = new Map();

client.on(Events.SHARD_DISCONNECT, (_, shardID) => {
for (const [guildID, adapter] of this.adapters.entries()) {
if (client.guilds.cache.get(guildID)?.shardID === shardID) {
client.on(Events.SHARD_DISCONNECT, (_, shardId) => {
for (const [guildId, adapter] of this.adapters.entries()) {
if (client.guilds.cache.get(guildId)?.shardId === shardId) {
adapter.destroy();
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/client/websocket/WebSocketManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ class WebSocketManager extends EventEmitter {
/**
* Emitted when a shard turns ready.
* @event Client#shardReady
* @param {number} id The shard ID that turned ready
* @param {?Set<string>} unavailableGuilds Set of unavailable guild IDs, if any
* @param {number} id The shard id that turned ready
* @param {?Set<string>} unavailableGuilds Set of unavailable guild ids, if any
*/
this.client.emit(Events.SHARD_READY, shard.id, unavailableGuilds);

Expand All @@ -189,7 +189,7 @@ class WebSocketManager extends EventEmitter {
* Emitted when a shard's WebSocket disconnects and will no longer reconnect.
* @event Client#shardDisconnect
* @param {CloseEvent} event The WebSocket close event
* @param {number} id The shard ID that disconnected
* @param {number} id The shard id that disconnected
*/
this.client.emit(Events.SHARD_DISCONNECT, event, shard.id);
this.debug(WSCodes[event.code], shard);
Expand All @@ -198,20 +198,20 @@ class WebSocketManager extends EventEmitter {

if (UNRESUMABLE_CLOSE_CODES.includes(event.code)) {
// These event codes cannot be resumed
shard.sessionID = null;
shard.sessionId = null;
}

/**
* Emitted when a shard is attempting to reconnect or re-identify.
* @event Client#shardReconnecting
* @param {number} id The shard ID that is attempting to reconnect
* @param {number} id The shard id that is attempting to reconnect
*/
this.client.emit(Events.SHARD_RECONNECTING, shard.id);

this.shardQueue.add(shard);

if (shard.sessionID) {
this.debug(`Session ID is present, attempting an immediate reconnect...`, shard);
if (shard.sessionId) {
this.debug(`Session id is present, attempting an immediate reconnect...`, shard);
this.reconnect();
} else {
shard.destroy({ reset: true, emit: false, log: false });
Expand Down
34 changes: 17 additions & 17 deletions src/client/websocket/WebSocketShard.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WebSocketShard extends EventEmitter {
this.manager = manager;

/**
* The ID of the shard
* The shard's id
* @type {number}
*/
this.id = id;
Expand All @@ -54,11 +54,11 @@ class WebSocketShard extends EventEmitter {
this.closeSequence = 0;

/**
* The current session ID of the shard
* The current session id of the shard
* @type {?string}
* @private
*/
this.sessionID = null;
this.sessionId = null;

/**
* The previous heartbeat ping of the shard
Expand Down Expand Up @@ -134,7 +134,7 @@ class WebSocketShard extends EventEmitter {
Object.defineProperty(this, 'eventsAttached', { value: false, writable: true });

/**
* A set of guild IDs this shard expects to receive
* A set of guild ids this shard expects to receive
* @name WebSocketShard#expectedGuilds
* @type {?Set<string>}
* @private
Expand Down Expand Up @@ -313,7 +313,7 @@ class WebSocketShard extends EventEmitter {
* Emitted whenever a shard's WebSocket encounters a connection error.
* @event Client#shardError
* @param {Error} error The encountered error
* @param {number} shardID The shard that encountered this error
* @param {number} shardId The shard that encountered this error
*/
this.manager.client.emit(Events.SHARD_ERROR, error, this.id);
}
Expand Down Expand Up @@ -382,10 +382,10 @@ class WebSocketShard extends EventEmitter {
*/
this.emit(ShardEvents.READY);

this.sessionID = packet.d.session_id;
this.sessionId = packet.d.session_id;
this.expectedGuilds = new Set(packet.d.guilds.map(d => d.id));
this.status = Status.WAITING_FOR_GUILDS;
this.debug(`[READY] Session ${this.sessionID}.`);
this.debug(`[READY] Session ${this.sessionId}.`);
this.lastHeartbeatAcked = true;
this.sendHeartbeat('ReadyHeartbeat');
break;
Expand All @@ -398,7 +398,7 @@ class WebSocketShard extends EventEmitter {

this.status = Status.READY;
const replayed = packet.s - this.closeSequence;
this.debug(`[RESUMED] Session ${this.sessionID} | Replayed ${replayed} events.`);
this.debug(`[RESUMED] Session ${this.sessionId} | Replayed ${replayed} events.`);
this.lastHeartbeatAcked = true;
this.sendHeartbeat('ResumeHeartbeat');
break;
Expand Down Expand Up @@ -426,8 +426,8 @@ class WebSocketShard extends EventEmitter {
}
// Reset the sequence
this.sequence = -1;
// Reset the session ID as it's invalid
this.sessionID = null;
// Reset the session id as it's invalid
this.sessionId = null;
// Set the status to reconnecting
this.status = Status.RECONNECTING;
// Finally, emit the INVALID_SESSION event
Expand Down Expand Up @@ -576,7 +576,7 @@ class WebSocketShard extends EventEmitter {
* @returns {void}
*/
identify() {
return this.sessionID ? this.identifyResume() : this.identifyNew();
return this.sessionId ? this.identifyResume() : this.identifyNew();
}

/**
Expand Down Expand Up @@ -609,19 +609,19 @@ class WebSocketShard extends EventEmitter {
* @private
*/
identifyResume() {
if (!this.sessionID) {
this.debug('[RESUME] No session ID was present; identifying as a new session.');
if (!this.sessionId) {
this.debug('[RESUME] No session id was present; identifying as a new session.');
this.identifyNew();
return;
}

this.status = Status.RESUMING;

this.debug(`[RESUME] Session ${this.sessionID}, sequence ${this.closeSequence}`);
this.debug(`[RESUME] Session ${this.sessionId}, sequence ${this.closeSequence}`);

const d = {
token: this.manager.client.token,
session_id: this.sessionID,
session_id: this.sessionId,
seq: this.closeSequence,
};

Expand Down Expand Up @@ -731,10 +731,10 @@ class WebSocketShard extends EventEmitter {
// Step 4: Cache the old sequence (use to attempt a resume)
if (this.sequence !== -1) this.closeSequence = this.sequence;

// Step 5: Reset the sequence and session ID if requested
// Step 5: Reset the sequence and session id if requested
if (reset) {
this.sequence = -1;
this.sessionID = null;
this.sessionId = null;
}

// Step 6: reset the ratelimit data
Expand Down
2 changes: 1 addition & 1 deletion src/client/websocket/handlers/GUILD_CREATE.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = (client, { d: data }, shard) => {
}
} else {
// A new guild
data.shardID = shard.id;
data.shardId = shard.id;
guild = client.guilds.add(data);
if (client.ws.status === Status.READY) {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/client/websocket/handlers/READY.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = (client, { d: data }, shard) => {
}

for (const guild of data.guilds) {
guild.shardID = shard.id;
guild.shardId = shard.id;
client.guilds.add(guild);
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/websocket/handlers/RESUMED.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (client, packet, shard) => {
/**
* Emitted when a shard resumes successfully.
* @event Client#shardResume
* @param {number} id The shard ID that resumed
* @param {number} id The shard id that resumed
* @param {number} replayedEvents The amount of replayed events
*/
client.emit(Events.SHARD_RESUME, shard.id, replayed);
Expand Down
12 changes: 6 additions & 6 deletions src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const Messages = {

BUTTON_LABEL: 'MessageButton label must be a string',
BUTTON_URL: 'MessageButton url must be a string',
BUTTON_CUSTOM_ID: 'MessageButton customID must be a string',
BUTTON_CUSTOM_ID: 'MessageButton customId must be a string',

SELECT_MENU_CUSTOM_ID: 'MessageSelectMenu customID must be a string',
SELECT_MENU_CUSTOM_ID: 'MessageSelectMenu customId must be a string',
SELECT_MENU_PLACEHOLDER: 'MessageSelectMenu placeholder must be a string',
SELECT_OPTION_LABEL: 'MessageSelectOption label must be a string',
SELECT_OPTION_VALUE: 'MessageSelectOption value must be a string',
Expand Down Expand Up @@ -82,8 +82,8 @@ const Messages = {

SPLIT_MAX_LEN: 'Chunk exceeds the max length and contains no split characters.',

BAN_RESOLVE_ID: (ban = false) => `Couldn't resolve the user ID to ${ban ? 'ban' : 'unban'}.`,
FETCH_BAN_RESOLVE_ID: "Couldn't resolve the user ID to fetch the ban.",
BAN_RESOLVE_ID: (ban = false) => `Couldn't resolve the user id to ${ban ? 'ban' : 'unban'}.`,
FETCH_BAN_RESOLVE_ID: "Couldn't resolve the user id to fetch the ban.",

PRUNE_DAYS_TYPE: 'Days must be a number',

Expand All @@ -109,7 +109,7 @@ const Messages = {
MISSING_MANAGE_EMOJIS_PERMISSION: guild =>
`Client must have Manage Emoji permission in guild ${guild} to see emoji authors.`,

REACTION_RESOLVE_USER: "Couldn't resolve the user ID to remove from the reaction.",
REACTION_RESOLVE_USER: "Couldn't resolve the user id to remove from the reaction.",

VANITY_URL: 'This guild does not have the VANITY_URL feature enabled.',

Expand All @@ -121,7 +121,7 @@ const Messages = {
GLOBAL_COMMAND_PERMISSIONS:
'Permissions for global commands may only be fetched or modified by providing a GuildResolvable ' +
"or from a guild's application command manager.",
GUILD_UNCACHED_ROLE_RESOLVE: 'Cannot resolve roles from an arbitrary guild, provide an ID instead',
GUILD_UNCACHED_ROLE_RESOLVE: 'Cannot resolve roles from an arbitrary guild, provide an id instead',

INTERACTION_ALREADY_REPLIED: 'This interaction has already been deferred or replied to.',
INTERACTION_NOT_REPLIED: 'This interaction has not been deferred or replied to.',
Expand Down
Loading

0 comments on commit a7c6678

Please sign in to comment.