Fixed DataStore, deprecation leftovers and a bit of Event Constants (#1841)

* Fixed leftover fetchThing and removed unused methods/error messages

* Added resume event constant and used event constants wherever possible

* Replaced mentions of removed method name with their new name.

* Fixed typo: resume -> resumed
This commit is contained in:
SpaceEEC
2017-08-28 00:11:28 +02:00
committed by Crawl
parent c4fecf6609
commit 65d9d46a3c
13 changed files with 22 additions and 32 deletions

View File

@@ -365,7 +365,7 @@ class Client extends EventEmitter {
throw new TypeError('CLIENT_INVALID_OPTION', 'Lifetime', 'a number'); throw new TypeError('CLIENT_INVALID_OPTION', 'Lifetime', 'a number');
} }
if (lifetime <= 0) { if (lifetime <= 0) {
this.emit('debug', 'Didn\'t sweep messages - lifetime is unlimited'); this.emit(Constants.Events.DEBUG, 'Didn\'t sweep messages - lifetime is unlimited');
return -1; return -1;
} }
@@ -386,7 +386,8 @@ class Client extends EventEmitter {
} }
} }
this.emit('debug', `Swept ${messages} messages older than ${lifetime} seconds in ${channels} text-based channels`); this.emit(Constants.Events.DEBUG,
`Swept ${messages} messages older than ${lifetime} seconds in ${channels} text-based channels`);
return messages; return messages;
} }

View File

