Internal API Request Rewrite (#1490)

* start rewrite

* converted guilds

* more changes

* convert GuildMember

* convert User and remove friend methods which kill people

* convert more stuff

* even more stuff

* make things nicer

* speed and fixes and stuff

* almost finished

* fix

* Update Client.js

* uwu

* Update RESTMethods.js

* message editing

* fix router

* fix issue with references

* message delete reason

* move message sending

* fix dm

* message splitting

* NO MORE REST METHODS

* Update Client.js

* Update WebhookClient.js

* remove all those endpoints from the constants

* Update ClientUser.js

* Update ClientUser.js

* fixes

* Update ClientUser.js

* complaiancy

* all sort of fixes

* merge master (#1)

* Fix Permissions now that member is deprecated (#1491)

* removing more deprecation leftovers (#1492)

* Fix MessageCollectors

* Fix awaitMessages (#1493)

* Fix MessageCollector#cleanup

* Fix MessageCollector#postCheck

* Add max option back for safety

* Update Invite.js (#1496)

* guild setPosition missing docs (#1498)

* missing docs

* update return docs

* indent

* switched .invites for the apirouter and invite.js

* make multiple options an object

* Update ClientUser.js

* fix nicks

* Update WebhookClient.js
This commit is contained in:
Gus Caplan
2017-05-21 00:04:19 -05:00
committed by Crawl
parent 02f03c439f
commit 0baa59b679
33 changed files with 849 additions and 1303 deletions

View File

@@ -332,10 +332,24 @@ class GuildMember {
/**
* Edit a guild member.
* @param {GuildMemberEditData} data The data to edit the member with
* @param {string} [reason] Reason for editing this user
* @returns {Promise<GuildMember>}
*/
edit(data) {
return this.client.rest.methods.updateGuildMember(this, data);
edit(data, reason) {
if (data.channel) {
data.channel_id = this.client.resolver.resolveChannel(data.channel).id;
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);
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);
} else {
endpoint = endpoint.members(this.id);
}
return endpoint.patch({ data, reason }).then(newData => this.guild._updateMember(this, newData).mem);
}
/**
@@ -382,7 +396,10 @@ class GuildMember {
addRole(role) {
if (!(role instanceof Role)) role = this.guild.roles.get(role);
if (!role) return Promise.reject(new TypeError('Supplied parameter was neither a Role nor a Snowflake.'));
return this.client.rest.methods.addMemberRole(this, role);
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)
.put()
.then(() => this);
}
/**
@@ -394,9 +411,9 @@ class GuildMember {
let allRoles;
if (roles instanceof Collection) {
allRoles = this._roles.slice();
for (const role of roles.values()) allRoles.push(role.id);
for (const role of roles.values()) allRoles.push(role.id ? role.id : role);
} else {
allRoles = this._roles.concat(roles);
allRoles = this._roles.concat(roles.map(r => r.id ? r.id : r));
}
return this.edit({ roles: allRoles });
}
@@ -409,7 +426,9 @@ class GuildMember {
removeRole(role) {
if (!(role instanceof Role)) role = this.guild.roles.get(role);
if (!role) return Promise.reject(new TypeError('Supplied parameter was neither a Role nor a Snowflake.'));
return this.client.rest.methods.removeMemberRole(this, role);
return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id)
.delete()
.then(() => this);
}
/**
@@ -464,7 +483,13 @@ class GuildMember {
* @returns {Promise<GuildMember>}
*/
kick(reason) {
return this.client.rest.methods.kickGuildMember(this.guild, this, 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,
user: this.user,
}).member
);
}
/**