Files
data
events
prefix
slash
config.json
Code
44 3,580
events/guild/interactionButton.js
const { Events, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionFlagsBits, EmbedBuilder, ChannelType } = require('discord.js');
const { createErrorEmbed, createSuccessEmbed } = require('../../util/embeds');
const { saveDraft, getDraft, deleteDraft, createEmbed, createButtons } = require('../../util/embedDraftManager');
const giveawayManager = require('../../util/giveawayManager');
const pollManager = require('../../util/pollManager');
const ticketManager = require('../../util/ticketManager');
function createPollMessage(client, poll) {
const POLL_EMOJIS = ['1๏ธโฃ', '2๏ธโฃ', '3๏ธโฃ', '4๏ธโฃ', '5๏ธโฃ'];
const totalVotes = poll.options.reduce((sum, opt) => sum + opt.voters.length, 0);
let description = `**Total Votes: ${totalVotes}**\n\n`;
const fields = poll.options.map((opt, index) => {
const votes = opt.voters.length;
const percentage = totalVotes > 0 ? (votes / totalVotes) * 100 : 0;
const barLength = Math.round(percentage / 10);
const bar = 'โ'.repeat(barLength) + 'โ'.repeat(10 - barLength);
return {
name: `${POLL_EMOJIS[index]} ${opt.text}`,
value: `${bar} **${percentage.toFixed(1)}%** (${votes} votes)`,
inline: false
};
});
const embed = new EmbedBuilder()
.setTitle(`๐ ${poll.question}`)
.setColor(poll.status === 'ACTIVE' ? client.config.embedColor : '#AA0000')
.setDescription(description)
.addFields(fields)
.setFooter({ text: `Poll ID: ${poll.messageId} | Hosted by: ${client.users.cache.get(poll.creatorId)?.tag || 'Unknown User'}` });
const rows = [];
let row = new ActionRowBuilder();
poll.options.forEach((opt, index) => {
const button = new ButtonBuilder()
.setCustomId(`poll_vote_${poll.messageId}_${index}`)
.setLabel(POLL_EMOJIS[index])
.setStyle(poll.status === 'ACTIVE' ? ButtonStyle.Primary : ButtonStyle.Secondary)
.setDisabled(poll.status !== 'ACTIVE');
if (row.components.length >= 5) {
rows.push(row);
row = new ActionRowBuilder();
}
row.addComponents(button);
});
rows.push(row);
if (poll.status === 'ACTIVE') {
const controlRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`poll_end_${poll.messageId}`)
.setLabel('End Poll')
.setStyle(ButtonStyle.Danger)
);
rows.push(controlRow);
}
return { embed, components: rows };
}
async function forceEndGiveaway(client, giveaway) {
const channel = client.channels.cache.get(giveaway.channelId);
if (!channel) return giveawayManager.deleteGiveaway(giveaway.messageId);
const message = await channel.messages.fetch(giveaway.messageId).catch(() => null);
if (!message) return giveawayManager.deleteGiveaway(giveaway.messageId);
const latestGiveaway = giveawayManager.getGiveaway(giveaway.messageId);
if (!latestGiveaway) return giveawayManager.deleteGiveaway(giveaway.messageId);
const result = giveawayManager.drawWinners(latestGiveaway.messageId);
const endedGiveaway = giveawayManager.getGiveaway(giveaway.messageId);
const endedEmbed = new EmbedBuilder()
.setTitle(`๐ ${endedGiveaway.prize}`)
.setColor(client.config.embedColor)
.setDescription(`Giveaway has ended!`)
.addFields(
{ name: 'Hosted By', value: `<@${endedGiveaway.creatorId}>`, inline: true },
{ name: 'Winners', value: result.winners.length > 0 ? result.winners.map(id => `<@${id}>`).join(', ') : 'No valid winners could be determined.', inline: true }
)
.setTimestamp();
const rerollButton = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId(`giveaway_reroll_${endedGiveaway.messageId}`)
.setLabel('Reroll Winners')
.setStyle(ButtonStyle.Secondary)
);
await message.edit({ embeds: [endedEmbed], components: [rerollButton] }).catch(() => {});
if (result.winners.length > 0) {
channel.send(`Congratulations ${result.winners.map(id => `<@${id}>`).join(', ')}! You won **${endedGiveaway.prize}**!`).catch(() => {});
} else {
channel.send(`Nobody won the **${endedGiveaway.prize}** giveaway!`).catch(() => {});
}
}
async function createTranscript(channel, client, ticketData) {
let transcript = `--- Ticket Transcript for #${channel.name} ---\n`;
transcript += `Ticket ID: ${channel.id}\nUser ID: ${ticketData.userId} (${client.users.cache.get(ticketData.userId)?.tag || 'Unknown'})\nClosed by: ${client.user.tag}\nDate: ${new Date().toUTCString()}\n\n`;
const messages = await channel.messages.fetch({ limit: 100 });
messages.reverse().forEach(msg => {
const time = new Date(msg.createdTimestamp).toLocaleTimeString();
let content = msg.content;
if (msg.attachments.size > 0) {
content += ' [Attachments: ' + msg.attachments.map(a => a.url).join(', ') + ']';
}
transcript += `[${time}] ${msg.author.tag}: ${content}\n`;
});
return transcript;
}
module.exports = {
name: Events.InteractionCreate,
async execute(interaction, client) {
if (!interaction.isButton()) return;
const userId = interaction.user.id;
const [type, action, id, index] = interaction.customId.split('_');
const POLL_EMOJIS = ['1๏ธโฃ', '2๏ธโฃ', '3๏ธโฃ', '4๏ธโฃ', '5๏ธโฃ'];
if (type === 'embed') {
let draft = getDraft(userId);
if (!draft) {
return interaction.reply({ embeds: [createErrorEmbed(client, 'Your embed draft session has expired or was cleared. Please use `/embed create` to start a new one.')], ephemeral: true });
}
switch (interaction.customId) {
case 'embed_edit_title':
const titleModal = new ModalBuilder()
.setCustomId('embed_modal_title')
.setTitle('Edit Title and Description');
const titleInput = new TextInputBuilder()
.setCustomId('embed_title_input')
.setLabel('Embed Title')
.setStyle(TextInputStyle.Short)
.setRequired(true)
.setValue(draft.title)
.setMaxLength(256);
const descInput = new TextInputBuilder()
.setCustomId('embed_desc_input')
.setLabel('Embed Description')
.setStyle(TextInputStyle.Paragraph)
.setRequired(true)
.setValue(draft.description)
.setMaxLength(4000);
titleModal.addComponents(new ActionRowBuilder().addComponents(titleInput), new ActionRowBuilder().addComponents(descInput));
await interaction.showModal(titleModal);
break;
case 'embed_edit_color':
const colorModal = new ModalBuilder()
.setCustomId('embed_modal_color')
.setTitle('Edit Embed Color');
const colorInput = new TextInputBuilder()
.setCustomId('embed_color_input')
.setLabel('Hex Color (e.g., #00FF00 or 00FF00)')
.setStyle(TextInputStyle.Short)
.setRequired(true)
.setValue(draft.color.toString(16).toUpperCase());
colorModal.addComponents(new ActionRowBuilder().addComponents(colorInput));
await interaction.showModal(colorModal);
break;
case 'embed_add_image':
const imageModal = new ModalBuilder()
.setCustomId('embed_modal_image')
.setTitle('Add/Remove Image');
const imageInput = new TextInputBuilder()
.setCustomId('embed_image_input')
.setLabel('Image URL (Leave empty to remove)')
.setStyle(TextInputStyle.Short)
.setRequired(false)
.setValue(draft.image || '');
imageModal.addComponents(new ActionRowBuilder().addComponents(imageInput));
await interaction.showModal(imageModal);
break;