refactor: change xID to xId (#6036)

* 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>
This commit is contained in:
Antonio Román
2021-07-04 20:54:27 +02:00
committed by GitHub
parent 281072be44
commit a7c6678c72
95 changed files with 963 additions and 963 deletions

View File

@@ -29,30 +29,30 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* The id of the guild that this manager acts on
* @type {?Snowflake}
*/
this.guildID = manager.guildID ?? manager.guild?.id ?? null;
this.guildId = manager.guildId ?? manager.guild?.id ?? null;
/**
* The id of the command this manager acts on
* @type {?Snowflake}
*/
this.commandID = manager.id ?? null;
this.commandId = manager.id ?? null;
}
/**
* The APIRouter path to the commands
* @param {Snowflake} guildID ID of the guild to use in the path,
* @param {Snowflake} [commandID] ID of the application command
* @param {Snowflake} guildId The guild's id to use in the path,
* @param {Snowflake} [commandId] The application command's id
* @returns {Object}
* @private
*/
permissionsPath(guildID, commandID) {
return this.client.api.applications(this.client.application.id).guilds(guildID).commands(commandID).permissions;
permissionsPath(guildId, commandId) {
return this.client.api.applications(this.client.application.id).guilds(guildId).commands(commandId).permissions;
}
/**
* Data for setting the permissions of an application command.
* @typedef {Object} ApplicationCommandPermissionData
* @property {Snowflake} id The ID of the role or user
* @property {Snowflake} id The role or user's id
* @property {ApplicationCommandPermissionType|number} type Whether this permission is for a role or a user
* @property {boolean} permission Whether the role or user has the permission to use this command
*/
@@ -60,20 +60,20 @@ class ApplicationCommandPermissionsManager extends BaseManager {
/**
* The object returned when fetching permissions for an application command.
* @typedef {Object} ApplicationCommandPermissions
* @property {Snowflake} id The ID of the role or user
* @property {Snowflake} id The role or user's id
* @property {ApplicationCommandPermissionType} type Whether this permission is for a role or a user
* @property {boolean} permission Whether the role or user has the permission to use this command
*/
/**
* Options for managing permissions for one or more Application Commands
* <warn>When passing these options to a manager where `guildID` is `null`,
* <warn>When passing these options to a manager where `guildId` is `null`,
* `guild` is a required parameter</warn>
* @typedef {Object} BaseApplicationCommandPermissionsOptions
* @param {GuildResolvable} [guild] The guild to modify / check permissions for
* <warn>Ignored when the manager has a non-null `guildID` property</warn>
* <warn>Ignored when the manager has a non-null `guildId` property</warn>
* @param {ApplicationCommandResolvable} [command] The command to modify / check permissions for
* <warn>Ignored when the manager has a non-null `commandID` property</warn>
* <warn>Ignored when the manager has a non-null `commandId` property</warn>
*/
/**
@@ -92,13 +92,13 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async fetch({ guild, command } = {}) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (commandID) {
const data = await this.permissionsPath(guildID, commandID).get();
const { guildId, commandId } = this._validateOptions(guild, command);
if (commandId) {
const data = await this.permissionsPath(guildId, commandId).get();
return data.permissions.map(perm => this.constructor.transformPermissions(perm, true));
}
const data = await this.permissionsPath(guildID).get();
const data = await this.permissionsPath(guildId).get();
return data.reduce(
(coll, perm) =>
coll.set(
@@ -112,14 +112,14 @@ class ApplicationCommandPermissionsManager extends BaseManager {
/**
* Data used for overwriting the permissions for all application commands in a guild.
* @typedef {Object} GuildApplicationCommandPermissionData
* @property {Snowflake} id The ID of the command
* @property {Snowflake} id The command's id
* @property {ApplicationCommandPermissionData[]} permissions The permissions for this command
*/
/**
* Options used to set permissions for one or more Application Commands in a guild
* <warn>One of `command` AND `permissions`, OR `fullPermissions` is required.
* `fullPermissions` is not a valid option when passing to a manager where `commandID` is non-null</warn>
* `fullPermissions` is not a valid option when passing to a manager where `commandId` is non-null</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} SetApplicationCommandPermissionsOptions
* @param {ApplicationCommandPermissionData[]} [permissions] The new permissions for the command
* @param {GuildApplicationCommandPermissionData[]} [fullPermissions] The new permissions for all commands
@@ -157,13 +157,13 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async set({ guild, command, permissions, fullPermissions } = {}) {
const { guildID, commandID } = this._validateOptions(guild, command);
const { guildId, commandId } = this._validateOptions(guild, command);
if (commandID) {
if (commandId) {
if (!Array.isArray(permissions)) {
throw new TypeError('INVALID_TYPE', 'permissions', 'Array of ApplicationCommandPermissionData', true);
}
const data = await this.permissionsPath(guildID, commandID).put({
const data = await this.permissionsPath(guildId, commandId).put({
data: { permissions: permissions.map(perm => this.constructor.transformPermissions(perm)) },
});
return data.permissions.map(perm => this.constructor.transformPermissions(perm, true));
@@ -181,7 +181,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
permissions: perm.permissions.map(p => this.constructor.transformPermissions(p)),
});
}
const data = await this.permissionsPath(guildID).put({
const data = await this.permissionsPath(guildId).put({
data: APIPermissions,
});
return data.reduce(
@@ -196,7 +196,7 @@ class ApplicationCommandPermissionsManager extends BaseManager {
/**
* Options used to add permissions to a command
* <warn>The `command` parameter is not optional when the managers `commandID` is `null`</warn>
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} AddApplicationCommandPermissionsOptions
* @param {ApplicationCommandPermissionData[]} permissions The permissions to add to the command
*/
@@ -218,15 +218,15 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async add({ guild, command, permissions }) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (!commandID) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
const { guildId, commandId } = this._validateOptions(guild, command);
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
if (!Array.isArray(permissions)) {
throw new TypeError('INVALID_TYPE', 'permissions', 'Array of ApplicationCommandPermissionData', true);
}
let existing = [];
try {
existing = await this.fetch({ guild: guildID, command: commandID });
existing = await this.fetch({ guild: guildId, command: commandId });
} catch (error) {
if (error.code !== APIErrors.UNKNOWN_APPLICATION_COMMAND_PERMISSIONS) throw error;
}
@@ -238,12 +238,12 @@ class ApplicationCommandPermissionsManager extends BaseManager {
}
}
return this.set({ guild: guildID, command: commandID, permissions: newPermissions });
return this.set({ guild: guildId, command: commandId, permissions: newPermissions });
}
/**
* Options used to remove permissions from a command
* <warn>The `command` parameter is not optional when the managers `commandID` is `null`</warn>
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} RemoveApplicationCommandPermissionsOptions
* @param {UserResolvable|UserResolvable[]} [users] The user(s) to remove from the command permissions
* <warn>One of `users` or `roles` is required</warn>
@@ -269,67 +269,67 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* .catch(console.error);
*/
async remove({ guild, command, users, roles }) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (!commandID) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
const { guildId, commandId } = this._validateOptions(guild, command);
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
if (!users && !roles) throw new TypeError('INVALID_TYPE', 'users OR roles', 'Array or Resolvable', true);
let resolvedIDs = [];
let resolvedIds = [];
if (Array.isArray(users)) {
users.forEach(user => {
const userID = this.client.users.resolveID(user);
if (!userID) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', user);
resolvedIDs.push(userID);
const userId = this.client.users.resolveId(user);
if (!userId) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', user);
resolvedIds.push(userId);
});
} else if (users) {
const userID = this.client.users.resolveID(users);
if (!userID) {
const userId = this.client.users.resolveId(users);
if (!userId) {
throw new TypeError('INVALID_TYPE', 'users', 'Array or UserResolvable');
}
resolvedIDs.push(userID);
resolvedIds.push(userId);
}
if (Array.isArray(roles)) {
roles.forEach(role => {
if (typeof role === 'string') {
resolvedIDs.push(role);
resolvedIds.push(role);
return;
}
if (!this.guild) throw new Error('GUILD_UNCACHED_ROLE_RESOLVE');
const roleID = this.guild.roles.resolveID(role);
if (!roleID) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', role);
resolvedIDs.push(roleID);
const roleId = this.guild.roles.resolveId(role);
if (!roleId) throw new TypeError('INVALID_ELEMENT', 'Array', 'users', role);
resolvedIds.push(roleId);
});
} else if (roles) {
if (typeof roles === 'string') {
resolvedIDs.push(roles);
resolvedIds.push(roles);
} else {
if (!this.guild) throw new Error('GUILD_UNCACHED_ROLE_RESOLVE');
const roleID = this.guild.roles.resolveID(roles);
if (!roleID) {
const roleId = this.guild.roles.resolveId(roles);
if (!roleId) {
throw new TypeError('INVALID_TYPE', 'users', 'Array or RoleResolvable');
}
resolvedIDs.push(roleID);
resolvedIds.push(roleId);
}
}
let existing = [];
try {
existing = await this.fetch({ guild: guildID, command: commandID });
existing = await this.fetch({ guild: guildId, command: commandId });
} catch (error) {
if (error.code !== APIErrors.UNKNOWN_APPLICATION_COMMAND_PERMISSIONS) throw error;
}
const permissions = existing.filter(perm => !resolvedIDs.includes(perm.id));
const permissions = existing.filter(perm => !resolvedIds.includes(perm.id));
return this.set({ guild: guildID, command: commandID, permissions });
return this.set({ guild: guildId, command: commandId, permissions });
}
/**
* Options used to check existance of permissions on a command
* <warn>The `command` parameter is not optional when the managers `commandID` is `null`</warn>
* <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
* @typedef {BaseApplicationCommandPermissionsOptions} HasApplicationCommandPermissionsOptions
* @param {UserResolvable|RoleResolvable} permissionID The user or role to check if a permission exists for
* @param {UserResolvable|RoleResolvable} permissionId The user or role to check if a permission exists for
* on this command.
*/
@@ -339,54 +339,54 @@ class ApplicationCommandPermissionsManager extends BaseManager {
* @returns {Promise<boolean>}
* @example
* // Check whether a user has permission to use a command
* guild.commands.permissions.has({ command: '123456789012345678', permissionID: '876543210123456789' })
* guild.commands.permissions.has({ command: '123456789012345678', permissionId: '876543210123456789' })
* .then(console.log)
* .catch(console.error);
*/
async has({ guild, command, permissionID }) {
const { guildID, commandID } = this._validateOptions(guild, command);
if (!commandID) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
async has({ guild, command, permissionId }) {
const { guildId, commandId } = this._validateOptions(guild, command);
if (!commandId) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable');
if (!permissionID) throw new TypeError('INVALID_TYPE', 'permissionsID', 'UserResolvable or RoleResolvable');
let resolvedID = permissionID;
if (typeof permissionID !== 'string') {
resolvedID = this.client.users.resolveID(permissionID);
if (!resolvedID) {
if (!permissionId) throw new TypeError('INVALID_TYPE', 'permissionsId', 'UserResolvable or RoleResolvable');
let resolvedId = permissionId;
if (typeof permissionId !== 'string') {
resolvedId = this.client.users.resolveId(permissionId);
if (!resolvedId) {
if (!this.guild) throw new Error('GUILD_UNCACHED_ROLE_RESOLVE');
resolvedID = this.guild.roles.resolveID(permissionID);
resolvedId = this.guild.roles.resolveId(permissionId);
}
if (!resolvedID) {
throw new TypeError('INVALID_TYPE', 'permissionID', 'UserResolvable or RoleResolvable');
if (!resolvedId) {
throw new TypeError('INVALID_TYPE', 'permissionId', 'UserResolvable or RoleResolvable');
}
}
let existing = [];
try {
existing = await this.fetch({ guild: guildID, command: commandID });
existing = await this.fetch({ guild: guildId, command: commandId });
} catch (error) {
if (error.code !== APIErrors.UNKNOWN_APPLICATION_COMMAND_PERMISSIONS) throw error;
}
return existing.some(perm => perm.id === resolvedID);
return existing.some(perm => perm.id === resolvedId);
}
_validateOptions(guild, command) {
const guildID = this.guildID ?? this.client.guilds.resolveID(guild);
if (!guildID) throw new Error('GLOBAL_COMMAND_PERMISSIONS');
let commandID = this.commandID;
if (command && !commandID) {
commandID = this.manager.resolveID?.(command);
if (!commandID && this.guild) {
commandID = this.guild.commands.resolveID(command);
const guildId = this.guildId ?? this.client.guilds.resolveId(guild);
if (!guildId) throw new Error('GLOBAL_COMMAND_PERMISSIONS');
let commandId = this.commandId;
if (command && !commandId) {
commandId = this.manager.resolveId?.(command);
if (!commandId && this.guild) {
commandId = this.guild.commands.resolveId(command);
}
if (!commandID) {
commandID = this.client.application?.commands.resolveID(command);
if (!commandId) {
commandId = this.client.application?.commands.resolveId(command);
}
if (!commandID) {
if (!commandId) {
throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable', true);
}
}
return { guildID, commandID };
return { guildId, commandId };
}
/**