Cleanup Part 2: Electric Boogaloo (Reloaded) (#594)

* Cleanup Part 2: Electric Boogaloo (Reloaded)

* Moar cleanup

* Tweak NOT_A_PERMISSION error
This commit is contained in:
Schuyler Cebulskie
2016-09-04 05:08:09 -04:00
committed by Amish Shah
parent 5a9c42061f
commit 0b908f5bce
95 changed files with 946 additions and 1526 deletions

View File

@@ -71,14 +71,14 @@ class VoiceConnection extends EventEmitter {
/**
* Executed whenever an error occurs with the UDP/WebSocket sub-client
* @private
* @param {Error} err The error that occurred
* @param {Error} err The encountered error
*/
_onError(err) {
this._reject(err);
/**
* Emitted whenever the connection encounters a fatal error.
* @event VoiceConnection#error
* @param {Error} error the encountered error
* @param {Error} error The encountered error
*/
this.emit('error', err);
this._shutdown(err);
@@ -86,7 +86,7 @@ class VoiceConnection extends EventEmitter {
/**
* Disconnects the Client from the Voice Channel
* @param {string} [reason='user requested'] the reason of the disconnection
* @param {string} [reason='user requested'] The reason of the disconnection
*/
disconnect(reason = 'user requested') {
this.manager.client.ws.send({
@@ -107,19 +107,15 @@ class VoiceConnection extends EventEmitter {
}
_shutdown(e) {
if (!this.ready) {
return;
}
if (!this.ready) return;
this.ready = false;
this.websocket._shutdown();
this.player._shutdown();
if (this.udp) {
this.udp._shutdown();
}
if (this.udp) this.udp._shutdown();
/**
* Emit once the voice connection has disconnected.
* @event VoiceConnection#disconnected
* @param {Error} error the error, if any
* @param {Error} error The encountered error, if any
*/
this.emit('disconnected', e);
}
@@ -149,9 +145,7 @@ class VoiceConnection extends EventEmitter {
});
this.once('ready', () => {
setImmediate(() => {
for (const item of this.queue) {
this.emit(...item);
}
for (const item of this.queue) this.emit(...item);
this.queue = [];
});
});
@@ -197,21 +191,18 @@ class VoiceConnection extends EventEmitter {
/**
* Emitted whenever a user starts/stops speaking
* @event VoiceConnection#speaking
* @param {User} user the user that has started/stopped speaking
* @param {boolean} speaking whether or not the user is speaking
* @param {User} user The user that has started/stopped speaking
* @param {boolean} speaking Whether or not the user is speaking
*/
if (this.ready) {
this.emit('speaking', user, data.speaking);
} else {
this.queue.push(['speaking', user, data.speaking]);
}
if (this.ready) this.emit('speaking', user, data.speaking);
else this.queue.push(['speaking', user, data.speaking]);
guild._memberSpeakUpdate(data.user_id, data.speaking);
});
}
/**
* Play the given file in the voice connection
* @param {string} file the path to the file
* @param {string} file The path to the file
* @returns {StreamDispatcher}
* @example
* // play files natively
@@ -227,7 +218,7 @@ class VoiceConnection extends EventEmitter {
/**
* Plays and converts an audio stream in the voice connection
* @param {ReadableStream} stream the audio stream to play
* @param {ReadableStream} stream The audio stream to play
* @returns {StreamDispatcher}
* @example
* // play streams using ytdl-core
@@ -245,7 +236,7 @@ class VoiceConnection extends EventEmitter {
/**
* Plays a stream of 16-bit signed stereo PCM at 48KHz.
* @param {ReadableStream} stream the audio stream to play.
* @param {ReadableStream} stream The audio stream to play.
* @returns {StreamDispatcher}
*/
playConvertedStream(stream) {