Merge branch 'indev' of https://github.com/hydrabolt/discord.js into indev

This commit is contained in:
Amish Shah
2016-10-26 15:14:30 +01:00
4 changed files with 26 additions and 20 deletions

View File

@@ -234,17 +234,14 @@ class Client extends EventEmitter {
* @returns {Promise} * @returns {Promise}
*/ */
destroy() { destroy() {
return new Promise((resolve, reject) => { return this.manager.destroy().then(() => {
this.manager.destroy().then(() => { for (const t of this._timeouts) clearTimeout(t);
for (const t of this._timeouts) clearTimeout(t); for (const i of this._intervals) clearInterval(i);
for (const i of this._intervals) clearInterval(i); this._timeouts.clear();
this._timeouts = []; this._intervals.clear();
this._intervals = []; this.token = null;
this.token = null; this.email = null;
this.email = null; this.password = null;
this.password = null;
resolve();
}).catch(reject);
}); });
} }

View File

@@ -58,14 +58,11 @@ class ClientManager {
} }
destroy() { destroy() {
return new Promise((resolve) => { let p = Promise.resolve();
if (!this.client.user.bot) { if (!this.client.user.bot) {
this.client.rest.methods.logout().then(resolve); p = this.client.rest.methods.logout();
} else { }
this.client.ws.destroy(); return p.then(() => this.client.ws.destroy());
resolve();
}
});
} }
} }

View File

@@ -35,7 +35,7 @@ class RESTMethods {
} }
logout() { logout() {
return this.rest.makeRequest('post', Constants.Endpoints.logout, true); return this.rest.makeRequest('post', Constants.Endpoints.logout, true, {});
} }
getGateway() { getGateway() {

12
test/destroy.js Normal file
View File

@@ -0,0 +1,12 @@
'use strict';
const Discord = require('../');
const client = new Discord.Client({ fetch_all_members: false, api_request_method: 'sequential' });
const { email, password, token } = require('./auth.json');
let p = client.login(token);
p = p.then(() => client.destroy());
p = p.then(() => client.login(token));
p = p.then(() => client.destroy());