Fix ticket and references autocompleters

This commit is contained in:
Isaac 2022-10-11 21:28:53 +01:00
parent 83ab003db5
commit 33d61869d8
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
2 changed files with 17 additions and 2 deletions

View File

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

View File

@ -1,5 +1,7 @@
const { Autocompleter } = require('@eartharoid/dbf');
const emoji = require('node-emoji');
const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class TicketCompleter extends Autocompleter {
constructor(client, options) {
@ -43,7 +45,7 @@ module.exports = class TicketCompleter extends Autocompleter {
.slice(0, 25)
.map(t => {
const date = new Date(t.createdAt).toLocaleString(settings.locale, { dateStyle: 'short' });
const topic = t.topic ? '| ' + t.topic.substring(0, 50) : '';
const topic = t.topic ? '| ' + cryptr.decrypt(t.topic).substring(0, 50) : '';
const category = emoji.hasEmoji(t.category.emoji) ? emoji.get(t.category.emoji) + ' ' + t.category.name : t.category.name;
return {
name: `${category} #${t.number} - ${date} ${topic}`,