Skip to content

Commit

Permalink
fix: only send value if not empty (closes #458)
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Jan 20, 2024
1 parent e695aa2 commit bcd02b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
44 changes: 21 additions & 23 deletions src/buttons/edit.js
Expand Up @@ -36,6 +36,15 @@ module.exports = class EditButton extends Button {
const getMessage = client.i18n.getLocale(ticket.guild.locale);

if (ticket.questionAnswers.length === 0) {
const field = new TextInputBuilder()
.setCustomId('topic')
.setLabel(getMessage('modals.topic.label'))
.setStyle(TextInputStyle.Paragraph)
.setMaxLength(1000)
.setMinLength(5)
.setPlaceholder(getMessage('modals.topic.placeholder'))
.setRequired(true);
if (ticket.topic) field.setValue(cryptr.decrypt(ticket.topic));
await interaction.showModal(
new ModalBuilder()
.setCustomId(JSON.stringify({
Expand All @@ -45,17 +54,7 @@ module.exports = class EditButton extends Button {
.setTitle(ticket.category.name)
.setComponents(
new ActionRowBuilder()
.setComponents(
new TextInputBuilder()
.setCustomId('topic')
.setLabel(getMessage('modals.topic.label'))
.setStyle(TextInputStyle.Paragraph)
.setMaxLength(1000)
.setMinLength(5)
.setPlaceholder(getMessage('modals.topic.placeholder'))
.setRequired(true)
.setValue(ticket.topic ? cryptr.decrypt(ticket.topic) : ''),
),
.setComponents(field),
),
);
} else {
Expand All @@ -71,18 +70,17 @@ module.exports = class EditButton extends Button {
.filter(a => a.question.type === 'TEXT') // TODO: remove this when modals support select menus
.map(a => {
if (a.question.type === 'TEXT') {
return new ActionRowBuilder()
.setComponents(
new TextInputBuilder()
.setCustomId(String(a.id))
.setLabel(a.question.label)
.setStyle(a.question.style)
.setMaxLength(Math.min(a.question.maxLength, 1000))
.setMinLength(a.question.minLength)
.setPlaceholder(a.question.placeholder)
.setRequired(a.question.required)
.setValue(a.value ? cryptr.decrypt(a.value) : a.question.value),
);
const field = new TextInputBuilder()
.setCustomId(String(a.id))
.setLabel(a.question.label)
.setStyle(a.question.style)
.setMaxLength(Math.min(a.question.maxLength, 1000))
.setMinLength(a.question.minLength)
.setPlaceholder(a.question.placeholder)
.setRequired(a.question.required);
if (a.value) field.setValue(cryptr.decrypt(a.value));
else if (a.question.value) field.setValue(a.question.value);
return new ActionRowBuilder().setComponents(field);
} else if (a.question.type === 'MENU') {
return new ActionRowBuilder()
.setComponents(
Expand Down
22 changes: 10 additions & 12 deletions src/lib/tickets/manager.js
Expand Up @@ -285,18 +285,16 @@ module.exports = class TicketManager {
.filter(q => q.type === 'TEXT') // TODO: remove this when modals support select menus
.map(q => {
if (q.type === 'TEXT') {
return new ActionRowBuilder()
.setComponents(
new TextInputBuilder()
.setCustomId(q.id)
.setLabel(q.label)
.setStyle(q.style)
.setMaxLength(Math.min(q.maxLength, 1000))
.setMinLength(q.minLength)
.setPlaceholder(q.placeholder)
.setRequired(q.required)
.setValue(q.value),
);
const field = new TextInputBuilder()
.setCustomId(q.id)
.setLabel(q.label)
.setStyle(q.style)
.setMaxLength(Math.min(q.maxLength, 1000))
.setMinLength(q.minLength)
.setPlaceholder(q.placeholder)
.setRequired(q.required);
if (q.value) field.setValue(q.value);
return new ActionRowBuilder().setComponents(field);
} else if (q.type === 'MENU') {
return new ActionRowBuilder()
.setComponents(
Expand Down

0 comments on commit bcd02b1

Please sign in to comment.