fix: convert surveys to buttons

This commit is contained in:
Isaac 2021-10-07 12:21:44 +01:00
parent c607771c9e
commit dae9a8c0d0
No known key found for this signature in database
GPG Key ID: 87B9B6BD04EB7534
2 changed files with 73 additions and 50 deletions

View File

@ -598,7 +598,11 @@
"title": "✅ Thank you"
},
"start": {
"description": "Hey, %s. Before this channel is deleted, would you mind completing a quick %d-question survey? React with ✅ to start, or ignore this message.",
"buttons": {
"start": "Start survey",
"ignore": "No"
},
"description": "Hey, %s. Before this channel is deleted, would you mind completing a quick %d-question survey?",
"title": "❔ Feedback"
}
},

View File

@ -306,7 +306,24 @@ module.exports = class TicketManager extends EventEmitter {
});
if (survey) {
const r_collector_message = await channel.send({
await channel.send({
components: [
new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId(`start_survey:${channel.id}`)
.setLabel(i18n('ticket.survey.start.buttons.start'))
.setEmoji('✅')
.setStyle('SUCCESS')
)
.addComponents(
new MessageButton()
.setCustomId(`ignore_survey:${channel.id}`)
.setLabel(i18n('ticket.survey.start.buttons.ignore'))
.setEmoji('❌')
.setStyle('SECONDARY')
)
],
content: creator.toString(),
embeds: [
new MessageEmbed()
@ -317,17 +334,16 @@ module.exports = class TicketManager extends EventEmitter {
]
});
await r_collector_message.react('✅');
const filter = (reaction, user) => user.id === creator.user.id && reaction.emoji.name === '✅';
const r_collector = r_collector_message.createReactionCollector({
const filter = i => i.user.id === creator.id && i.customId.includes(channel.id);
const collector = channel.createMessageComponentCollector({
filter,
time: 60000
});
r_collector.on('collect', async () => {
r_collector.stop();
collector.on('collect', async i => {
await i.deferUpdate();
if (i.customId === `start_survey:${channel.id}`) {
const filter = message => message.author.id === creator.id;
let answers = [];
let number = 1;
@ -351,7 +367,7 @@ module.exports = class TicketManager extends EventEmitter {
});
answers.push(collected.first().content);
} catch (collected) {
return await close();
await close();
}
}
@ -371,12 +387,15 @@ module.exports = class TicketManager extends EventEmitter {
survey: survey.id,
ticket: t_row.id
});
await close();
} else {
await close();
}
collector.stop();
});
r_collector.on('end', async collected => {
collector.on('end', async collected => {
if (collected.size === 0) {
await close();
}
@ -386,8 +405,8 @@ module.exports = class TicketManager extends EventEmitter {
await close();
}
})
.catch(async () => {
this.client.log.debug('Skipping survey as member has left');
.catch(async error => {
this.client.log.debug(error);
await close();
});
}