Question answer & topic encryption

This commit is contained in:
Isaac 2022-09-11 19:46:53 +01:00
parent 7dd1478de1
commit 94c6fc21e7
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
4 changed files with 17 additions and 9 deletions

View File

@ -8,6 +8,8 @@ const {
TextInputStyle,
} = require('discord.js');
const emoji = require('node-emoji');
const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class EditButton extends Button {
constructor(client, options) {
@ -52,7 +54,7 @@ module.exports = class EditButton extends Button {
.setMinLength(5)
.setPlaceholder(getMessage('modals.topic.placeholder'))
.setRequired(true)
.setValue(ticket.topic || ''),
.setValue(ticket.topic ? cryptr.decrypt(ticket.topic) : ''),
),
),
);
@ -79,7 +81,7 @@ module.exports = class EditButton extends Button {
.setMinLength(a.question.minLength)
.setPlaceholder(a.question.placeholder)
.setRequired(a.question.required)
.setValue(a.value || a.question.value),
.setValue(a.value ? cryptr.decrypt(a.value) : a.question.value),
);
} else if (a.question.type === 'MENU') {
return new ActionRowBuilder()

View File

@ -15,6 +15,8 @@ const emoji = require('node-emoji');
const ms = require('ms');
const ExtendedEmbedBuilder = require('../embed');
const { logTicketEvent } = require('../logging');
const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY);
/**
* @typedef {import('@prisma/client').Category &
@ -314,7 +316,7 @@ module.exports = class TicketManager {
answers = category.questions.map(q => ({
questionId: q.id,
userId: interaction.user.id,
value: interaction.fields.getTextInputValue(q.id),
value: interaction.fields.getTextInputValue(q.id) ? cryptr.encrypt(interaction.fields.getTextInputValue(q.id)) : '',
}));
if (category.customTopic) topic = interaction.fields.getTextInputValue(category.customTopic);
} else if (action === 'topic') {
@ -549,7 +551,7 @@ module.exports = class TicketManager {
id: channel.id,
number,
openingMessageId: sent.id,
topic,
topic: topic ? cryptr.encrypt(topic) : null,
};
if (referencesTicketId) data.referencesTicket = { connect: { id: referencesTicketId } };
let message;

View File

@ -2,6 +2,8 @@ const { Modal } = require('@eartharoid/dbf');
const { EmbedBuilder } = require('discord.js');
const ExtendedEmbedBuilder = require('../lib/embed');
const { logTicketEvent } = require('../lib/logging');
const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class QuestionsModal extends Modal {
constructor(client, options) {
@ -49,7 +51,7 @@ module.exports = class QuestionsModal extends Modal {
data: {
questionAnswers: {
update: interaction.fields.fields.map(f => ({
data: { value: f.value },
data: { value: f.value ? cryptr.encrypt(f.value) : '' },
where: { id: Number(f.customId) },
})),
},
@ -70,7 +72,7 @@ module.exports = class QuestionsModal extends Modal {
ticket.questionAnswers
.map(a => ({
name: a.question.label,
value: a.value || getMessage('ticket.answers.no_value'),
value: a.value ? cryptr.decrypt(a.value) : getMessage('ticket.answers.no_value'),
})),
);
await opening.edit({ embeds });
@ -92,7 +94,7 @@ module.exports = class QuestionsModal extends Modal {
const makeDiff = ticket => {
const diff = {};
ticket.questionAnswers.forEach(a => {
diff[a.question.label] = a.value || getMessage('ticket.answers.no_value');
diff[a.question.label] = a.value ? cryptr.decrypt(a.value) : getMessage('ticket.answers.no_value');
});
return diff;
};

View File

@ -2,6 +2,8 @@ const { Modal } = require('@eartharoid/dbf');
const { EmbedBuilder } = require('discord.js');
const ExtendedEmbedBuilder = require('../lib/embed');
const { logTicketEvent } = require('../lib/logging');
const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class TopicModal extends Modal {
constructor(client, options) {
@ -36,7 +38,7 @@ module.exports = class TopicModal extends Modal {
where: { id: interaction.channel.id },
});
const ticket = await client.prisma.ticket.update({
data: { topic },
data: { topic: topic ? cryptr.encrypt(topic) : null },
select,
where: { id: interaction.channel.id },
});
@ -70,7 +72,7 @@ module.exports = class TopicModal extends Modal {
/** @param {ticket} ticket */
const makeDiff = ticket => {
const diff = {};
diff[getMessage('ticket.opening_message.fields.topic')] = ticket.topic;
diff[getMessage('ticket.opening_message.fields.topic')] = ticket.topic ? cryptr.decrypt(ticket.topic) : ' ';
return diff;
};