Improve option format

This commit is contained in:
Isaac 2022-08-17 20:41:51 +01:00
parent 4c176d082f
commit 07af37b4a2
No known key found for this signature in database
GPG Key ID: F4EAABEB0FFCC06A
3 changed files with 12 additions and 27 deletions

View File

@ -1,4 +1,5 @@
const { Autocompleter } = require('@eartharoid/dbf'); const { Autocompleter } = require('@eartharoid/dbf');
const emoji = require('node-emoji');
module.exports = class TicketCompleter extends Autocompleter { module.exports = class TicketCompleter extends Autocompleter {
constructor(client, options) { constructor(client, options) {
@ -18,6 +19,14 @@ module.exports = class TicketCompleter extends Autocompleter {
const client = this.client; const client = this.client;
const settings = await client.prisma.guild.findUnique({ where: { id: interaction.guild.id } }); const settings = await client.prisma.guild.findUnique({ where: { id: interaction.guild.id } });
const tickets = await client.prisma.ticket.findMany({ const tickets = await client.prisma.ticket.findMany({
include: {
category: {
select: {
emoji: true,
name: true,
},
},
},
where: { where: {
createdById: interaction.user.id, createdById: interaction.user.id,
guildId: interaction.guild.id, guildId: interaction.guild.id,
@ -34,8 +43,10 @@ module.exports = class TicketCompleter extends Autocompleter {
.slice(0, 25) .slice(0, 25)
.map(t => { .map(t => {
const date = new Date(t.createdAt).toLocaleString(settings.locale, { dateStyle: 'short' }); const date = new Date(t.createdAt).toLocaleString(settings.locale, { dateStyle: 'short' });
const topic = t.topic ? '| ' + t.topic.substring(0, 50) : '';
const category = emoji.hasEmoji(t.category.emoji) ? emoji.get(t.category.emoji) + ' ' + t.category.name : t.category.name;
return { return {
name: `#${t.number} - ${date} ${t.topic ? '| ' + t.topic.substring(0, 50) : ''}`, name: `${category} #${t.number} - ${date} ${topic}`,
value: t.id, value: t.id,
}; };
}), }),

View File

@ -192,31 +192,6 @@ module.exports = class TicketManager {
}); });
} }
// const lastTicket = await this.client.prisma.ticket.findFirst({
// orderBy: [{ closedAt: 'desc' }],
// select: { closedAt: true },
// where: {
// categoryId: category.id,
// createdById: interaction.user.id,
// open: false,
// },
// });
// if (Date.now() - lastTicket.closedAt < category.cooldown) {
// return await interaction.reply({
// embeds: [
// new ExtendedEmbedBuilder({
// iconURL: guild.iconURL(),
// text: category.guild.footer,
// })
// .setColor(category.guild.errorColour)
// .setTitle(getMessage('misc.cooldown.title'))
// .setDescription(getMessage('misc.cooldown.description', { time: ms(category.cooldown - (Date.now() - lastTicket.closedAt)) })),
// ],
// ephemeral: true,
// });
// }
const cooldown = await this.getCooldown(category.id, interaction.user.id); const cooldown = await this.getCooldown(category.id, interaction.user.id);
if (cooldown) { if (cooldown) {
return await interaction.reply({ return await interaction.reply({

View File

@ -72,6 +72,5 @@ module.exports = {
ephemeral: true, ephemeral: true,
}); });
} }
}, },
}; };