From 33d61869d86550edb1567e43c2691ee9e0008dc2 Mon Sep 17 00:00:00 2001 From: Isaac Date: Tue, 11 Oct 2022 21:28:53 +0100 Subject: [PATCH] Fix `ticket` and `references` autocompleters --- src/autocomplete/references.js | 15 ++++++++++++++- src/autocomplete/ticket.js | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/autocomplete/references.js b/src/autocomplete/references.js index bf80611..f947726 100644 --- a/src/autocomplete/references.js +++ b/src/autocomplete/references.js @@ -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, }; }), diff --git a/src/autocomplete/ticket.js b/src/autocomplete/ticket.js index 7f86dbe..bdf58a1 100644 --- a/src/autocomplete/ticket.js +++ b/src/autocomplete/ticket.js @@ -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}`,