Skip to content

Commit

Permalink
refactor: remove cryptr prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
eartharoid committed Oct 24, 2022
1 parent 15df841 commit ecd23a1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/autocomplete/references.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Autocompleter } = require('@eartharoid/dbf');
const emoji = require('node-emoji');
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 {
constructor(client, options) {
Expand Down Expand Up @@ -45,7 +45,7 @@ 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 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;
return {
name: `${category} #${t.number} - ${date} ${topic}`,
Expand Down
4 changes: 2 additions & 2 deletions src/autocomplete/ticket.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Autocompleter } = require('@eartharoid/dbf');
const emoji = require('node-emoji');
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 {
constructor(client, options) {
Expand Down Expand Up @@ -45,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 ? '| ' + 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;
return {
name: `${category} #${t.number} - ${date} ${topic}`,
Expand Down
10 changes: 4 additions & 6 deletions src/lib/tickets/archiver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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
Expand All @@ -12,8 +12,6 @@ module.exports = class TicketArchiver {
constructor(client) {
/** @type {import("client")} */
this.client = client;
this.encrypt = cryptr.encrypt;
this.decrypt = cryptr.decrypt;
}

/** Add or update a message
Expand Down Expand Up @@ -78,11 +76,11 @@ module.exports = class TicketArchiver {
avatar: member.avatar || member.user.avatar, // TODO: save avatar in user/avatars/
bot: member.user.bot,
discriminator: member.user.discriminator,
displayName: member.displayName ? this.encrypt(member.displayName) : null,
displayName: member.displayName ? encrypt(member.displayName) : null,
roleId: !!member && hoistedRole(member).id,
ticketId,
userId: member.user.id,
username: this.encrypt(member.user.username),
username: encrypt(member.user.username),
};
await this.client.prisma.archivedUser.upsert({
create: data,
Expand All @@ -108,7 +106,7 @@ module.exports = class TicketArchiver {
},
},
},
content: cryptr.encrypt(
content: encrypt(
JSON.stringify({
attachments: [...message.attachments.values()],
components: [...message.components.values()],
Expand Down
11 changes: 7 additions & 4 deletions src/modals/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) },
})),
},
Expand All @@ -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 });
Expand All @@ -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;
};
Expand Down
9 changes: 6 additions & 3 deletions src/modals/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 },
});
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit ecd23a1

Please sign in to comment.