email fixes
This commit is contained in:
@@ -93,16 +93,35 @@ async function handleButton(interaction) {
|
||||
|
||||
// --- CLOSE ---
|
||||
if (interaction.customId === 'close_ticket') {
|
||||
const confirmRow = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('confirm_close')
|
||||
.setLabel('Confirm Close')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('cancel_close')
|
||||
.setLabel('Cancel')
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
);
|
||||
const isEmailTicket = ticket.gmailThreadId && !ticket.gmailThreadId.startsWith('discord-');
|
||||
const confirmRow = new ActionRowBuilder();
|
||||
if (isEmailTicket) {
|
||||
confirmRow.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('confirm_close_with_email')
|
||||
.setLabel('Confirm Close With Email')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('confirm_close_no_email')
|
||||
.setLabel('Confirm Close Without Email')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('cancel_close')
|
||||
.setLabel('Cancel')
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
);
|
||||
} else {
|
||||
confirmRow.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('confirm_close')
|
||||
.setLabel('Confirm Close')
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('cancel_close')
|
||||
.setLabel('Cancel')
|
||||
.setStyle(ButtonStyle.Secondary)
|
||||
);
|
||||
}
|
||||
|
||||
return interaction.reply({
|
||||
content: 'Are you sure you want to close this ticket?',
|
||||
@@ -110,7 +129,12 @@ async function handleButton(interaction) {
|
||||
});
|
||||
}
|
||||
|
||||
if (interaction.customId === 'confirm_close') {
|
||||
if (
|
||||
interaction.customId === 'confirm_close' ||
|
||||
interaction.customId === 'confirm_close_with_email' ||
|
||||
interaction.customId === 'confirm_close_no_email'
|
||||
) {
|
||||
const sendEmail = interaction.customId !== 'confirm_close_no_email';
|
||||
const timerSeconds = CONFIG.FORCE_CLOSE_TIMER;
|
||||
if (pendingCloses.has(interaction.channel.id)) {
|
||||
return interaction.reply({ content: 'A close is already pending for this ticket.', ephemeral: true });
|
||||
@@ -123,6 +147,7 @@ async function handleButton(interaction) {
|
||||
);
|
||||
await interaction.update({ content: `Closing ticket in ${timerSeconds} seconds.`, components: [cancelRow] });
|
||||
const timerId = setTimeout(async () => {
|
||||
const pending = pendingCloses.get(interaction.channel.id);
|
||||
pendingCloses.delete(interaction.channel.id);
|
||||
const freshTicket = await Ticket.findOne({ discordThreadId: interaction.channel.id }).lean();
|
||||
if (!freshTicket || freshTicket.status === 'closed') return;
|
||||
@@ -132,9 +157,10 @@ async function handleButton(interaction) {
|
||||
{ name: 'Set by', value: interaction.user.tag },
|
||||
{ name: 'Duration', value: `${timerSeconds}s` }
|
||||
]).catch(() => {});
|
||||
await handleConfirmClose(interaction, freshTicket);
|
||||
const effectiveSendEmail = pending?.sendEmail ?? true;
|
||||
await handleConfirmClose(interaction, freshTicket, effectiveSendEmail);
|
||||
}, timerSeconds * 1000);
|
||||
pendingCloses.set(interaction.channel.id, { timeout: timerId, userId: interaction.user.id, username: interaction.user.tag });
|
||||
pendingCloses.set(interaction.channel.id, { timeout: timerId, userId: interaction.user.id, username: interaction.user.tag, sendEmail });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -394,7 +420,7 @@ async function handleClaim(interaction, ticket) {
|
||||
}
|
||||
|
||||
// --- CONFIRM CLOSE ---
|
||||
async function handleConfirmClose(interaction, ticket) {
|
||||
async function handleConfirmClose(interaction, ticket, sendEmail = true) {
|
||||
const closedAt = new Date();
|
||||
try {
|
||||
await interaction.update({ content: 'Archiving and closing...', components: [] });
|
||||
@@ -522,8 +548,8 @@ async function handleConfirmClose(interaction, ticket) {
|
||||
const closerDisplayName =
|
||||
interaction.member?.displayName || interaction.user.username;
|
||||
|
||||
if (!ticket.gmailThreadId?.startsWith('discord-')) {
|
||||
await sendTicketClosedEmail(ticket, closerDisplayName);
|
||||
if (sendEmail && !ticket.gmailThreadId?.startsWith('discord-')) {
|
||||
await sendTicketClosedEmail(ticket, closerDisplayName, interaction.user.id);
|
||||
}
|
||||
await Ticket.updateOne(
|
||||
{ gmailThreadId: ticket.gmailThreadId },
|
||||
|
||||
Reference in New Issue
Block a user