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, TextInputStyle,
} = require('discord.js'); } = require('discord.js');
const emoji = require('node-emoji'); const emoji = require('node-emoji');
const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class EditButton extends Button { module.exports = class EditButton extends Button {
constructor(client, options) { constructor(client, options) {
@ -52,7 +54,7 @@ module.exports = class EditButton extends Button {
.setMinLength(5) .setMinLength(5)
.setPlaceholder(getMessage('modals.topic.placeholder')) .setPlaceholder(getMessage('modals.topic.placeholder'))
.setRequired(true) .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) .setMinLength(a.question.minLength)
.setPlaceholder(a.question.placeholder) .setPlaceholder(a.question.placeholder)
.setRequired(a.question.required) .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') { } else if (a.question.type === 'MENU') {
return new ActionRowBuilder() return new ActionRowBuilder()

View File

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

View File

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

View File

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