mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
ESLint stuff...
This commit is contained in:
@@ -1,100 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
const Constants = require('../../../util/Constants');
|
||||
|
||||
const BeforeReadyWhitelist = [
|
||||
Constants.WSEvents.READY,
|
||||
Constants.WSEvents.GUILD_CREATE,
|
||||
Constants.WSEvents.GUILD_DELETE,
|
||||
Constants.WSEvents.READY,
|
||||
Constants.WSEvents.GUILD_CREATE,
|
||||
Constants.WSEvents.GUILD_DELETE,
|
||||
];
|
||||
|
||||
class WebSocketPacketManager {
|
||||
|
||||
constructor(websocketManager) {
|
||||
this.ws = websocketManager;
|
||||
this.handlers = {};
|
||||
this.queue = [];
|
||||
constructor(websocketManager) {
|
||||
this.ws = websocketManager;
|
||||
this.handlers = {};
|
||||
this.queue = [];
|
||||
|
||||
this.register(Constants.WSEvents.READY, 'Ready');
|
||||
this.register(Constants.WSEvents.GUILD_CREATE, 'GuildCreate');
|
||||
this.register(Constants.WSEvents.GUILD_DELETE, 'GuildDelete');
|
||||
this.register(Constants.WSEvents.GUILD_UPDATE, 'GuildUpdate');
|
||||
this.register(Constants.WSEvents.GUILD_BAN_ADD, 'GuildBanAdd');
|
||||
this.register(Constants.WSEvents.GUILD_BAN_REMOVE, 'GuildBanRemove');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBER_ADD, 'GuildMemberAdd');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBER_REMOVE, 'GuildMemberRemove');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBER_UPDATE, 'GuildMemberUpdate');
|
||||
this.register(Constants.WSEvents.GUILD_ROLE_CREATE, 'GuildRoleCreate');
|
||||
this.register(Constants.WSEvents.GUILD_ROLE_DELETE, 'GuildRoleDelete');
|
||||
this.register(Constants.WSEvents.GUILD_ROLE_UPDATE, 'GuildRoleUpdate');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBERS_CHUNK, 'GuildMembersChunk');
|
||||
this.register(Constants.WSEvents.CHANNEL_CREATE, 'ChannelCreate');
|
||||
this.register(Constants.WSEvents.CHANNEL_DELETE, 'ChannelDelete');
|
||||
this.register(Constants.WSEvents.CHANNEL_UPDATE, 'ChannelUpdate');
|
||||
this.register(Constants.WSEvents.PRESENCE_UPDATE, 'PresenceUpdate');
|
||||
this.register(Constants.WSEvents.USER_UPDATE, 'UserUpdate');
|
||||
this.register(Constants.WSEvents.VOICE_STATE_UPDATE, 'VoiceStateUpdate');
|
||||
this.register(Constants.WSEvents.TYPING_START, 'TypingStart');
|
||||
this.register(Constants.WSEvents.MESSAGE_CREATE, 'MessageCreate');
|
||||
this.register(Constants.WSEvents.MESSAGE_DELETE, 'MessageDelete');
|
||||
this.register(Constants.WSEvents.MESSAGE_UPDATE, 'MessageUpdate');
|
||||
}
|
||||
this.register(Constants.WSEvents.READY, 'Ready');
|
||||
this.register(Constants.WSEvents.GUILD_CREATE, 'GuildCreate');
|
||||
this.register(Constants.WSEvents.GUILD_DELETE, 'GuildDelete');
|
||||
this.register(Constants.WSEvents.GUILD_UPDATE, 'GuildUpdate');
|
||||
this.register(Constants.WSEvents.GUILD_BAN_ADD, 'GuildBanAdd');
|
||||
this.register(Constants.WSEvents.GUILD_BAN_REMOVE, 'GuildBanRemove');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBER_ADD, 'GuildMemberAdd');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBER_REMOVE, 'GuildMemberRemove');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBER_UPDATE, 'GuildMemberUpdate');
|
||||
this.register(Constants.WSEvents.GUILD_ROLE_CREATE, 'GuildRoleCreate');
|
||||
this.register(Constants.WSEvents.GUILD_ROLE_DELETE, 'GuildRoleDelete');
|
||||
this.register(Constants.WSEvents.GUILD_ROLE_UPDATE, 'GuildRoleUpdate');
|
||||
this.register(Constants.WSEvents.GUILD_MEMBERS_CHUNK, 'GuildMembersChunk');
|
||||
this.register(Constants.WSEvents.CHANNEL_CREATE, 'ChannelCreate');
|
||||
this.register(Constants.WSEvents.CHANNEL_DELETE, 'ChannelDelete');
|
||||
this.register(Constants.WSEvents.CHANNEL_UPDATE, 'ChannelUpdate');
|
||||
this.register(Constants.WSEvents.PRESENCE_UPDATE, 'PresenceUpdate');
|
||||
this.register(Constants.WSEvents.USER_UPDATE, 'UserUpdate');
|
||||
this.register(Constants.WSEvents.VOICE_STATE_UPDATE, 'VoiceStateUpdate');
|
||||
this.register(Constants.WSEvents.TYPING_START, 'TypingStart');
|
||||
this.register(Constants.WSEvents.MESSAGE_CREATE, 'MessageCreate');
|
||||
this.register(Constants.WSEvents.MESSAGE_DELETE, 'MessageDelete');
|
||||
this.register(Constants.WSEvents.MESSAGE_UPDATE, 'MessageUpdate');
|
||||
}
|
||||
|
||||
get client() {
|
||||
return this.ws.client;
|
||||
}
|
||||
get client() {
|
||||
return this.ws.client;
|
||||
}
|
||||
|
||||
register(event, handle) {
|
||||
let Handler = require(`./handlers/${handle}`);
|
||||
this.handlers[event] = new Handler(this);
|
||||
}
|
||||
register(event, handle) {
|
||||
const Handler = require(`./handlers/${handle}`);
|
||||
this.handlers[event] = new Handler(this);
|
||||
}
|
||||
|
||||
handleQueue() {
|
||||
for (let packetIndex in this.queue) {
|
||||
this.handle(this.queue[packetIndex]);
|
||||
this.queue.splice(packetIndex, 1);
|
||||
}
|
||||
}
|
||||
handleQueue() {
|
||||
this.queue.forEach((element, index) => {
|
||||
this.handle(this.queue[index]);
|
||||
this.queue.splice(index, 1);
|
||||
});
|
||||
}
|
||||
|
||||
setSequence(s) {
|
||||
if (s && s > this.ws.store.sequence) {
|
||||
this.ws.store.sequence = s;
|
||||
}
|
||||
}
|
||||
setSequence(s) {
|
||||
if (s && s > this.ws.store.sequence) {
|
||||
this.ws.store.sequence = s;
|
||||
}
|
||||
}
|
||||
|
||||
handle(packet) {
|
||||
handle(packet) {
|
||||
if (packet.op === Constants.OPCodes.RECONNECT) {
|
||||
this.setSequence(packet.s);
|
||||
this.ws.tryReconnect();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (packet.op === Constants.OPCodes.RECONNECT) {
|
||||
this.setSequence(packet.s);
|
||||
this.ws.tryReconnect();
|
||||
return;
|
||||
}
|
||||
if (packet.op === Constants.OPCodes.INVALID_SESSION) {
|
||||
this.ws._sendNewIdentify();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (packet.op === Constants.OPCodes.INVALID_SESSION) {
|
||||
this.ws._sendNewIdentify();
|
||||
return;
|
||||
}
|
||||
if (this.ws.reconnecting) {
|
||||
this.ws.reconnecting = false;
|
||||
this.ws.checkIfReady();
|
||||
}
|
||||
|
||||
if (this.ws.reconnecting) {
|
||||
this.ws.reconnecting = false;
|
||||
this.ws.checkIfReady();
|
||||
}
|
||||
this.setSequence(packet.s);
|
||||
|
||||
this.setSequence(packet.s);
|
||||
if (this.ws.status !== Constants.Status.READY) {
|
||||
if (BeforeReadyWhitelist.indexOf(packet.t) === -1) {
|
||||
this.queue.push(packet);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.ws.status !== Constants.Status.READY) {
|
||||
if (BeforeReadyWhitelist.indexOf(packet.t) === -1) {
|
||||
this.queue.push(packet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.handlers[packet.t]) {
|
||||
return this.handlers[packet.t].handle(packet);
|
||||
}
|
||||
|
||||
if (this.handlers[packet.t]) {
|
||||
return this.handlers[packet.t].handle(packet);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user