mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
partially working autorevive
This commit is contained in:
@@ -15,7 +15,7 @@ export default class Client extends EventEmitter {
|
||||
this class is an interface for the internal
|
||||
client.
|
||||
*/
|
||||
constructor(options) {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.options = options || {};
|
||||
this.options.compress = options.compress || true;
|
||||
@@ -69,6 +69,15 @@ export default class Client extends EventEmitter {
|
||||
return this.internal.logout()
|
||||
.then(callback, errCB(callback));
|
||||
}
|
||||
|
||||
// def destroy
|
||||
destroy(callback = (/*err*/) => { }) {
|
||||
this.internal.logout()
|
||||
.then(() => {
|
||||
this.internal.disconnected(true);
|
||||
});
|
||||
}
|
||||
|
||||
// def sendMessage
|
||||
sendMessage(where, content, options = {}, callback = (/*e, m*/) => {}) {
|
||||
if (typeof options === "function") {
|
||||
|
||||
@@ -62,6 +62,11 @@ function delay(ms) {
|
||||
|
||||
export default class InternalClient {
|
||||
constructor(discordClient) {
|
||||
this.setup(discordClient);
|
||||
}
|
||||
|
||||
setup(discordClient) {
|
||||
discordClient = discordClient || this.client;
|
||||
this.client = discordClient;
|
||||
this.state = ConnectionState.IDLE;
|
||||
this.websocket = null;
|
||||
@@ -96,6 +101,20 @@ export default class InternalClient {
|
||||
}
|
||||
}
|
||||
|
||||
disconnected(forced = false){
|
||||
|
||||
this.cleanIntervals();
|
||||
|
||||
this.leaveVoiceChannel();
|
||||
|
||||
if(this.client.options.autoRevive && !forced){
|
||||
this.setup();
|
||||
this.login(this.email, this.password);
|
||||
}
|
||||
|
||||
this.client.emit("disconnected");
|
||||
}
|
||||
|
||||
get uptime() {
|
||||
return (this.readyTime ? Date.now() - this.readyTime : null);
|
||||
}
|
||||
@@ -1028,11 +1047,7 @@ export default class InternalClient {
|
||||
this.websocket.onclose = () => {
|
||||
self.websocket = null;
|
||||
self.state = ConnectionState.DISCONNECTED;
|
||||
client.emit("disconnected");
|
||||
self.cleanIntervals();
|
||||
if(self.voiceConnection){
|
||||
self.leaveVoiceChannel();
|
||||
}
|
||||
self.disconnected();
|
||||
};
|
||||
|
||||
this.websocket.onerror = e => {
|
||||
|
||||
Reference in New Issue
Block a user