feat: reject full log (InteractionTimeout)

This commit is contained in:
March 7th 2022-12-12 18:40:55 +07:00
parent dea8324c00
commit be786d3876
4 changed files with 24 additions and 8 deletions

View File

@ -7,10 +7,10 @@ const { Events } = require('../../../util/Constants');
* @property {Snowflake} nonce nonce in POST /interactions * @property {Snowflake} nonce nonce in POST /interactions
*/ */
module.exports = (client, packet) => { module.exports = (client, { d: data }) => {
if (client.user.bot) { if (client.user.bot) {
client.actions.InteractionCreate.handle(packet.d); client.actions.InteractionCreate.handle(data);
} else { } else {
client.emit(Events.INTERACTION_CREATE, packet.d); client.emit(Events.INTERACTION_CREATE, data);
} }
}; };

View File

@ -907,7 +907,11 @@ class ApplicationCommand extends Base {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
this.client.removeListener('interactionResponse', handler); this.client.removeListener('interactionResponse', handler);
this.client.decrementMaxListeners(); this.client.decrementMaxListeners();
reject(new Error('INTERACTION_TIMEOUT')); reject(
new Error('INTERACTION_TIMEOUT', {
cause: data,
}),
);
}, this.client.options.interactionTimeout).unref(); }, this.client.options.interactionTimeout).unref();
this.client.incrementMaxListeners(); this.client.incrementMaxListeners();
this.client.on('interactionResponse', handler); this.client.on('interactionResponse', handler);
@ -998,7 +1002,11 @@ class ApplicationCommand extends Base {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
this.client.removeListener('interactionResponse', handler); this.client.removeListener('interactionResponse', handler);
this.client.decrementMaxListeners(); this.client.decrementMaxListeners();
reject(new Error('INTERACTION_TIMEOUT')); reject(
new Error('INTERACTION_TIMEOUT', {
cause: data,
}),
);
}, this.client.options.interactionTimeout).unref(); }, this.client.options.interactionTimeout).unref();
this.client.incrementMaxListeners(); this.client.incrementMaxListeners();
this.client.on('interactionResponse', handler); this.client.on('interactionResponse', handler);

View File

@ -173,7 +173,7 @@ class MessageButton extends BaseMessageComponent {
async click(message) { async click(message) {
const nonce = SnowflakeUtil.generate(); const nonce = SnowflakeUtil.generate();
if (!(message instanceof Message())) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message'); if (!(message instanceof Message())) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
if (!this.customId || this.style == 5 || this.disabled) return false; // Button URL, Disabled if (!this.customId || this.style == MessageButtonStyles.LINK || this.disabled) return false;
const data = { const data = {
type: InteractionTypes.MESSAGE_COMPONENT, type: InteractionTypes.MESSAGE_COMPONENT,
nonce, nonce,
@ -216,7 +216,11 @@ class MessageButton extends BaseMessageComponent {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
message.client.removeListener('interactionResponse', handler); message.client.removeListener('interactionResponse', handler);
message.client.decrementMaxListeners(); message.client.decrementMaxListeners();
reject(new Error('INTERACTION_TIMEOUT')); reject(
new Error('INTERACTION_TIMEOUT', {
cause: data,
}),
);
}, message.client.options.interactionTimeout).unref(); }, message.client.options.interactionTimeout).unref();
message.client.incrementMaxListeners(); message.client.incrementMaxListeners();
message.client.on('interactionResponse', handler); message.client.on('interactionResponse', handler);

View File

@ -396,7 +396,11 @@ class MessageSelectMenu extends BaseMessageComponent {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
message.client.removeListener('interactionResponse', handler); message.client.removeListener('interactionResponse', handler);
message.client.decrementMaxListeners(); message.client.decrementMaxListeners();
reject(new Error('INTERACTION_TIMEOUT')); reject(
new Error('INTERACTION_TIMEOUT', {
cause: data,
}),
);
}, message.client.options.interactionTimeout).unref(); }, message.client.options.interactionTimeout).unref();
message.client.incrementMaxListeners(); message.client.incrementMaxListeners();
message.client.on('interactionResponse', handler); message.client.on('interactionResponse', handler);