refactor: enforce single param on sending/editing methods (#5758)

Co-authored-by: ckohen <chaikohen@gmail.com>
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>
Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Adrian Castro
2021-06-09 14:12:16 +02:00
committed by GitHub
parent dda5ee2e9f
commit 0467a9075f
8 changed files with 89 additions and 260 deletions

View File

@@ -53,8 +53,7 @@ class InteractionResponses {
/**
* Creates a reply to this interaction.
* @param {string|APIMessage|MessageAdditions} content The content for the reply
* @param {InteractionReplyOptions} [options] Additional options for the reply
* @param {string|APIMessage|InteractionReplyOptions} options The options for the reply
* @returns {Promise<void>}
* @example
* // Reply to the interaction with an embed
@@ -65,13 +64,17 @@ class InteractionResponses {
* .catch(console.error);
* @example
* // Create an ephemeral reply
* interaction.reply('Pong!', { ephemeral: true })
* interaction.reply({ content: 'Pong!', ephemeral: true })
* .then(console.log)
* .catch(console.error);
*/
async reply(content, options) {
async reply(options) {
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options);
let apiMessage;
if (options instanceof APIMessage) apiMessage = options;
else apiMessage = APIMessage.create(this, options);
const { data, files } = await apiMessage.resolveData().resolveFiles();
await this.client.api.interactions(this.id, this.token).callback.post({
@@ -101,8 +104,7 @@ class InteractionResponses {
/**
* Edits the initial reply to this interaction.
* @see Webhook#editMessage
* @param {string|APIMessage|MessageAdditions} content The new content for the message
* @param {WebhookEditMessageOptions} [options] The options to provide
* @param {string|APIMessage|WebhookEditMessageOptions} options The new options for the message
* @returns {Promise<Message|Object>}
* @example
* // Edit the reply to this interaction
@@ -110,8 +112,8 @@ class InteractionResponses {
* .then(console.log)
* .catch(console.error);
*/
editReply(content, options) {
return this.webhook.editMessage('@original', content, options);
editReply(options) {
return this.webhook.editMessage('@original', options);
}
/**
@@ -130,12 +132,11 @@ class InteractionResponses {
/**
* Send a follow-up message to this interaction.
* @param {string|APIMessage|MessageAdditions} content The content for the reply
* @param {InteractionReplyOptions} [options] Additional options for the reply
* @param {string|APIMessage|InteractionReplyOptions} options The options for the reply
* @returns {Promise<Message|Object>}
*/
followUp(content, options) {
return this.webhook.send(content, options);
followUp(options) {
return this.webhook.send(options);
}
/**
@@ -159,8 +160,7 @@ class InteractionResponses {
/**
* Updates the original message whose button was pressed
* @param {string|APIMessage|MessageAdditions} content The content for the reply
* @param {WebhookEditMessageOptions} [options] Additional options for the reply
* @param {string|APIMessage|WebhookEditMessageOptions} options The options for the reply
* @returns {Promise<void>}
* @example
* // Remove the buttons from the message
@@ -168,9 +168,13 @@ class InteractionResponses {
* .then(console.log)
* .catch(console.error);
*/
async update(content, options) {
async update(options) {
if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
const apiMessage = content instanceof APIMessage ? content : APIMessage.create(this, content, options);
let apiMessage;
if (options instanceof APIMessage) apiMessage = options;
else apiMessage = APIMessage.create(this, options);
const { data, files } = await apiMessage.resolveData().resolveFiles();
await this.client.api.interactions(this.id, this.token).callback.post({

View File

@@ -117,8 +117,7 @@ class TextBasedChannel {
/**
* Sends a message to this channel.
* @param {string|APIMessage} [content=''] The content to send
* @param {MessageOptions|MessageAdditions} [options={}] The options to provide
* @param {string|APIMessage|MessageOptions} options The options to provide
* @returns {Promise<Message|Message[]>}
* @example
* // Send a basic message
@@ -158,20 +157,20 @@ class TextBasedChannel {
* .then(console.log)
* .catch(console.error);
*/
async send(content, options) {
async send(options) {
const User = require('../User');
const GuildMember = require('../GuildMember');
if (this instanceof User || this instanceof GuildMember) {
return this.createDM().then(dm => dm.send(content, options));
return this.createDM().then(dm => dm.send(options));
}
let apiMessage;
if (content instanceof APIMessage) {
apiMessage = content.resolveData();
if (options instanceof APIMessage) {
apiMessage = options.resolveData();
} else {
apiMessage = APIMessage.create(this, content, options).resolveData();
apiMessage = APIMessage.create(this, options).resolveData();
if (Array.isArray(apiMessage.data.content)) {
return Promise.all(apiMessage.split().map(this.send.bind(this)));
}