refactor: use EventEmitter.off in favour of EventEmitter.removeListener

This commit is contained in:
NotSugden
2020-02-26 20:38:26 +00:00
parent 9953b4d267
commit 2a36dff43a
8 changed files with 28 additions and 28 deletions

View File

@@ -98,7 +98,7 @@ class ClientVoiceManager {
connection.once('authenticated', () => {
connection.once('ready', () => {
resolve(connection);
connection.removeListener('error', reject);
connection.off('error', reject);
});
connection.once('disconnect', () => this.connections.delete(channel.guild.id));
});

View File

@@ -88,7 +88,7 @@ class GuildManager extends BaseManager {
const handleGuild = guild => {
if (guild.id === data.id) {
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.off(Events.GUILD_CREATE, handleGuild);
this.client.clearTimeout(timeout);
resolve(guild);
}
@@ -96,7 +96,7 @@ class GuildManager extends BaseManager {
this.client.on(Events.GUILD_CREATE, handleGuild);
const timeout = this.client.setTimeout(() => {
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.off(Events.GUILD_CREATE, handleGuild);
resolve(this.client.guilds.add(data));
}, 10000);
return undefined;

View File

@@ -224,12 +224,12 @@ class GuildMemberManager extends BaseManager {
if (this.guild.memberCount <= this.cache.size ||
((query || limit) && members.size < 1000) ||
(limit && fetchedMembers.size >= limit)) {
this.guild.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
this.guild.client.off(Events.GUILD_MEMBERS_CHUNK, handler);
resolve(query || limit ? fetchedMembers : this.cache);
}
};
const timeout = this.guild.client.setTimeout(() => {
this.guild.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
this.guild.client.off(Events.GUILD_MEMBERS_CHUNK, handler);
reject(new Error('GUILD_MEMBERS_TIMEOUT'));
}, 120e3);
this.guild.client.on(Events.GUILD_MEMBERS_CHUNK, handler);

View File

@@ -144,10 +144,10 @@ class Shard extends EventEmitter {
*/
kill() {
if (this.process) {
this.process.removeListener('exit', this._exitListener);
this.process.off('exit', this._exitListener);
this.process.kill();
} else {
this.worker.removeListener('exit', this._exitListener);
this.worker.off('exit', this._exitListener);
this.worker.terminate();
}
@@ -202,14 +202,14 @@ class Shard extends EventEmitter {
const listener = message => {
if (!message || message._fetchProp !== prop) return;
child.removeListener('message', listener);
child.off('message', listener);
this._fetches.delete(prop);
resolve(message._result);
};
child.on('message', listener);
this.send({ _fetchProp: prop }).catch(err => {
child.removeListener('message', listener);
child.off('message', listener);
this._fetches.delete(prop);
reject(err);
});
@@ -232,7 +232,7 @@ class Shard extends EventEmitter {
const listener = message => {
if (!message || message._eval !== script) return;
child.removeListener('message', listener);
child.off('message', listener);
this._evals.delete(script);
if (!message._error) resolve(message._result); else reject(Util.makeError(message._error));
};
@@ -240,7 +240,7 @@ class Shard extends EventEmitter {
const _eval = typeof script === 'function' ? `(${script})(this)` : script;
this.send({ _eval }).catch(err => {
child.removeListener('message', listener);
child.off('message', listener);
this._evals.delete(script);
reject(err);
});

View File

@@ -97,13 +97,13 @@ class ShardClientUtil {
const listener = message => {
if (!message || message._sFetchProp !== prop) return;
parent.removeListener('message', listener);
parent.off('message', listener);
if (!message._error) resolve(message._result); else reject(Util.makeError(message._error));
};
parent.on('message', listener);
this.send({ _sFetchProp: prop }).catch(err => {
parent.removeListener('message', listener);
parent.off('message', listener);
reject(err);
});
});
@@ -126,13 +126,13 @@ class ShardClientUtil {
const listener = message => {
if (!message || message._sEval !== script) return;
parent.removeListener('message', listener);
parent.off('message', listener);
if (!message._error) resolve(message._result); else reject(Util.makeError(message._error));
};
parent.on('message', listener);
this.send({ _sEval: script }).catch(err => {
parent.removeListener('message', listener);
parent.off('message', listener);
reject(err);
});
});

View File

@@ -50,11 +50,11 @@ class MessageCollector extends Collector {
this.client.on(Events.GUILD_DELETE, this._handleGuildDeletion);
this.once('end', () => {
this.client.removeListener(Events.MESSAGE_CREATE, this.handleCollect);
this.client.removeListener(Events.MESSAGE_DELETE, this.handleDispose);
this.client.removeListener(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.removeListener(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.off(Events.MESSAGE_CREATE, this.handleCollect);
this.client.off(Events.MESSAGE_DELETE, this.handleDispose);
this.client.off(Events.MESSAGE_BULK_DELETE, bulkDeleteListener);
this.client.off(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.off(Events.GUILD_DELETE, this._handleGuildDeletion);
if (this.client.getMaxListeners() !== 0) this.client.setMaxListeners(this.client.getMaxListeners() - 1);
});
}

View File

@@ -58,12 +58,12 @@ class ReactionCollector extends Collector {
this.client.on(Events.GUILD_DELETE, this._handleGuildDeletion);
this.once('end', () => {
this.client.removeListener(Events.MESSAGE_REACTION_ADD, this.handleCollect);
this.client.removeListener(Events.MESSAGE_REACTION_REMOVE, this.handleDispose);
this.client.removeListener(Events.MESSAGE_REACTION_REMOVE_ALL, this.empty);
this.client.removeListener(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.removeListener(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
this.client.off(Events.MESSAGE_REACTION_ADD, this.handleCollect);
this.client.off(Events.MESSAGE_REACTION_REMOVE, this.handleDispose);
this.client.off(Events.MESSAGE_REACTION_REMOVE_ALL, this.empty);
this.client.off(Events.MESSAGE_DELETE, this._handleMessageDeletion);
this.client.off(Events.CHANNEL_DELETE, this._handleChannelDeletion);
this.client.off(Events.GUILD_DELETE, this._handleGuildDeletion);
if (this.client.getMaxListeners() !== 0) this.client.setMaxListeners(this.client.getMaxListeners() - 1);
});

View File

@@ -142,8 +142,8 @@ class Collector extends EventEmitter {
}
const cleanup = () => {
this.removeListener('collect', onCollect);
this.removeListener('end', onEnd);
this.off('collect', onCollect);
this.off('end', onEnd);
};
const onCollect = item => {