Add client.destroy();

This commit is contained in:
Amish Shah
2016-08-30 13:05:50 +01:00
parent 56352220af
commit d249aa10cc
18 changed files with 74 additions and 42 deletions

View File

@@ -105,6 +105,8 @@ class Client extends EventEmitter {
* @type {?Number}
*/
this.readyTime = null;
this._intervals = [];
this._timeouts = [];
}
/**
@@ -135,6 +137,32 @@ class Client extends EventEmitter {
return this.rest.methods.loginToken(email);
}
/**
* Destroys the client and logs out. Resolves with null if successful.
* @returns {Promise<null, Error>}
*/
destroy() {
return new Promise((resolve, reject) => {
this.manager.destroy().then(() => {
this._intervals.map(i => clearInterval(i));
this._timeouts.map(t => clearTimeout(t));
this.token = null;
this.email = null;
this.password = null;
resolve();
})
.catch(reject);
});
}
setInterval(...params) {
this._intervals.push(setInterval(...params));
}
setTimeout(...params) {
this._timeouts.push(setTimeout(...params));
}
/**
* Caches a user, or obtains it from the cache if it's already cached.
* If the user isn't already cached, it will only be obtainable by OAuth bot accounts.