mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
add component support
This commit is contained in:
@@ -3,6 +3,7 @@ import { cache } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { DiscordenoInteractionResponse } from "../../types/discordeno/interaction_response.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { validateComponents } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Send a response to a users slash command. The command data will have the id and token necessary to respond.
|
||||
@@ -13,8 +14,10 @@ import { endpoints } from "../../util/constants.ts";
|
||||
export async function sendInteractionResponse(
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: DiscordenoInteractionResponse,
|
||||
options: DiscordenoInteractionResponse
|
||||
) {
|
||||
// TODO: add more options validations
|
||||
if (options.data?.components) validateComponents(options.data?.components);
|
||||
// If its already been executed, we need to send a followup response
|
||||
if (cache.executedSlashCommands.has(token)) {
|
||||
return await rest.runMethod(
|
||||
@@ -22,22 +25,19 @@ export async function sendInteractionResponse(
|
||||
endpoints.WEBHOOK(applicationId, token),
|
||||
{
|
||||
...options,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Expire in 15 minutes
|
||||
cache.executedSlashCommands.add(token);
|
||||
setTimeout(
|
||||
() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running setTimeout in send_interaction_response file.`,
|
||||
);
|
||||
cache.executedSlashCommands.delete(token);
|
||||
},
|
||||
900000,
|
||||
);
|
||||
setTimeout(() => {
|
||||
eventHandlers.debug?.(
|
||||
"loop",
|
||||
`Running setTimeout in send_interaction_response file.`
|
||||
);
|
||||
cache.executedSlashCommands.delete(token);
|
||||
}, 900000);
|
||||
|
||||
// If the user wants this as a private message mark it ephemeral
|
||||
if (options.private) {
|
||||
@@ -52,6 +52,6 @@ export async function sendInteractionResponse(
|
||||
return await rest.runMethod(
|
||||
"post",
|
||||
endpoints.INTERACTION_ID_TOKEN(id, token),
|
||||
options,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user