mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Refactored static resolvers to Util (#1517)
* ready event will now throw errors properly * ws login rejection fix * moved static resolves to util
This commit is contained in:
@@ -911,7 +911,7 @@ class Guild {
|
||||
* .catch(console.error)
|
||||
*/
|
||||
createRole({ data = {}, reason } = {}) {
|
||||
if (data.color) data.color = this.client.resolver.resolveColor(data.color);
|
||||
if (data.color) data.color = Util.resolveColor(data.color);
|
||||
if (data.permissions) data.permissions = Permissions.resolve(data.permissions);
|
||||
|
||||
return this.client.api.guilds(this.id).roles.post({ data, reason }).then(role =>
|
||||
|
||||
@@ -381,13 +381,13 @@ class Message {
|
||||
options = {};
|
||||
}
|
||||
|
||||
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
|
||||
if (typeof content !== 'undefined') content = Util.resolveString(content);
|
||||
|
||||
const { embed, code, reply } = options;
|
||||
|
||||
// Wrap everything in a code block
|
||||
if (typeof code !== 'undefined' && (typeof code !== 'boolean' || code === true)) {
|
||||
content = Util.escapeMarkdown(this.client.resolver.resolveString(content), true);
|
||||
content = Util.escapeMarkdown(Util.resolveString(content), true);
|
||||
content = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n${content}\n\`\`\``;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const ClientDataResolver = require('../client/ClientDataResolver');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* A rich embed to be sent with a message with a fluent interface for creation.
|
||||
@@ -79,7 +79,7 @@ class RichEmbed {
|
||||
* @returns {RichEmbed} This embed
|
||||
*/
|
||||
setTitle(title) {
|
||||
title = resolveString(title);
|
||||
title = Util.resolveString(title);
|
||||
if (title.length > 256) throw new RangeError('RichEmbed titles may not exceed 256 characters.');
|
||||
this.title = title;
|
||||
return this;
|
||||
@@ -91,7 +91,7 @@ class RichEmbed {
|
||||
* @returns {RichEmbed} This embed
|
||||
*/
|
||||
setDescription(description) {
|
||||
description = resolveString(description);
|
||||
description = Util.resolveString(description);
|
||||
if (description.length > 2048) throw new RangeError('RichEmbed descriptions may not exceed 2048 characters.');
|
||||
this.description = description;
|
||||
return this;
|
||||
@@ -113,7 +113,7 @@ class RichEmbed {
|
||||
* @returns {RichEmbed} This embed
|
||||
*/
|
||||
setColor(color) {
|
||||
this.color = ClientDataResolver.resolveColor(color);
|
||||
this.color = Util.resolveColor(color);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ class RichEmbed {
|
||||
* @returns {RichEmbed} This embed
|
||||
*/
|
||||
setAuthor(name, icon, url) {
|
||||
this.author = { name: resolveString(name), icon_url: icon, url };
|
||||
this.author = { name: Util.resolveString(name), icon_url: icon, url };
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -148,10 +148,10 @@ class RichEmbed {
|
||||
*/
|
||||
addField(name, value, inline = false) {
|
||||
if (this.fields.length >= 25) throw new RangeError('RichEmbeds may not exceed 25 fields.');
|
||||
name = resolveString(name);
|
||||
name = Util.resolveString(name);
|
||||
if (name.length > 256) throw new RangeError('RichEmbed field names may not exceed 256 characters.');
|
||||
if (!/\S/.test(name)) throw new RangeError('RichEmbed field names may not be empty.');
|
||||
value = resolveString(value);
|
||||
value = Util.resolveString(value);
|
||||
if (value.length > 1024) throw new RangeError('RichEmbed field values may not exceed 1024 characters.');
|
||||
if (!/\S/.test(value)) throw new RangeError('RichEmbed field values may not be empty.');
|
||||
this.fields.push({ name, value, inline });
|
||||
@@ -194,7 +194,7 @@ class RichEmbed {
|
||||
* @returns {RichEmbed} This embed
|
||||
*/
|
||||
setFooter(text, icon) {
|
||||
text = resolveString(text);
|
||||
text = Util.resolveString(text);
|
||||
if (text.length > 2048) throw new RangeError('RichEmbed footer text may not exceed 2048 characters.');
|
||||
this.footer = { text, icon_url: icon };
|
||||
return this;
|
||||
@@ -214,9 +214,3 @@ class RichEmbed {
|
||||
}
|
||||
|
||||
module.exports = RichEmbed;
|
||||
|
||||
function resolveString(data) {
|
||||
if (typeof data === 'string') return data;
|
||||
if (data instanceof Array) return data.join('\n');
|
||||
return String(data);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Represents a role on Discord.
|
||||
@@ -205,7 +206,7 @@ class Role {
|
||||
data: {
|
||||
name: data.name || this.name,
|
||||
position: typeof data.position !== 'undefined' ? data.position : this.position,
|
||||
color: this.client.resolver.resolveColor(data.color || this.color),
|
||||
color: Util.resolveColor(data.color || this.color),
|
||||
hoist: typeof data.hoist !== 'undefined' ? data.hoist : this.hoist,
|
||||
mentionable: typeof data.mentionable !== 'undefined' ? data.mentionable : this.mentionable,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const path = require('path');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Represents a webhook.
|
||||
@@ -113,7 +114,7 @@ class Webhook {
|
||||
options.avatarURL = null;
|
||||
}
|
||||
|
||||
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
|
||||
if (typeof content !== 'undefined') content = Util.resolveString(content);
|
||||
if (content) {
|
||||
if (options.disableEveryone ||
|
||||
(typeof options.disableEveryone === 'undefined' && this.client.options.disableEveryone)
|
||||
|
||||
@@ -12,7 +12,7 @@ module.exports = function sendMessage(channel, options) {
|
||||
}
|
||||
|
||||
if (content) {
|
||||
content = channel.client.resolver.resolveString(content);
|
||||
content = Util.resolveString(content);
|
||||
if (split && typeof split !== 'object') split = {};
|
||||
// Wrap everything in a code block
|
||||
if (typeof code !== 'undefined' && (typeof code !== 'boolean' || code === true)) {
|
||||
|
||||
Reference in New Issue
Block a user