mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
Remove all string object references (#586)
This commit is contained in:
committed by
Amish Shah
parent
ec0a5cdfbc
commit
d97ce2e181
@@ -10,10 +10,6 @@ const Guild = getStructure('Guild');
|
|||||||
const Channel = getStructure('Channel');
|
const Channel = getStructure('Channel');
|
||||||
const GuildMember = getStructure('GuildMember');
|
const GuildMember = getStructure('GuildMember');
|
||||||
|
|
||||||
function $string(obj) {
|
|
||||||
return (typeof obj === 'string' || obj instanceof String);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them, e.g.
|
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them, e.g.
|
||||||
* extracting a User from a Message object.
|
* extracting a User from a Message object.
|
||||||
@@ -31,7 +27,7 @@ class ClientDataResolver {
|
|||||||
* * A Message (resolves to the message author)
|
* * A Message (resolves to the message author)
|
||||||
* * A Guild (owner of the guild)
|
* * A Guild (owner of the guild)
|
||||||
* * A Guild Member
|
* * A Guild Member
|
||||||
* @typedef {User|String|Message|Guild|GuildMember} UserResolvable
|
* @typedef {User|string|Message|Guild|GuildMember} UserResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,7 +38,7 @@ class ClientDataResolver {
|
|||||||
resolveUser(user) {
|
resolveUser(user) {
|
||||||
if (user instanceof User) {
|
if (user instanceof User) {
|
||||||
return user;
|
return user;
|
||||||
} else if ($string(user)) {
|
} else if (typeof user === 'string') {
|
||||||
return this.client.users.get(user);
|
return this.client.users.get(user);
|
||||||
} else if (user instanceof Message) {
|
} else if (user instanceof Message) {
|
||||||
return user.author;
|
return user.author;
|
||||||
@@ -105,7 +101,7 @@ class ClientDataResolver {
|
|||||||
/**
|
/**
|
||||||
* Data that resolves to give a Base64 string, typically for image uploading. This can be:
|
* Data that resolves to give a Base64 string, typically for image uploading. This can be:
|
||||||
* * A Buffer
|
* * A Buffer
|
||||||
* * A Base64 String
|
* * A Base64 string
|
||||||
* @typedef {Buffer|string} Base64Resolvable
|
* @typedef {Buffer|string} Base64Resolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -139,7 +135,7 @@ class ClientDataResolver {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($string(channel)) {
|
if (typeof channel === 'string') {
|
||||||
return this.client.channels.get(channel.id);
|
return this.client.channels.get(channel.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,20 +143,20 @@ class ClientDataResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data that can be resolved to give a String. This can be:
|
* Data that can be resolved to give a string. This can be:
|
||||||
* * A String
|
* * A string
|
||||||
* * An Array (joined with a new line delimiter to give a string)
|
* * An Array (joined with a new line delimiter to give a string)
|
||||||
* * Any object
|
* * Any object
|
||||||
* @typedef {string|Array|Object} StringResolvable
|
* @typedef {string|Array|Object} StringResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a StringResolvable to a String
|
* Resolves a StringResolvable to a string
|
||||||
* @param {StringResolvable} StringResolvable the string resolvable to resolve
|
* @param {StringResolvable} StringResolvable the string resolvable to resolve
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
resolveString(data) {
|
resolveString(data) {
|
||||||
if (data instanceof String) {
|
if (typeof data === 'string') {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +181,7 @@ class ClientDataResolver {
|
|||||||
* @returns {string|Buffer}
|
* @returns {string|Buffer}
|
||||||
*/
|
*/
|
||||||
resolveFile(resource) {
|
resolveFile(resource) {
|
||||||
if ($string(resource)) {
|
if (typeof resource === 'string') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (/^https?:\/\//.test(resource)) {
|
if (/^https?:\/\//.test(resource)) {
|
||||||
request.get(resource)
|
request.get(resource)
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ class RESTMethods {
|
|||||||
if (_data.permissions) {
|
if (_data.permissions) {
|
||||||
let perms = 0;
|
let perms = 0;
|
||||||
for (let perm of _data.permissions) {
|
for (let perm of _data.permissions) {
|
||||||
if (perm instanceof String || typeof perm === 'string') {
|
if (typeof perm === 'string') {
|
||||||
perm = Constants.PermissionFlags[perm];
|
perm = Constants.PermissionFlags[perm];
|
||||||
}
|
}
|
||||||
perms |= perm;
|
perms |= perm;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class DMChannel extends Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a String, this automatically concatenates the recipient's mention instead of the
|
* When concatenated with a string, this automatically concatenates the recipient's mention instead of the
|
||||||
* DM channel object.
|
* DM channel object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class Emoji {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a String, this automatically returns the emoji mention rather than the object.
|
* When concatenated with a string, this automatically returns the emoji mention rather than the object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @example
|
* @example
|
||||||
* // send an emoji:
|
* // send an emoji:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class EvaluatedPermissions {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
hasPermission(permission, explicit = false) {
|
hasPermission(permission, explicit = false) {
|
||||||
if (permission instanceof String || typeof permission === 'string') {
|
if (typeof permission === 'string') {
|
||||||
permission = Constants.PermissionFlags[permission];
|
permission = Constants.PermissionFlags[permission];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class Guild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a String, this automatically concatenates the Guild's name instead of the Guild object.
|
* When concatenated with a string, this automatically concatenates the Guild's name instead of the Guild object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @example
|
* @example
|
||||||
* // logs: Hello from My Guild!
|
* // logs: Hello from My Guild!
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class GuildChannel extends Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a String, this automatically returns the Channel's mention instead of the Channel object.
|
* When concatenated with a string, this automatically returns the Channel's mention instead of the Channel object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @example
|
* @example
|
||||||
* // Outputs: Hello from #general
|
* // Outputs: Hello from #general
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class Role {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
hasPermission(permission, explicit = false) {
|
hasPermission(permission, explicit = false) {
|
||||||
if (permission instanceof String || typeof permission === 'string') {
|
if (typeof permission === 'string') {
|
||||||
permission = Constants.PermissionFlags[permission];
|
permission = Constants.PermissionFlags[permission];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ class Role {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a String, this automatically concatenates the Role mention rather than the Role object.
|
* When concatenated with a string, this automatically concatenates the Role mention rather than the Role object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
toString() {
|
toString() {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a String, this automatically concatenates the User's mention instead of the User object.
|
* When concatenated with a string, this automatically concatenates the User's mention instead of the User object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
* @example
|
* @example
|
||||||
* // logs: Hello from <@123456789>!
|
* // logs: Hello from <@123456789>!
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ class TextBasedChannel {
|
|||||||
*/
|
*/
|
||||||
sendFile(attachment, fileName) {
|
sendFile(attachment, fileName) {
|
||||||
if (!fileName) {
|
if (!fileName) {
|
||||||
if (attachment instanceof String || typeof attachment === 'string') {
|
if (typeof attachment === 'string') {
|
||||||
fileName = path.basename(attachment);
|
fileName = path.basename(attachment);
|
||||||
} else if (attachment && attachment.path) {
|
} else if (attachment && attachment.path) {
|
||||||
fileName = path.basename(attachment.path);
|
fileName = path.basename(attachment.path);
|
||||||
|
|||||||
Reference in New Issue
Block a user