refactor: remove cryptr prefix

This commit is contained in:
Isaac 2022-10-24 17:44:07 +01:00
parent 15df841774
commit ecd23a150a
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33
5 changed files with 21 additions and 17 deletions

View File

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

View File

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

View File

@ -1,5 +1,5 @@
const Cryptr = require('cryptr'); const Cryptr = require('cryptr');
const cryptr = new Cryptr(process.env.ENCRYPTION_KEY); const { encrypt } = new Cryptr(process.env.ENCRYPTION_KEY);
/** /**
* Returns highest (roles.highest) hoisted role , or everyone * Returns highest (roles.highest) hoisted role , or everyone
@ -12,8 +12,6 @@ module.exports = class TicketArchiver {
constructor(client) { constructor(client) {
/** @type {import("client")} */ /** @type {import("client")} */
this.client = client; this.client = client;
this.encrypt = cryptr.encrypt;
this.decrypt = cryptr.decrypt;
} }
/** Add or update a message /** Add or update a message
@ -78,11 +76,11 @@ module.exports = class TicketArchiver {
avatar: member.avatar || member.user.avatar, // TODO: save avatar in user/avatars/ avatar: member.avatar || member.user.avatar, // TODO: save avatar in user/avatars/
bot: member.user.bot, bot: member.user.bot,
discriminator: member.user.discriminator, discriminator: member.user.discriminator,
displayName: member.displayName ? this.encrypt(member.displayName) : null, displayName: member.displayName ? encrypt(member.displayName) : null,
roleId: !!member && hoistedRole(member).id, roleId: !!member && hoistedRole(member).id,
ticketId, ticketId,
userId: member.user.id, userId: member.user.id,
username: this.encrypt(member.user.username), username: encrypt(member.user.username),
}; };
await this.client.prisma.archivedUser.upsert({ await this.client.prisma.archivedUser.upsert({
create: data, create: data,
@ -108,7 +106,7 @@ module.exports = class TicketArchiver {
}, },
}, },
}, },
content: cryptr.encrypt( content: encrypt(
JSON.stringify({ JSON.stringify({
attachments: [...message.attachments.values()], attachments: [...message.attachments.values()],
components: [...message.components.values()], components: [...message.components.values()],

View File

@ -3,7 +3,10 @@ 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 = 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 { module.exports = class QuestionsModal extends Modal {
constructor(client, options) { constructor(client, options) {
@ -51,7 +54,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 ? cryptr.encrypt(f.value) : '' }, data: { value: f.value ? encrypt(f.value) : '' },
where: { id: Number(f.customId) }, where: { id: Number(f.customId) },
})), })),
}, },
@ -72,7 +75,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 ? cryptr.decrypt(a.value) : getMessage('ticket.answers.no_value'), value: a.value ? decrypt(a.value) : getMessage('ticket.answers.no_value'),
})), })),
); );
await opening.edit({ embeds }); await opening.edit({ embeds });
@ -94,7 +97,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 ? 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; return diff;
}; };

View File

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