mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
fix: convert surveys to buttons
This commit is contained in:
parent
c607771c9e
commit
dae9a8c0d0
@ -598,7 +598,11 @@
|
|||||||
"title": "✅ Thank you"
|
"title": "✅ Thank you"
|
||||||
},
|
},
|
||||||
"start": {
|
"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"
|
"title": "❔ Feedback"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -306,7 +306,24 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (survey) {
|
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(),
|
content: creator.toString(),
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
@ -317,66 +334,68 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
await r_collector_message.react('✅');
|
const filter = i => i.user.id === creator.id && i.customId.includes(channel.id);
|
||||||
|
const collector = channel.createMessageComponentCollector({
|
||||||
const filter = (reaction, user) => user.id === creator.user.id && reaction.emoji.name === '✅';
|
|
||||||
|
|
||||||
const r_collector = r_collector_message.createReactionCollector({
|
|
||||||
filter,
|
filter,
|
||||||
time: 60000
|
time: 60000
|
||||||
});
|
});
|
||||||
|
|
||||||
r_collector.on('collect', async () => {
|
collector.on('collect', async i => {
|
||||||
r_collector.stop();
|
await i.deferUpdate();
|
||||||
const filter = message => message.author.id === creator.id;
|
|
||||||
let answers = [];
|
if (i.customId === `start_survey:${channel.id}`) {
|
||||||
let number = 1;
|
const filter = message => message.author.id === creator.id;
|
||||||
for (const question of survey.questions) {
|
let answers = [];
|
||||||
|
let number = 1;
|
||||||
|
for (const question of survey.questions) {
|
||||||
|
await channel.send({
|
||||||
|
embeds: [
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setTitle(`${number++}/${survey.questions.length}`)
|
||||||
|
.setDescription(question)
|
||||||
|
.setFooter(i18n('collector_expires_in', 60))
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const collected = await channel.awaitMessages({
|
||||||
|
errors: ['time'],
|
||||||
|
filter,
|
||||||
|
max: 1,
|
||||||
|
time: 60000
|
||||||
|
});
|
||||||
|
answers.push(collected.first().content);
|
||||||
|
} catch (collected) {
|
||||||
|
await close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await channel.send({
|
await channel.send({
|
||||||
embeds: [
|
embeds: [
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(settings.colour)
|
.setColor(settings.success_colour)
|
||||||
.setTitle(`${number++}/${survey.questions.length}`)
|
.setTitle(i18n('ticket.survey.complete.title'))
|
||||||
.setDescription(question)
|
.setDescription(i18n('ticket.survey.complete.description'))
|
||||||
.setFooter(i18n('collector_expires_in', 60))
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
answers = answers.map(a => this.client.cryptr.encrypt(a));
|
||||||
const collected = await channel.awaitMessages({
|
await this.client.db.models.SurveyResponse.create({
|
||||||
errors: ['time'],
|
answers,
|
||||||
filter,
|
survey: survey.id,
|
||||||
max: 1,
|
ticket: t_row.id
|
||||||
time: 60000
|
});
|
||||||
});
|
await close();
|
||||||
answers.push(collected.first().content);
|
} else {
|
||||||
} catch (collected) {
|
await close();
|
||||||
return await close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await channel.send({
|
collector.stop();
|
||||||
embeds: [
|
|
||||||
new MessageEmbed()
|
|
||||||
.setColor(settings.success_colour)
|
|
||||||
.setTitle(i18n('ticket.survey.complete.title'))
|
|
||||||
.setDescription(i18n('ticket.survey.complete.description'))
|
|
||||||
.setFooter(settings.footer, guild.iconURL())
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
answers = answers.map(a => this.client.cryptr.encrypt(a));
|
|
||||||
await this.client.db.models.SurveyResponse.create({
|
|
||||||
answers,
|
|
||||||
survey: survey.id,
|
|
||||||
ticket: t_row.id
|
|
||||||
});
|
|
||||||
|
|
||||||
await close();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
r_collector.on('end', async collected => {
|
collector.on('end', async collected => {
|
||||||
if (collected.size === 0) {
|
if (collected.size === 0) {
|
||||||
await close();
|
await close();
|
||||||
}
|
}
|
||||||
@ -386,8 +405,8 @@ module.exports = class TicketManager extends EventEmitter {
|
|||||||
await close();
|
await close();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(async () => {
|
.catch(async error => {
|
||||||
this.client.log.debug('Skipping survey as member has left');
|
this.client.log.debug(error);
|
||||||
await close();
|
await close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user