Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/handlers/interactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,22 @@ async function handleComponent(interaction) {
}

if (interaction.isButton() && id.startsWith('review:rate:')) {
const [, , ticketIdRaw, ratingRaw] = id.split(':');
const [, , ticketIdRaw, ratingRaw, requestedOwnerId] = id.split(':');
const ticketId = Number(ticketIdRaw);
const rating = Number(ratingRaw);
const ticket = db.getTicketById(ticketId);
if (!ticket || ticket.owner_id !== user.id) throw new Error('Only the ticket owner can review this ticket.');
if (!config.features?.reviews) throw new Error('Reviews are disabled.');
const modal = new ModalBuilder().setCustomId(`review:submit:${ticketId}:${rating}`).setTitle(`Rate ticket #${ticketId}`)
if (!Number.isInteger(ticketId) || ticketId < 1 || !Number.isInteger(rating) || rating < 1 || rating > 5) {
throw new Error('This review button is invalid. Please use the latest review message from the bot.');
}
if (requestedOwnerId && requestedOwnerId !== user.id) {
throw new Error('These review buttons were sent to a different account. Open the review DM sent to the ticket owner.');
}
const ticket = db.getTicketById(ticketId);
if (!ticket) throw new Error('This ticket record is no longer available, so this review link has expired.');
if (ticket.owner_id !== user.id) {
throw new Error('This review link is out of date and no longer matches your ticket. Please ask support for a fresh review link.');
}
const modal = new ModalBuilder().setCustomId(`review:submit:${ticketId}:${rating}:${user.id}`).setTitle(`Rate ticket #${ticketId}`)
.addComponents(new ActionRowBuilder().addComponents(new TextInputBuilder().setCustomId('comment').setLabel('Optional feedback').setStyle(TextInputStyle.Paragraph).setRequired(false).setMaxLength(900)));
return interaction.showModal(modal);
}
Expand Down Expand Up @@ -442,15 +451,17 @@ async function handleModal(interaction) {
}

if (id.startsWith('review:submit:')) {
const [, , ticketIdRaw, ratingRaw] = id.split(':');
const [, , ticketIdRaw, ratingRaw, requestedOwnerId] = id.split(':');
const ticketId = Number(ticketIdRaw);
const rating = Number(ratingRaw);
if (requestedOwnerId && requestedOwnerId !== user.id) throw new Error('This review form was issued to a different account.');
const ticket = db.getTicketById(ticketId);
if (!ticket || ticket.owner_id !== user.id) throw new Error('Only the ticket owner can review this ticket.');
if (!ticket) throw new Error('This ticket record is no longer available, so the review could not be saved.');
if (ticket.owner_id !== user.id) throw new Error('Only the ticket owner can submit this review.');
if (!Number.isInteger(rating) || rating < 1 || rating > 5) throw new Error('Invalid rating.');
const comment = interaction.fields.getTextInputValue('comment') || '';
db.saveReview({ ticketId, guildId: ticket.guild_id, userId: user.id, rating, comment: truncate(comment, 900) });
return interaction.reply({ content: `Thanks for rating ticket #${ticketId}: ${rating}/5.`, ...ephemeral });
return interaction.reply({ content: `Thanks for rating ticket #${ticketId}: ${'⭐'.repeat(rating)} (${rating}/5). Your feedback has been saved.`, ...ephemeral });
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/services/tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ export async function closeTicket({ ticket, channel, member, reason = 'No reason
const components = [];
if (config.features?.reviews) {
components.push(new ActionRowBuilder().addComponents(...[1,2,3,4,5].map((rating) =>
new ButtonBuilder().setCustomId(`review:rate:${ticket.id}:${rating}`).setLabel(String(rating)).setStyle(rating >= 4 ? ButtonStyle.Success : rating <= 2 ? ButtonStyle.Danger : ButtonStyle.Secondary))));
new ButtonBuilder()
.setCustomId(`review:rate:${ticket.id}:${rating}:${ticket.owner_id}`)
.setLabel(`${rating} star${rating === 1 ? '' : 's'}`)
.setEmoji('⭐')
.setStyle(rating >= 4 ? ButtonStyle.Success : rating <= 2 ? ButtonStyle.Danger : ButtonStyle.Secondary))));
}
await owner.send({
content: `Your support ticket #${ticket.id} in **${guild.name}** has been closed. ${config.features?.reviews ? 'You can leave an optional rating below.' : ''}`,
Expand Down
Loading