diff --git a/src/client/InteractionClient.js b/src/client/InteractionClient.js index 08d27d6a..3a709d08 100644 --- a/src/client/InteractionClient.js +++ b/src/client/InteractionClient.js @@ -108,19 +108,30 @@ class InteractionClient extends BaseClient { r({ type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE, }); - }, 500); + }, 250); }); - const interaction = new Interaction(this.client, data, resolved => { - if (timedOut) { - return false; - } - resolve({ - type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, - data: resolved.data, - }); - return true; - }); + const syncHandle = { + acknowledge() { + if (!timedOut) { + resolve({ + type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE, + }); + } + }, + reply(resolved) { + if (timedOut) { + return false; + } + resolve({ + type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, + data: resolved.data, + }); + return true; + }, + }; + + const interaction = new Interaction(this.client, data, syncHandle); Promise.resolve(this.handler(interaction)).catch(e => { this.client.emit('error', e); @@ -141,7 +152,7 @@ class InteractionClient extends BaseClient { * @returns {Function} The middleware function. */ middleware() { - return async (req, res, next) => { + return async (req, res) => { const timestamp = req.get('x-signature-timestamp'); const signature = req.get('x-signature-ed25519'); @@ -169,8 +180,6 @@ class InteractionClient extends BaseClient { const result = await this.handle(data); res.status(200).end(JSON.stringify(result)); - - next(); }; } diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index 6141ff90..b97bb07a 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -9,9 +9,9 @@ const Snowflake = require('../util/Snowflake'); * @extends {Base} */ class Interaction extends Base { - constructor(client, data, handler) { + constructor(client, data, syncHandle) { super(client); - this.handler = handler; + this.syncHandle = syncHandle; this._patch(data); } @@ -83,6 +83,18 @@ class Interaction extends Base { return new Date(this.createdTimestamp); } + /** + * Acknowledge this interaction without content. + */ + async acknowledge() { + await this.syncHandle.acknowledge(); + } + + /** + * Reply to this interaction. + * @param {(StringResolvable | APIMessage)?} content The content for the message. + * @param {(MessageOptions | MessageAdditions)?} options The options to provide. + */ async reply(content, options) { let apiMessage; @@ -91,13 +103,13 @@ class Interaction extends Base { } else { apiMessage = APIMessage.create(this, content, options).resolveData(); if (Array.isArray(apiMessage.data.content)) { - throw new Error(); + throw new Error('Message is too long'); } } const resolved = await apiMessage.resolveFiles(); - if (!this.handler(resolved)) { + if (!this.syncHandle.reply(resolved)) { const clientID = this.client.interactionClient.clientID || (await this.client.api.oauth2.applications('@me').get()).id;