@sodacore/discord
Version:
Sodacore Discord is a plugin that offers Discord SSO/OAuth2 support and the ability to create bots in a similar controller pattern.
68 lines (67 loc) • 2.67 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Colors, EmbedBuilder } from 'discord.js';
import { Provide } from '@sodacore/di';
let PromptsHelper = class PromptsHelper {
async confirm(interaction, question, options) {
// Define the interaction response.
let response;
// Create an embed.
const embed = new EmbedBuilder()
.setTitle(question)
.setColor(Colors.Green);
// Check for a description.
if (options?.description)
embed.setDescription(options.description);
if (options?.timestamp)
embed.setTimestamp();
if (options?.fields)
embed.addFields(options.fields);
// Create the buttons.
const buttonRow = new ActionRowBuilder()
.addComponents(new ButtonBuilder()
.setCustomId('internal:confirm:accept')
.setLabel(options?.acceptLabel || 'Yes')
.setStyle(ButtonStyle.Success), new ButtonBuilder()
.setCustomId('internal:confirm:reject')
.setLabel(options?.rejectLabel || 'No')
.setStyle(ButtonStyle.Danger));
// Send the message.
if (interaction.replied) {
await interaction.editReply({ embeds: [embed], components: [buttonRow] });
}
else {
response = await interaction.reply({ embeds: [embed], components: [buttonRow], withResponse: true });
}
// Wait for the response.
const result = await response.resource?.message?.awaitMessageComponent({
filter: i => i.user.id === interaction.user.id,
time: options?.timeout || 60000,
});
// Check the response.
if (result?.customId === 'internal:confirm:accept') {
return true;
}
return false;
}
async choice() {
// TODO.
}
async input() {
// TODO.
}
async select() {
// TODO.
}
async modal() {
// TODO.
}
};
PromptsHelper = __decorate([
Provide()
], PromptsHelper);
export default PromptsHelper;