refactor: remove cryptr prefix

This commit is contained in:
Isaac
2022-10-24 17:44:07 +01:00
parent 15df841774
commit ecd23a150a
5 changed files with 21 additions and 17 deletions

View File

@@ -3,7 +3,10 @@ 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);
const {
encrypt,
decrypt,
} = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class QuestionsModal extends Modal {
constructor(client, options) {
@@ -51,7 +54,7 @@ module.exports = class QuestionsModal extends Modal {
data: {
questionAnswers: {
update: interaction.fields.fields.map(f => ({
data: { value: f.value ? cryptr.encrypt(f.value) : '' },
data: { value: f.value ? encrypt(f.value) : '' },
where: { id: Number(f.customId) },
})),
},
@@ -72,7 +75,7 @@ module.exports = class QuestionsModal extends Modal {
ticket.questionAnswers
.map(a => ({
name: a.question.label,
value: a.value ? cryptr.decrypt(a.value) : getMessage('ticket.answers.no_value'),
value: a.value ? decrypt(a.value) : getMessage('ticket.answers.no_value'),
})),
);
await opening.edit({ embeds });
@@ -94,7 +97,7 @@ module.exports = class QuestionsModal extends Modal {
const makeDiff = ticket => {
const diff = {};
ticket.questionAnswers.forEach(a => {
diff[a.question.label] = a.value ? cryptr.decrypt(a.value) : getMessage('ticket.answers.no_value');
diff[a.question.label] = a.value ? decrypt(a.value) : getMessage('ticket.answers.no_value');
});
return diff;
};

View File

@@ -3,7 +3,10 @@ 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);
const {
encrypt,
decrypt,
} = new Cryptr(process.env.ENCRYPTION_KEY);
module.exports = class TopicModal extends Modal {
constructor(client, options) {
@@ -38,7 +41,7 @@ module.exports = class TopicModal extends Modal {
where: { id: interaction.channel.id },
});
const ticket = await client.prisma.ticket.update({
data: { topic: topic ? cryptr.encrypt(topic) : null },
data: { topic: topic ? encrypt(topic) : null },
select,
where: { id: interaction.channel.id },
});
@@ -72,7 +75,7 @@ module.exports = class TopicModal extends Modal {
/** @param {ticket} ticket */
const makeDiff = ticket => {
const diff = {};
diff[getMessage('ticket.opening_message.fields.topic')] = ticket.topic ? cryptr.decrypt(ticket.topic) : ' ';
diff[getMessage('ticket.opening_message.fields.topic')] = ticket.topic ? decrypt(ticket.topic) : ' ';
return diff;
};