dressed
Version:
A sleek, serverless-ready Discord bot framework.
71 lines • 3.47 kB
JavaScript
import { MessageFlags, } from "discord-api-types/v10";
import { editWebhookMessage, executeWebhook } from "../../resources/generated.resources.js";
import { createInteractionCallback } from "../../resources/interactions.js";
import { botEnv } from "../../utils/env.js";
export function baseInteractionMethods(interaction) {
var _a, _b;
const history = [];
return {
reply(data, $req) {
var _a;
history.push("reply");
if (typeof data === "string") {
data = { content: data };
}
if (data.ephemeral) {
data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.Ephemeral;
}
const { files, ...rest } = data;
return createInteractionCallback(interaction.id, interaction.token, "ChannelMessageWithSource", rest, files, {
with_response: data === null || data === void 0 ? void 0 : data.with_response,
}, $req);
},
deferReply(data, $req) {
var _a;
history.push("deferReply");
if (data === null || data === void 0 ? void 0 : data.ephemeral) {
data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.Ephemeral;
}
return createInteractionCallback(interaction.id, interaction.token, "DeferredChannelMessageWithSource", data, undefined, { with_response: data === null || data === void 0 ? void 0 : data.with_response }, $req);
},
update(data, $req) {
history.push("update");
if (typeof data === "string") {
data = { content: data };
}
const { files, ...rest } = data;
return createInteractionCallback(interaction.id, interaction.token, "UpdateMessage", rest, files, {
with_response: data.with_response,
}, $req);
},
deferUpdate(params, $req) {
history.push("deferUpdate");
return createInteractionCallback(interaction.id, interaction.token, "DeferredMessageUpdate", undefined, undefined, params, $req);
},
editReply(data, $req) {
history.push("editReply");
return editWebhookMessage(botEnv.DISCORD_APP_ID, interaction.token, "@original", data, undefined, $req);
},
followUp(data, $req) {
var _a;
history.push("followUp");
if (typeof data === "object" && data.ephemeral) {
data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.Ephemeral;
}
return executeWebhook(botEnv.DISCORD_APP_ID, interaction.token, data, {
wait: true,
}, $req);
},
showModal(data, params, $req) {
history.push("showModal");
return createInteractionCallback(interaction.id, interaction.token, "Modal", data, undefined, params, $req);
},
sendChoices(choices, params, $req) {
history.push("sendChoices");
return createInteractionCallback(interaction.id, interaction.token, "ApplicationCommandAutocompleteResult", { choices }, undefined, params, $req);
},
user: (_a = interaction.user) !== null && _a !== void 0 ? _a : (_b = interaction.member) === null || _b === void 0 ? void 0 : _b.user,
history,
};
}
//# sourceMappingURL=responses.js.map