refactor: make use of destructuring for Constants (#1942)

This commit is contained in:
SpaceEEC
2017-09-16 20:31:36 +02:00
committed by Crawl
parent 25ece1882b
commit ec4c98704f
66 changed files with 262 additions and 262 deletions

View File

@@ -1,5 +1,5 @@
const Collection = require('../../util/Collection');
const Constants = require('../../util/Constants');
const { VoiceStatus } = require('../../util/Constants');
const VoiceConnection = require('./VoiceConnection');
const { Error } = require('../../errors');
@@ -33,7 +33,7 @@ class ClientVoiceManager {
onVoiceStateUpdate({ guild_id, session_id, channel_id }) {
const connection = this.connections.get(guild_id);
if (!connection) return;
if (!channel_id && connection.status !== Constants.VoiceStatus.DISCONNECTED) {
if (!channel_id && connection.status !== VoiceStatus.DISCONNECTED) {
connection._disconnect();
return;
}

View File

@@ -1,7 +1,7 @@
const VoiceWebSocket = require('./VoiceWebSocket');
const VoiceUDP = require('./VoiceUDPClient');
const Util = require('../../util/Util');
const Constants = require('../../util/Constants');
const { OPCodes, VoiceOPCodes, VoiceStatus } = require('../../util/Constants');
const AudioPlayer = require('./player/AudioPlayer');
const VoiceReceiver = require('./receiver/VoiceReceiver');
const EventEmitter = require('events');
@@ -56,7 +56,7 @@ class VoiceConnection extends EventEmitter {
* The current status of the voice connection
* @type {VoiceStatus}
*/
this.status = Constants.VoiceStatus.AUTHENTICATING;
this.status = VoiceStatus.AUTHENTICATING;
/**
* Whether we're currently transmitting audio
@@ -134,10 +134,10 @@ class VoiceConnection extends EventEmitter {
*/
setSpeaking(value) {
if (this.speaking === value) return;
if (this.status !== Constants.VoiceStatus.CONNECTED) return;
if (this.status !== VoiceStatus.CONNECTED) return;
this.speaking = value;
this.sockets.ws.sendPacket({
op: Constants.VoiceOPCodes.SPEAKING,
op: VoiceOPCodes.SPEAKING,
d: {
speaking: true,
delay: 0,
@@ -161,7 +161,7 @@ class VoiceConnection extends EventEmitter {
}, options);
this.client.ws.send({
op: Constants.OPCodes.VOICE_STATE_UPDATE,
op: OPCodes.VOICE_STATE_UPDATE,
d: options,
});
}
@@ -191,7 +191,7 @@ class VoiceConnection extends EventEmitter {
return;
}
if (this.status === Constants.VoiceStatus.AUTHENTICATING) {
if (this.status === VoiceStatus.AUTHENTICATING) {
this.authentication.token = token;
this.authentication.endpoint = endpoint;
this.checkAuthenticated();
@@ -211,7 +211,7 @@ class VoiceConnection extends EventEmitter {
return;
}
if (this.status === Constants.VoiceStatus.AUTHENTICATING) {
if (this.status === VoiceStatus.AUTHENTICATING) {
this.authentication.sessionID = sessionID;
this.checkAuthenticated();
} else if (sessionID !== this.authentication.sessionID) {
@@ -234,7 +234,7 @@ class VoiceConnection extends EventEmitter {
if (token && endpoint && sessionID) {
clearTimeout(this.connectTimeout);
this.status = Constants.VoiceStatus.CONNECTING;
this.status = VoiceStatus.CONNECTING;
/**
* Emitted when we successfully initiate a voice connection.
* @event VoiceConnection#authenticated
@@ -251,7 +251,7 @@ class VoiceConnection extends EventEmitter {
*/
authenticateFailed(reason) {
clearTimeout(this.connectTimeout);
if (this.status === Constants.VoiceStatus.AUTHENTICATING) {
if (this.status === VoiceStatus.AUTHENTICATING) {
/**
* Emitted when we fail to initiate a voice connection.
* @event VoiceConnection#failed
@@ -261,7 +261,7 @@ class VoiceConnection extends EventEmitter {
} else {
this.emit('error', new Error(reason));
}
this.status = Constants.VoiceStatus.DISCONNECTED;
this.status = VoiceStatus.DISCONNECTED;
}
/**
@@ -294,7 +294,7 @@ class VoiceConnection extends EventEmitter {
this.authentication.token = token;
this.authentication.endpoint = endpoint;
this.status = Constants.VoiceStatus.RECONNECTING;
this.status = VoiceStatus.RECONNECTING;
/**
* Emitted when the voice connection is reconnecting (typically after a region change).
* @event VoiceConnection#reconnecting
@@ -320,7 +320,7 @@ class VoiceConnection extends EventEmitter {
*/
_disconnect() {
this.cleanup();
this.status = Constants.VoiceStatus.DISCONNECTED;
this.status = VoiceStatus.DISCONNECTED;
/**
* Emitted when the voice connection disconnects.
* @event VoiceConnection#disconnect
@@ -356,7 +356,7 @@ class VoiceConnection extends EventEmitter {
* @private
*/
connect() {
if (this.status !== Constants.VoiceStatus.RECONNECTING) {
if (this.status !== VoiceStatus.RECONNECTING) {
if (this.sockets.ws) throw new Error('WS_CONNECTION_EXISTS');
if (this.sockets.udp) throw new Error('UDP_CONNECTION_EXISTS');
}
@@ -407,7 +407,7 @@ class VoiceConnection extends EventEmitter {
this.authentication.encryptionMode = mode;
this.authentication.secretKey = secret;
this.status = Constants.VoiceStatus.CONNECTED;
this.status = VoiceStatus.CONNECTED;
/**
* Emitted once the connection is ready, when a promise to join a voice channel resolves,
* the connection will already be ready.
@@ -436,7 +436,7 @@ class VoiceConnection extends EventEmitter {
* @param {User} user The user that has started/stopped speaking
* @param {boolean} speaking Whether or not the user is speaking
*/
if (this.status === Constants.VoiceStatus.CONNECTED) this.emit('speaking', user, speaking);
if (this.status === VoiceStatus.CONNECTED) this.emit('speaking', user, speaking);
guild._memberSpeakUpdate(user_id, speaking);
}

View File

@@ -1,6 +1,6 @@
const udp = require('dgram');
const dns = require('dns');
const Constants = require('../../util/Constants');
const { VoiceOPCodes } = require('../../util/Constants');
const EventEmitter = require('events');
const { Error } = require('../../errors');
@@ -113,7 +113,7 @@ class VoiceConnectionUDPClient extends EventEmitter {
this.localPort = packet.port;
this.voiceConnection.sockets.ws.sendPacket({
op: Constants.VoiceOPCodes.SELECT_PROTOCOL,
op: VoiceOPCodes.SELECT_PROTOCOL,
d: {
protocol: 'udp',
data: {

View File

@@ -1,4 +1,4 @@
const Constants = require('../../util/Constants');
const { OPCodes, VoiceOPCodes } = require('../../util/Constants');
const SecretKey = require('./util/SecretKey');
const EventEmitter = require('events');
const { Error } = require('../../errors');
@@ -109,7 +109,7 @@ class VoiceWebSocket extends EventEmitter {
*/
onOpen() {
this.sendPacket({
op: Constants.OPCodes.DISPATCH,
op: OPCodes.DISPATCH,
d: {
server_id: this.voiceConnection.channel.guild.id,
user_id: this.client.user.id,
@@ -155,7 +155,7 @@ class VoiceWebSocket extends EventEmitter {
*/
onPacket(packet) {
switch (packet.op) {
case Constants.VoiceOPCodes.READY:
case VoiceOPCodes.READY:
this.setHeartbeat(packet.d.heartbeat_interval);
/**
* Emitted once the voice WebSocket receives the ready packet.
@@ -164,7 +164,7 @@ class VoiceWebSocket extends EventEmitter {
*/
this.emit('ready', packet.d);
break;
case Constants.VoiceOPCodes.SESSION_DESCRIPTION:
case VoiceOPCodes.SESSION_DESCRIPTION:
/**
* Emitted once the Voice Websocket receives a description of this voice session.
* @param {string} encryptionMode The type of encryption being used
@@ -173,7 +173,7 @@ class VoiceWebSocket extends EventEmitter {
*/
this.emit('sessionDescription', packet.d.mode, new SecretKey(packet.d.secret_key));
break;
case Constants.VoiceOPCodes.SPEAKING:
case VoiceOPCodes.SPEAKING:
/**
* Emitted whenever a speaking packet is received.
* @param {Object} data
@@ -229,7 +229,7 @@ class VoiceWebSocket extends EventEmitter {
* Sends a heartbeat packet.
*/
sendHeartbeat() {
this.sendPacket({ op: Constants.VoiceOPCodes.HEARTBEAT, d: null }).catch(() => {
this.sendPacket({ op: VoiceOPCodes.HEARTBEAT, d: null }).catch(() => {
this.emit('warn', 'Tried to send heartbeat, but connection is not open');
this.clearHeartbeat();
});

View File

@@ -1,6 +1,6 @@
const VolumeInterface = require('../util/VolumeInterface');
const VoiceBroadcast = require('../VoiceBroadcast');
const Constants = require('../../../util/Constants');
const { VoiceStatus } = require('../../../util/Constants');
const secretbox = require('../util/Secretbox');
@@ -109,7 +109,7 @@ class StreamDispatcher extends VolumeInterface {
setSpeaking(value) {
if (this.speaking === value) return;
if (this.player.voiceConnection.status !== Constants.VoiceStatus.CONNECTED) return;
if (this.player.voiceConnection.status !== VoiceStatus.CONNECTED) return;
this.speaking = value;
/**
* Emitted when the dispatcher starts/stops speaking.