@@ -37,7 +37,7 @@ class WebSocketManager extends EventEmitter {
* @returns {void} * @returns {void}
*/ */
debug(message) { debug(message) {
return this.client.emit('debug', `[ws] ${message}`); return this.client.emit(Constants.Events.DEBUG, `[ws] ${message}`);
} }
/** /**

View File

@@ -1,5 +1,5 @@
const AbstractHandler = require('./AbstractHandler'); const AbstractHandler = require('./AbstractHandler');
const Constants = require('../../../../util/Constants');
const ClientUser = require('../../../../structures/ClientUser'); const ClientUser = require('../../../../structures/ClientUser');
class ReadyHandler extends AbstractHandler { class ReadyHandler extends AbstractHandler {
@@ -73,7 +73,7 @@ class ReadyHandler extends AbstractHandler {
ws.sessionID = data.session_id; ws.sessionID = data.session_id;
ws._trace = data._trace; ws._trace = data._trace;
client.emit('debug', `READY ${ws._trace.join(' -> ')} ${ws.sessionID}`); client.emit(Constants.Events.DEBUG, `READY ${ws._trace.join(' -> ')} ${ws.sessionID}`);
ws.checkIfReady(); ws.checkIfReady();
} }
} }

View File

@@ -5,11 +5,11 @@ class RelationshipAddHandler extends AbstractHandler {
const client = this.packetManager.client; const client = this.packetManager.client;
const data = packet.d; const data = packet.d;
if (data.type === 1) { if (data.type === 1) {
client.fetchUser(data.id).then(user => { client.users.fetch(data.id).then(user => {
client.user.friends.set(user.id, user); client.user.friends.set(user.id, user);
}); });
} else if (data.type === 2) { } else if (data.type === 2) {
client.fetchUser(data.id).then(user => { client.users.fetch(data.id).then(user => {
client.user.blocked.set(user.id, user); client.user.blocked.set(user.id, user);
}); });
} }

View File

@@ -14,14 +14,14 @@ class ResumedHandler extends AbstractHandler {
const replayed = ws.sequence - ws.closeSequence; const replayed = ws.sequence - ws.closeSequence;
ws.debug(`RESUMED ${ws._trace.join(' -> ')} | replayed ${replayed} events.`); ws.debug(`RESUMED ${ws._trace.join(' -> ')} | replayed ${replayed} events.`);
client.emit('resume', replayed); client.emit(Constants.Events.RESUMED, replayed);
ws.heartbeat(); ws.heartbeat();
} }
} }
/** /**
* Emitted whenever a WebSocket resumes. * Emitted whenever a WebSocket resumed.
* @event Client#resume * @event Client#resumed
* @param {number} replayed The number of events that were replayed * @param {number} replayed The number of events that were replayed
*/ */

View File

@@ -6,10 +6,8 @@ const Messages = {
TOKEN_INVALID: 'An invalid token was provided.', TOKEN_INVALID: 'An invalid token was provided.',
TOKEN_MISSING: 'Request to use token, but token was unavailable to the client.', TOKEN_MISSING: 'Request to use token, but token was unavailable to the client.',
FEATURE_BOT_ONLY: 'Only bot accounts are able to make use of this feature.',
FEATURE_USER_ONLY: 'Only user accounts are able to make use of this feature.', FEATURE_USER_ONLY: 'Only user accounts are able to make use of this feature.',
WS_BAD_MESSAGE: 'A bad message was received from the websocket; either bad compression, or not JSON.',
WS_CONNECTION_EXISTS: 'There is already an existing WebSocket connection.', WS_CONNECTION_EXISTS: 'There is already an existing WebSocket connection.',
WS_NOT_OPEN: (data = 'data') => `Websocket not open to send ${data}`, WS_NOT_OPEN: (data = 'data') => `Websocket not open to send ${data}`,
@@ -25,8 +23,6 @@ const Messages = {
SHARDING_IN_PROCESS: 'Shards are still being spawned', SHARDING_IN_PROCESS: 'Shards are still being spawned',
SHARDING_ALREADY_SPAWNED: count => `Already spawned ${count} shards`, SHARDING_ALREADY_SPAWNED: count => `Already spawned ${count} shards`,
SHARD_MESSAGE_FAILED: 'Failed to send message to master process.',
COLOR_RANGE: 'Color must be within the range 0 - 16777215 (0xFFFFFF).', COLOR_RANGE: 'Color must be within the range 0 - 16777215 (0xFFFFFF).',
COLOR_CONVERT: 'Unable to convert color to a number.', COLOR_CONVERT: 'Unable to convert color to a number.',
@@ -39,8 +35,6 @@ const Messages = {
FILE_NOT_FOUND: file => `File could not be found: ${file}`, FILE_NOT_FOUND: file => `File could not be found: ${file}`,
USER_STATUS: 'User status must be a string',
USER_NOT_CACHED: 'User is not cached. Use Client.fetchUser first.',
USER_NO_DMCHANNEL: 'No DM Channel exists!', USER_NO_DMCHANNEL: 'No DM Channel exists!',
VOICE_INVALID_HEARTBEAT: 'Tried to set voice heartbeat but no valid interval was specified.', VOICE_INVALID_HEARTBEAT: 'Tried to set voice heartbeat but no valid interval was specified.',
@@ -91,7 +85,6 @@ const Messages = {
INVALID_TYPE: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`, INVALID_TYPE: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`,
WEBHOOK_MESSAGE: 'The message was not sent by a webhook.', WEBHOOK_MESSAGE: 'The message was not sent by a webhook.',
EMOJI_TYPE: 'Emoji must be a string or Emoji/ReactionEmoji', EMOJI_TYPE: 'Emoji must be a string or Emoji/ReactionEmoji',

View File

@@ -1,4 +1,5 @@
const Util = require('../util/Util'); const Util = require('../util/Util');
const Constants = require('../util/Constants');
const { Error } = require('../errors'); const { Error } = require('../errors');
/** /**
@@ -123,7 +124,7 @@ class ShardClientUtil {
_respond(type, message) { _respond(type, message) {
this.send(message).catch(err => { this.send(message).catch(err => {
err.message = `Error when sending ${type} response to master process: ${err.message}`; err.message = `Error when sending ${type} response to master process: ${err.message}`;
this.client.emit('error', err); this.client.emit(Constants.Events.ERROR, err);
}); });
} }
@@ -136,7 +137,8 @@ class ShardClientUtil {
if (!this._singleton) { if (!this._singleton) {
this._singleton = new this(client); this._singleton = new this(client);
} else { } else {
client.emit('warn', 'Multiple clients created in child process; only the first will handle sharding helpers.'); client.emit(Constants.Events.WARN,
'Multiple clients created in child process; only the first will handle sharding helpers.');
} }
return this._singleton; return this._singleton;
} }

View File

@@ -38,9 +38,6 @@ class DMChannel extends Channel {
// These are here only for documentation purposes - they are implemented by TextBasedChannel // These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function */
send() {} send() {}
fetchMessage() {}
fetchMessages() {}
fetchPinnedMessages() {}
search() {} search() {}
startTyping() {} startTyping() {}
stopTyping() {} stopTyping() {}

View File

@@ -219,9 +219,6 @@ class GroupDMChannel extends Channel {
// These are here only for documentation purposes - they are implemented by TextBasedChannel // These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function */
send() {} send() {}
fetchMessage() {}
fetchMessages() {}
fetchPinnedMessages() {}
search() {} search() {}
startTyping() {} startTyping() {}
stopTyping() {} stopTyping() {}

View File

@@ -285,7 +285,7 @@ class Message extends Base {
*/ */
/** /**
* Similar to createCollector but in promise form. * Similar to createMessageCollector but in promise form.
* Resolves with a collection of reactions that pass the specified filter. * Resolves with a collection of reactions that pass the specified filter.
* @param {CollectorFilter} filter The filter function to use * @param {CollectorFilter} filter The filter function to use
* @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector * @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector

View File

@@ -73,9 +73,6 @@ class TextChannel extends GuildChannel {
// These are here only for documentation purposes - they are implemented by TextBasedChannel // These are here only for documentation purposes - they are implemented by TextBasedChannel
/* eslint-disable no-empty-function */ /* eslint-disable no-empty-function */
send() {} send() {}
fetchMessage() {}
fetchMessages() {}
fetchPinnedMessages() {}
search() {} search() {}
startTyping() {} startTyping() {}
stopTyping() {} stopTyping() {}

View File

@@ -245,8 +245,8 @@ class TextBasedChannel {
*/ */
/** /**
* Similar to createCollector but in promise form. Resolves with a collection of messages that pass the specified * Similar to createMessageCollector but in promise form.
* filter. * Resolves with a collection of messages that pass the specified filter.
* @param {CollectorFilter} filter The filter function to use * @param {CollectorFilter} filter The filter function to use
* @param {AwaitMessagesOptions} [options={}] Optional options to pass to the internal collector * @param {AwaitMessagesOptions} [options={}] Optional options to pass to the internal collector
* @returns {Promise<Collection<Snowflake, Message>>} * @returns {Promise<Collection<Snowflake, Message>>}
@@ -279,7 +279,9 @@ class TextBasedChannel {
* @returns {Promise<Collection<Snowflake, Message>>} Deleted messages * @returns {Promise<Collection<Snowflake, Message>>} Deleted messages
*/ */
bulkDelete(messages, filterOld = false) { bulkDelete(messages, filterOld = false) {
if (!isNaN(messages)) return this.fetchMessages({ limit: messages }).then(msgs => this.bulkDelete(msgs, filterOld)); if (!isNaN(messages)) {
return this.messages.fetch({ limit: messages }).then(msgs => this.bulkDelete(msgs, filterOld));
}
if (messages instanceof Array || messages instanceof Collection) { if (messages instanceof Array || messages instanceof Collection) {
let messageIDs = messages instanceof Collection ? messages.keyArray() : messages.map(m => m.id); let messageIDs = messages instanceof Collection ? messages.keyArray() : messages.map(m => m.id);
if (filterOld) { if (filterOld) {

View File

@@ -196,6 +196,7 @@ exports.VoiceOPCodes = {
exports.Events = { exports.Events = {
READY: 'ready', READY: 'ready',
RESUMED: 'resumed',
GUILD_CREATE: 'guildCreate', GUILD_CREATE: 'guildCreate',
GUILD_DELETE: 'guildDelete', GUILD_DELETE: 'guildDelete',
GUILD_UPDATE: 'guildUpdate', GUILD_UPDATE: 'guildUpdate',