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

@@ -380,7 +380,27 @@ class Message {
} else if (!options) {
options = {};
}
return this.client.rest.methods.updateMessage(this, content, options);
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
const { embed, code, reply } = options;
// Wrap everything in a code block
if (typeof code !== 'undefined' && (typeof code !== 'boolean' || code === true)) {
content = Util.escapeMarkdown(this.client.resolver.resolveString(content), true);
content = `\`\`\`${typeof code !== 'boolean' ? code || '' : ''}\n${content}\n\`\`\``;
}
// Add the reply prefix
if (reply && this.channel.type !== 'dm') {
const id = this.client.resolver.resolveUserID(reply);
const mention = `<@${reply instanceof GuildMember && reply.nickname ? '!' : ''}${id}>`;
content = `${mention}${content ? `, ${content}` : ''}`;
}
return this.client.api.channels(this.channel.id).messages(this.id)
.patch({ data: { content, embed } })
.then(data => this.client.actions.MessageUpdate.handle(data).updated);
}
/**
@@ -388,7 +408,8 @@ class Message {
* @returns {Promise<Message>}
*/
pin() {
return this.client.rest.methods.pinMessage(this);
return this.client.api.channels(this.channel.id).pins(this.id).put()
.then(() => this);
}
/**
@@ -396,7 +417,8 @@ class Message {
* @returns {Promise<Message>}
*/
unpin() {
return this.client.rest.methods.unpinMessage(this);
return this.client.api.channels(this.channel.id).pins(this.id).delete()
.then(() => this);
}
/**
@@ -408,7 +430,9 @@ class Message {
emoji = this.client.resolver.resolveEmojiIdentifier(emoji);
if (!emoji) throw new TypeError('Emoji must be a string or Emoji/ReactionEmoji');
return this.client.rest.methods.addMessageReaction(this, emoji);
return this.client.api.channels(this.channel.id).messages(this.id).reactions(emoji)['@me']
.put()
.then(() => this._addReaction(Util.parseEmoji(emoji), this.client.user));
}
/**
@@ -416,12 +440,15 @@ class Message {
* @returns {Promise<Message>}
*/
clearReactions() {
return this.client.rest.methods.removeMessageReactions(this);
return this.client.api.channels(this.channel.id).messages(this.id).reactions.delete()
.then(() => this);
}
/**
* Deletes the message.
* @param {number} [timeout=0] How long to wait to delete the message in milliseconds
* @param {Object} [options] Options
* @param {number} [options.timeout=0] How long to wait to delete the message in milliseconds
* @param {string} [options.reason] Reason for deleting this message, if it does not belong to the client user
* @returns {Promise<Message>}
* @example
* // Delete a message
@@ -429,13 +456,19 @@ class Message {
* .then(msg => console.log(`Deleted message from ${msg.author}`))
* .catch(console.error);
*/
delete(timeout = 0) {
delete({ timeout = 0, reason } = {}) {
if (timeout <= 0) {
return this.client.rest.methods.deleteMessage(this);
return this.client.api.channels(this.channel.id).messages(this.id)
.delete({ reason })
.then(() =>
this.client.actions.MessageDelete.handle({
id: this.id,
channel_id: this.channel.id,
}).message);
} else {
return new Promise(resolve => {
this.client.setTimeout(() => {
resolve(this.delete());
resolve(this.delete({ reason }));
}, timeout);
});
}
@@ -468,7 +501,12 @@ class Message {
* @returns {Promise<Message>}
*/
acknowledge() {
return this.client.rest.methods.ackMessage(this);
return this.client.api.channels(this.channel.id).messages(this.id).ack
.post({ data: { token: this.client.rest._ackToken } })
.then(res => {
if (res.token) this.client.rest._ackToken = res.token;
return this;
});
}
/**