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

@@ -91,7 +91,7 @@ class Webhook {
* Send a message with this webhook.
* @param {StringResolvable} [content] The content to send
* @param {WebhookMessageOptions} [options={}] The options to provide
* @returns {Promise<Message|Message[]>}
* @returns {Promise<Message|Object>}
* @example
* // Send a message
* webhook.send('hello!')
@@ -106,6 +106,23 @@ class Webhook {
options = {};
}
if (!options.username) options.username = this.name;
if (options.avatarURL) {
options.avatar_url = options.avatarURL;
options.avatarURL = null;
}
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
if (content) {
if (options.disableEveryone ||
(typeof options.disableEveryone === 'undefined' && this.client.options.disableEveryone)
) {
content = content.replace(/@(everyone|here)/g, '@\u200b$1');
}
}
options.content = content;
if (options.file) {
if (options.files) options.files.push(options.file);
else options.files = [options.file];
@@ -132,16 +149,29 @@ class Webhook {
file.file = buffer;
return file;
})
)).then(files => this.client.rest.methods.sendWebhookMessage(this, content, options, files));
)).then(files => this.client.api.webhooks(this.id, this.token).post({
data: options,
query: { wait: true },
files,
auth: false,
}));
}
return this.client.rest.methods.sendWebhookMessage(this, content, options);
return this.client.api.webhooks(this.id, this.token).post({
data: options,
query: { wait: true },
auth: false,
}).then(data => {
if (!this.client.channels) return data;
const Message = require('./Message');
return new Message(this.client.channels.get(data.channel_id, data, this.client));
});
}
/**
* Send a raw slack message with this webhook.
* @param {Object} body The raw body to send
* @returns {Promise}
* @returns {Promise<Message|Object>}
* @example
* // Send a slack message
* webhook.sendSlackMessage({
@@ -156,34 +186,49 @@ class Webhook {
* }).catch(console.error);
*/
sendSlackMessage(body) {
return this.client.rest.methods.sendSlackWebhookMessage(this, body);
return this.client.api.webhooks(this.id, this.token).slack.post({
query: { wait: true },
auth: false,
data: body,
}).then(data => {
if (!this.client.channels) return data;
const Message = require('./Message');
return new Message(this.client.channels.get(data.channel_id, data, this.client));
});
}
/**
* Edit the webhook.
* @param {string} name The new name for the webhook
* @param {BufferResolvable} avatar The new avatar for the webhook
* @param {Object} options Options
* @param {string} [options.name] New name for this webhook
* @param {BufferResolvable} [options.avatar] New avatar for this webhook
* @param {string} [reason] Reason for editing this webhook
* @returns {Promise<Webhook>}
*/
edit(name = this.name, avatar) {
if (avatar) {
edit({ name = this.name, avatar }, reason) {
if (avatar && (typeof avatar === 'string' && !avatar.startsWith('data:'))) {
return this.client.resolver.resolveBuffer(avatar).then(file => {
const dataURI = this.client.resolver.resolveBase64(file);
return this.client.rest.methods.editWebhook(this, name, dataURI);
return this.edit({ name, avatar: dataURI }, reason);
});
}
return this.client.rest.methods.editWebhook(this, name).then(data => {
this.setup(data);
return this.client.api.webhooks(this.id, this.token).patch({
data: { name, avatar },
reason,
}).then(data => {
this.name = data.name;
this.avatar = data.avatar;
return this;
});
}
/**
* Delete the webhook.
* @param {string} [reason] Reason for deleting this webhook
* @returns {Promise}
*/
delete() {
return this.client.rest.methods.deleteWebhook(this);
delete(reason) {
return this.client.api.webhooks(this.id, this.token).delete({ reason });
}
}