diff --git a/src/client/ClientDataResolver.js b/src/client/ClientDataResolver.js index b93a40382..c1fe09c17 100644 --- a/src/client/ClientDataResolver.js +++ b/src/client/ClientDataResolver.js @@ -199,7 +199,7 @@ class ClientDataResolver { } if (resource instanceof Buffer) return Promise.resolve(resource); - return Promise.reject(new TypeError('resource is not a string or Buffer')); + return Promise.reject(new TypeError('Resource must be a string or Buffer.')); } } diff --git a/src/client/ClientManager.js b/src/client/ClientManager.js index 0af72e110..f713a997b 100644 --- a/src/client/ClientManager.js +++ b/src/client/ClientManager.js @@ -25,10 +25,10 @@ class ClientManager { * @param {function} reject Function to run when connection fails */ connectToWebSocket(token, resolve, reject) { - this.client.emit('debug', `authenticated using token ${token}`); + this.client.emit('debug', `Authenticated using token ${token}`); this.client.token = token; this.client.rest.methods.getGateway().then(gateway => { - this.client.emit('debug', `using gateway ${gateway}`); + this.client.emit('debug', `Using gateway ${gateway}`); this.client.ws.connect(gateway); this.client.once(Constants.Events.READY, () => resolve(token)); }).catch(reject); diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index bc588e253..2269d59b1 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -15,7 +15,7 @@ class RESTMethods { loginEmailPassword(email, password) { return new Promise((resolve, reject) => { - this.rest.client.emit('debug', 'client launched using email and password - should use token instead'); + this.rest.client.emit('debug', 'Client launched using email and password - should use token instead'); this.rest.client.email = email; this.rest.client.password = password; this.rest.makeRequest('post', Constants.Endpoints.login, false, { email, password }) @@ -368,7 +368,7 @@ class RESTMethods { banGuildMember(guild, member, deleteDays) { return new Promise((resolve, reject) => { const user = this.rest.client.resolver.resolveUser(member); - if (!user) throw new Error('cannot ban a user that is not a user resolvable'); + if (!user) throw new Error('Couldn\'t resolve the user to ban.'); this.rest.makeRequest('put', `${Constants.Endpoints.guildBans(guild.id)}/${user.id}`, true, { 'delete-message-days': deleteDays, }).then(() => { @@ -380,7 +380,7 @@ class RESTMethods { unbanGuildMember(guild, member) { return new Promise((resolve, reject) => { member = this.rest.client.resolver.resolveUser(member); - if (!member) throw new Error('cannot unban a user that is not a user resolvable'); + if (!member) throw new Error('Couldn\'t resolve the user to unban.'); const listener = (eGuild, eUser) => { if (guild.id === guild.id && member.id === eUser.id) { this.rest.client.removeListener(Constants.Events.GUILD_BAN_REMOVE, listener); diff --git a/src/client/voice/ClientVoiceManager.js b/src/client/voice/ClientVoiceManager.js index 0b119914b..d32b4fb3f 100644 --- a/src/client/voice/ClientVoiceManager.js +++ b/src/client/voice/ClientVoiceManager.js @@ -33,7 +33,7 @@ class ClientVoiceManager { */ _checkPendingReady(guildID) { const pendingRequest = this.pending.get(guildID); - if (!pendingRequest) throw new Error('Guild not pending'); + if (!pendingRequest) throw new Error('Guild not pending.'); if (pendingRequest.token && pendingRequest.sessionID && pendingRequest.endpoint) { const { channel, token, sessionID, endpoint, resolve, reject } = pendingRequest; const voiceConnection = new VoiceConnection(this, channel, token, sessionID, endpoint, resolve, reject); @@ -53,7 +53,7 @@ class ClientVoiceManager { */ _receivedVoiceServer(guildID, token, endpoint) { const pendingRequest = this.pending.get(guildID); - if (!pendingRequest) throw new Error('Guild not pending'); + if (!pendingRequest) throw new Error('Guild not pending.'); pendingRequest.token = token; // remove the port otherwise it errors ¯\_(ツ)_/¯ pendingRequest.endpoint = endpoint.match(/([^:]*)/)[0]; @@ -67,7 +67,7 @@ class ClientVoiceManager { */ _receivedVoiceStateUpdate(guildID, sessionID) { const pendingRequest = this.pending.get(guildID); - if (!pendingRequest) throw new Error('Guild not pending'); + if (!pendingRequest) throw new Error('Guild not pending.'); pendingRequest.sessionID = sessionID; this._checkPendingReady(guildID); } @@ -97,7 +97,9 @@ class ClientVoiceManager { */ joinChannel(channel) { return new Promise((resolve, reject) => { - if (this.pending.get(channel.guild.id)) throw new Error('already connecting to a channel in this guild'); + if (this.pending.get(channel.guild.id)) { + throw new Error(`Already connecting to a channel in guild.`); + } const existingConn = this.connections.get(channel.guild.id); if (existingConn) { if (existingConn.channel.id !== channel.id) { @@ -116,7 +118,7 @@ class ClientVoiceManager { reject, }); this._sendWSJoin(channel); - this.client.setTimeout(() => reject(new Error('connection not established in 15s time period')), 15000); + this.client.setTimeout(() => reject(new Error('Connection not established within 15 seconds.')), 15000); }); } } diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index ade33a1ee..52ea5efda 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -109,7 +109,7 @@ class StreamDispatcher extends EventEmitter { const data = this.streamingData; if (data.missed >= 5) { - this._triggerTerminalState('error', new Error('stream is not generating fast enough')); + this._triggerTerminalState('error', new Error('Stream is not generating quickly enough.')); return; } @@ -184,7 +184,7 @@ class StreamDispatcher extends EventEmitter { * @event StreamDispatcher#debug * @param {string} information The debug information */ - this.emit('debug', `triggered terminal state ${state} - stream is now dead`); + this.emit('debug', `Triggered terminal state ${state} - stream is now dead`); this._triggered = true; this._setSpeaking(false); switch (state) { @@ -195,14 +195,14 @@ class StreamDispatcher extends EventEmitter { this._triggerError(err); break; default: - this.emit('error', 'unknown trigger state'); + this.emit('error', 'Unknown trigger state'); break; } } _startStreaming() { if (!this.stream) { - this.emit('error', 'no stream'); + this.emit('error', 'No stream'); return; } diff --git a/src/client/voice/opus/OpusEngineList.js b/src/client/voice/opus/OpusEngineList.js index a7f225f22..ffd512a64 100644 --- a/src/client/voice/opus/OpusEngineList.js +++ b/src/client/voice/opus/OpusEngineList.js @@ -20,5 +20,5 @@ exports.fetch = () => { const fetched = fetch(encoder); if (fetched) return fetched; } - throw new Error('could not find an opus engine'); + throw new Error('Couldn\'t find an Opus engine.'); }; diff --git a/src/client/voice/player/BasePlayer.js b/src/client/voice/player/BasePlayer.js index 2114bd8a1..3af99f9f9 100644 --- a/src/client/voice/player/BasePlayer.js +++ b/src/client/voice/player/BasePlayer.js @@ -50,30 +50,30 @@ class VoiceConnectionPlayer extends EventEmitter { killStream(stream) { const streams = this.processMap.get(stream); this._streamingData = this.dispatcher.streamingData; - this.emit('debug', 'cleaning up streams after end/error'); + this.emit('debug', 'Cleaning up streams after end/error'); if (streams) { this.processMap.delete(stream); if (streams.inputStream && streams.pcmConverter) { try { if (streams.inputStream.unpipe) { streams.inputStream.unpipe(streams.pcmConverter.stdin); - this.emit('debug', 'stream kill part 4/5 pass'); + this.emit('debug', 'Stream kill part 4/5 pass'); } if (streams.pcmConverter.stdout.destroy) { streams.pcmConverter.stdout.destroy(); - this.emit('debug', 'stream kill part 2/5 pass'); + this.emit('debug', 'Stream kill part 2/5 pass'); } if (streams.pcmConverter && streams.pcmConverter.kill) { streams.pcmConverter.kill('SIGINT'); - this.emit('debug', 'stream kill part 3/5 pass'); + this.emit('debug', 'Stream kill part 3/5 pass'); } if (streams.pcmConverter.stdin) { streams.pcmConverter.stdin.end(); - this.emit('debug', 'stream kill part 1/5 pass'); + this.emit('debug', 'Stream kill part 1/5 pass'); } if (streams.inputStream.destroy) { streams.inputStream.destroy(); - this.emit('debug', 'stream kill part 5/5 pass'); + this.emit('debug', 'Stream kill part 5/5 pass'); } } catch (err) { return err; diff --git a/src/client/voice/receiver/VoiceReceiver.js b/src/client/voice/receiver/VoiceReceiver.js index f28fbe463..77352a301 100644 --- a/src/client/voice/receiver/VoiceReceiver.js +++ b/src/client/voice/receiver/VoiceReceiver.js @@ -34,9 +34,7 @@ class VoiceReceiver extends EventEmitter { const ssrc = +msg.readUInt32BE(8).toString(10); const user = this.connection.ssrcMap.get(ssrc); if (!user) { - if (!this.queues.has(ssrc)) { - this.queues.set(ssrc, []); - } + if (!this.queues.has(ssrc)) this.queues.set(ssrc, []); this.queues.get(ssrc).push(msg); } else { if (this.queues.get(ssrc)) { @@ -58,12 +56,8 @@ class VoiceReceiver extends EventEmitter { */ createOpusStream(user) { user = this.connection.manager.client.resolver.resolveUser(user); - if (!user) { - throw new Error('invalid user object supplied'); - } - if (this.opusStreams.get(user.id)) { - throw new Error('there is already an existing stream for that user!'); - } + if (!user) throw new Error('Couldn\'t resolve the user to create Opus stream.'); + if (this.opusStreams.get(user.id)) throw new Error('There is already an existing stream for that user.'); const stream = new Readable(); this.opusStreams.set(user.id, stream); return stream; @@ -77,8 +71,8 @@ class VoiceReceiver extends EventEmitter { */ createPCMStream(user) { user = this.connection.manager.client.resolver.resolveUser(user); - if (!user) throw new Error('invalid user object supplied'); - if (this.pcmStreams.get(user.id)) throw new Error('there is already an existing stream for that user!'); + if (!user) throw new Error('Couldn\'t resolve the user to create PCM stream.'); + if (this.pcmStreams.get(user.id)) throw new Error('There is already an existing stream for that user.'); const stream = new Readable(); this.pcmStreams.set(user.id, stream); return stream; @@ -93,7 +87,7 @@ class VoiceReceiver extends EventEmitter { * @event VoiceReceiver#warn * @param {string} message The warning message */ - this.emit('warn', 'failed to decrypt voice packet'); + this.emit('warn', 'Failed to decrypt voice packet'); return; } data = new Buffer(data); diff --git a/src/client/websocket/WebSocketManager.js b/src/client/websocket/WebSocketManager.js index a5d643ff2..7124b9c40 100644 --- a/src/client/websocket/WebSocketManager.js +++ b/src/client/websocket/WebSocketManager.js @@ -56,7 +56,7 @@ class WebSocketManager { * @param {string} gateway The gateway to connect to */ connect(gateway) { - this.client.emit('debug', `connecting to gateway ${gateway}`); + this.client.emit('debug', `Connecting to gateway ${gateway}`); this.normalReady = false; this.status = Constants.Status.CONNECTING; this.ws = new WebSocket(gateway); @@ -115,7 +115,7 @@ class WebSocketManager { * Run whenever the gateway connections opens up */ eventOpen() { - this.client.emit('debug', 'connection to gateway opened'); + this.client.emit('debug', 'Connection to gateway opened'); if (this.reconnecting) this._sendResume(); else this._sendNewIdentify(); } @@ -224,7 +224,7 @@ class WebSocketManager { if (this.client.options.fetch_all_members) { const promises = this.client.guilds.array().map(g => g.fetchMembers()); Promise.all(promises).then(() => this._emitReady()).catch(e => { - this.client.emit('warn', `error on pre-ready guild member fetching - ${e}`); + this.client.emit('warn', `Error on pre-ready guild member fetching - ${e}`); this._emitReady(); }); return; diff --git a/src/sharding/ShardingManager.js b/src/sharding/ShardingManager.js index 902506a3b..a6ce22b00 100644 --- a/src/sharding/ShardingManager.js +++ b/src/sharding/ShardingManager.js @@ -24,10 +24,10 @@ class ShardingManager extends EventEmitter { * @type {string} */ this.file = file; - if (!file) throw new Error('file must be specified'); + if (!file) throw new Error('File must be specified.'); if (!path.isAbsolute(file)) this.file = path.resolve(process.cwd(), file); const stats = fs.statSync(this.file); - if (!stats.isFile()) throw new Error('file path does not point to a file'); + if (!stats.isFile()) throw new Error('File path does not point to a file.'); /** * The amount of shards that this manager is going to spawn @@ -35,9 +35,9 @@ class ShardingManager extends EventEmitter { */ this.totalShards = typeof totalShards !== 'undefined' ? totalShards : 1; if (typeof this.totalShards !== 'number' || isNaN(this.totalShards)) { - throw new TypeError('amout of shards must be a number'); + throw new TypeError('Amount of shards must be a number.'); } - if (this.totalShards < 1) throw new RangeError('amount of shards must be at least 1'); + if (this.totalShards < 1) throw new RangeError('Amount of shards must be at least 1.'); /** * A collection of shards that this manager has spawned @@ -62,8 +62,8 @@ class ShardingManager extends EventEmitter { */ spawn(amount) { if (typeof amount !== 'undefined') { - if (typeof amount !== 'number' || isNaN(amount)) throw new TypeError('amout of shards must be a number'); - if (amount < 1) throw new RangeError('amount of shards must be at least 1'); + if (typeof amount !== 'number' || isNaN(amount)) throw new TypeError('Amount of shards must be a number.'); + if (amount < 1) throw new RangeError('Amount of shards must be at least 1.'); this.totalShards = amount; } diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 7e3cb10b4..3558c384f 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -426,9 +426,9 @@ class Guild { * @returns {Promise} */ fetchMember(user) { - if (this._fetchWaiter) return Promise.reject(new Error('already fetching guild members')); + if (this._fetchWaiter) return Promise.reject(new Error('Already fetching guild members.')); user = this.client.resolver.resolveUser(user); - if (!user) return Promise.reject(new Error('user is not cached')); + if (!user) return Promise.reject(new Error('User is not cached. Use Client.fetchUser first.')); if (this.members.has(user.id)) return Promise.resolve(this.members.get(user.id)); return this.client.rest.methods.getGuildMember(this, user); } @@ -441,7 +441,7 @@ class Guild { */ fetchMembers(query = '') { return new Promise((resolve, reject) => { - if (this._fetchWaiter) throw new Error('already fetching guild members'); + if (this._fetchWaiter) throw new Error('Already fetching guild members in ${this.id}.'); if (this.memberCount === this.members.size) { resolve(this); return; @@ -456,7 +456,7 @@ class Guild { }, }); this._checkChunks(); - this.client.setTimeout(() => reject(new Error('members not here in time')), 120 * 1000); + this.client.setTimeout(() => reject(new Error('Members didn\'t arrive in time.')), 120 * 1000); }); } diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index 94e2eb939..e5644bf78 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -133,7 +133,7 @@ class GuildChannel extends Channel { } else { userOrRole = this.client.resolver.resolveUser(userOrRole); payload.type = 'member'; - if (!userOrRole) return Promise.reject(new TypeError('supplied parameter was neither a user or a role')); + if (!userOrRole) return Promise.reject(new TypeError('Supplied parameter was neither a User nor a Role.')); } payload.id = userOrRole.id; diff --git a/src/structures/interface/TextBasedChannel.js b/src/structures/interface/TextBasedChannel.js index ec0e5358c..ce6ce00d4 100644 --- a/src/structures/interface/TextBasedChannel.js +++ b/src/structures/interface/TextBasedChannel.js @@ -191,7 +191,7 @@ class TextBasedChannel { * channel.startTyping(); */ startTyping(count) { - if (typeof count !== 'undefined' && count < 1) throw new RangeError('count must be at least 1'); + if (typeof count !== 'undefined' && count < 1) throw new RangeError('Count must be at least 1.'); if (!this.client.user._typing.has(this.id)) { this.client.user._typing.set(this.id, { count: count || 1, @@ -304,7 +304,7 @@ class TextBasedChannel { */ bulkDelete(messages) { if (messages instanceof Collection) messages = messages.array(); - if (!(messages instanceof Array)) return Promise.reject(new TypeError('messages must be an array or collection')); + if (!(messages instanceof Array)) return Promise.reject(new TypeError('Messages must be an Array or Collection.')); const messageIDs = messages.map(m => m.id); return this.client.rest.methods.bulkDeleteMessages(this, messageIDs); } diff --git a/src/util/Collection.js b/src/util/Collection.js index 838770dc9..ae17b6013 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -67,8 +67,8 @@ class Collection extends Map { * collection.findAll('username', 'Bob'); */ findAll(key, value) { - if (typeof key !== 'string') throw new TypeError('key must be a string'); - if (typeof value === 'undefined') throw new Error('value must be specified'); + if (typeof key !== 'string') throw new TypeError('Key must be a string.'); + if (typeof value === 'undefined') throw new Error('Value must be specified.'); const results = []; for (const item of this.values()) { if (item[key] === value) results.push(item); @@ -85,8 +85,8 @@ class Collection extends Map { * collection.find('id', '123123...'); */ find(key, value) { - if (typeof key !== 'string') throw new TypeError('key must be a string'); - if (typeof value === 'undefined') throw new Error('value must be specified'); + if (typeof key !== 'string') throw new TypeError('Key must be a string.'); + if (typeof value === 'undefined') throw new Error('Value must be specified.'); for (const item of this.values()) { if (item[key] === value) return item; } diff --git a/src/util/Constants.js b/src/util/Constants.js index 14a8a8ca7..fa000faba 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -65,13 +65,13 @@ exports.ChannelTypes = { exports.Package = require('../../package.json'); exports.Errors = { - NO_TOKEN: 'request to use token, but token was unavailable to the client', - NO_BOT_ACCOUNT: 'you should ideally be using a bot account!', - BAD_WS_MESSAGE: 'a bad message was received from the websocket - bad compression or not json', - TOOK_TOO_LONG: 'something took too long to do', - NOT_A_PERMISSION: 'that is not a valid permission string or number', - INVALID_RATE_LIMIT_METHOD: 'unknown rate limiting method', - BAD_LOGIN: 'incorrect login details were provided', + NO_TOKEN: 'Request to use token, but token was unavailable to the client.', + NO_BOT_ACCOUNT: 'You ideally should be using a bot account!', + BAD_WS_MESSAGE: 'A bad message was received from the websocket; either bad compression, or not JSON.', + TOOK_TOO_LONG: 'Something took too long to do.', + NOT_A_PERMISSION: 'Invalid permission string or number.', + INVALID_RATE_LIMIT_METHOD: 'Unknown rate limiting method.', + BAD_LOGIN: 'Incorrect login details were provided.', }; const API = `https://discordapp.com/api/v${exports.DefaultOptions.protocol_version}`;