rewrite ratelimiting and api route builder (#1667)

* rewrite ratelimiting and api route builder

* more stuff

* let people pass their own handlers

* Update burst.js

* Update RequestHandler.js

* Update burst.js

* Update sequential.js

* Update RequestHandler.js
This commit is contained in:
Gus Caplan
2017-07-20 19:32:40 -05:00
committed by Crawl
parent 11556c0b3b
commit a2eeafc75d
20 changed files with 187 additions and 316 deletions

View File

@@ -342,13 +342,13 @@ class GuildMember {
data.channel = null;
}
if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role);
let endpoint = this.client.api.guilds[this.guild.id];
let endpoint = this.client.api.guilds(this.guild.id);
if (this.user.id === this.client.user.id) {
const keys = Object.keys(data);
if (keys.length === 1 && keys[0] === 'nick') endpoint = endpoint.members['@me'].nick;
else endpoint = endpoint.members[this.id];
if (keys.length === 1 && keys[0] === 'nick') endpoint = endpoint.members('@me').nick;
else endpoint = endpoint.members(this.id);
} else {
endpoint = endpoint.members[this.id];
endpoint = endpoint.members(this.id);
}
return endpoint.patch({ data, reason }).then(newData => this.guild._updateMember(this, newData).mem);
}
@@ -398,7 +398,7 @@ class GuildMember {
if (!(role instanceof Role)) role = this.guild.roles.get(role);
if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake'));
if (this._roles.includes(role.id)) return Promise.resolve(this);
return this.client.api.guilds[this.guild.id].members[this.user.id].roles[role.id]
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
.put()
.then(() => this);
}
@@ -427,7 +427,7 @@ class GuildMember {
removeRole(role) {
if (!(role instanceof Role)) role = this.guild.roles.get(role);
if (!role) return Promise.reject(new TypeError('INVALID_TYPE', 'role', 'Role nor a Snowflake'));
return this.client.api.guilds[this.guild.id].members[this.user.id].roles[role.id]
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
.delete()
.then(() => this);
}
@@ -484,7 +484,7 @@ class GuildMember {
* @returns {Promise<GuildMember>}
*/
kick(reason) {
return this.client.api.guilds[this.guild.id].members[this.user.id].delete({ reason })
return this.client.api.guilds(this.guild.id).members(this.user.id).delete({ reason })
.then(() =>
this.client.actions.GuildMemberRemove.handle({
guild_id: this.guild.id,