mirror of
https://github.com/danbulant/discord.js
synced 2026-07-07 04:00:42 +00:00
add ack api
This commit is contained in:
parent
4599ef954f
commit
8c65961a07
2 changed files with 39 additions and 18 deletions
|
|
@ -108,19 +108,30 @@ class InteractionClient extends BaseClient {
|
||||||
r({
|
r({
|
||||||
type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE,
|
type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE,
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 250);
|
||||||
});
|
});
|
||||||
|
|
||||||
const interaction = new Interaction(this.client, data, resolved => {
|
const syncHandle = {
|
||||||
if (timedOut) {
|
acknowledge() {
|
||||||
return false;
|
if (!timedOut) {
|
||||||
}
|
resolve({
|
||||||
resolve({
|
type: InteractionResponseType.ACKNOWLEDGE_WITH_SOURCE,
|
||||||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
|
});
|
||||||
data: resolved.data,
|
}
|
||||||
});
|
},
|
||||||
return true;
|
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 => {
|
Promise.resolve(this.handler(interaction)).catch(e => {
|
||||||
this.client.emit('error', e);
|
this.client.emit('error', e);
|
||||||
|
|
@ -141,7 +152,7 @@ class InteractionClient extends BaseClient {
|
||||||
* @returns {Function} The middleware function.
|
* @returns {Function} The middleware function.
|
||||||
*/
|
*/
|
||||||
middleware() {
|
middleware() {
|
||||||
return async (req, res, next) => {
|
return async (req, res) => {
|
||||||
const timestamp = req.get('x-signature-timestamp');
|
const timestamp = req.get('x-signature-timestamp');
|
||||||
const signature = req.get('x-signature-ed25519');
|
const signature = req.get('x-signature-ed25519');
|
||||||
|
|
||||||
|
|
@ -169,8 +180,6 @@ class InteractionClient extends BaseClient {
|
||||||
|
|
||||||
const result = await this.handle(data);
|
const result = await this.handle(data);
|
||||||
res.status(200).end(JSON.stringify(result));
|
res.status(200).end(JSON.stringify(result));
|
||||||
|
|
||||||
next();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ const Snowflake = require('../util/Snowflake');
|
||||||
* @extends {Base}
|
* @extends {Base}
|
||||||
*/
|
*/
|
||||||
class Interaction extends Base {
|
class Interaction extends Base {
|
||||||
constructor(client, data, handler) {
|
constructor(client, data, syncHandle) {
|
||||||
super(client);
|
super(client);
|
||||||
this.handler = handler;
|
this.syncHandle = syncHandle;
|
||||||
this._patch(data);
|
this._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,6 +83,18 @@ class Interaction extends Base {
|
||||||
return new Date(this.createdTimestamp);
|
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) {
|
async reply(content, options) {
|
||||||
let apiMessage;
|
let apiMessage;
|
||||||
|
|
||||||
|
|
@ -91,13 +103,13 @@ class Interaction extends Base {
|
||||||
} else {
|
} else {
|
||||||
apiMessage = APIMessage.create(this, content, options).resolveData();
|
apiMessage = APIMessage.create(this, content, options).resolveData();
|
||||||
if (Array.isArray(apiMessage.data.content)) {
|
if (Array.isArray(apiMessage.data.content)) {
|
||||||
throw new Error();
|
throw new Error('Message is too long');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolved = await apiMessage.resolveFiles();
|
const resolved = await apiMessage.resolveFiles();
|
||||||
|
|
||||||
if (!this.handler(resolved)) {
|
if (!this.syncHandle.reply(resolved)) {
|
||||||
const clientID =
|
const clientID =
|
||||||
this.client.interactionClient.clientID || (await this.client.api.oauth2.applications('@me').get()).id;
|
this.client.interactionClient.clientID || (await this.client.api.oauth2.applications('@me').get()).id;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue