mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-04 09:21:25 +03:00
Fixes and stuff
This commit is contained in:
@@ -37,7 +37,7 @@ module.exports = config => {
|
||||
}
|
||||
|
||||
return new Logger({
|
||||
namespaces: ['commands', 'http', 'listeners'],
|
||||
namespaces: ['commands', 'http', 'listeners', 'settings', 'tickets'],
|
||||
transports,
|
||||
});
|
||||
};
|
||||
|
@@ -32,21 +32,6 @@ async function getLogChannel(client, guildId) {
|
||||
return channelId && client.channels.cache.get(channelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("client")} client
|
||||
* @param {*} target
|
||||
* @returns {string} target.type
|
||||
* @returns {string} target.id
|
||||
*/
|
||||
async function getTargetName(client, target) {
|
||||
if (target.type === 'settings') {
|
||||
return client.guilds.cache.get(target.id).name;
|
||||
} else {
|
||||
const row = await client.prisma[target.type].findUnique({ where: { id: target.id } });
|
||||
return row.name ?? target.id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("client")} client
|
||||
* @param {object} details
|
||||
@@ -58,7 +43,7 @@ async function logAdminEvent(client, {
|
||||
guildId, userId, action, target, diff,
|
||||
}) {
|
||||
const user = await client.users.fetch(userId);
|
||||
client.log.info(`${user.tag} ${action}d ${target.type} ${target.id}`);
|
||||
client.log.info.settings(`${user.tag} ${action}d ${target.type} ${target.id}`);
|
||||
const settings = await client.prisma.guild.findUnique({
|
||||
select: {
|
||||
footer: true,
|
||||
@@ -75,7 +60,6 @@ async function logAdminEvent(client, {
|
||||
};
|
||||
const channel = client.channels.cache.get(settings.logChannel);
|
||||
if (!channel) return;
|
||||
const targetName = await getTargetName(client, target);
|
||||
|
||||
return await channel.send({
|
||||
embeds: [
|
||||
@@ -95,7 +79,7 @@ async function logAdminEvent(client, {
|
||||
targetType: getMessage(`log.admin.description.target.${target.type}`),
|
||||
verb: getMessage(`log.admin.verb.${action}`),
|
||||
}))
|
||||
.addField(getMessage(`log.admin.title.target.${target.type}`), targetName),
|
||||
.addField(getMessage(`log.admin.title.target.${target.type}`), target.name ?? target.id),
|
||||
// .setFooter({
|
||||
// iconURL: client.guilds.cache.get(guildId).iconURL(),
|
||||
// text: settings.footer,
|
||||
@@ -104,7 +88,8 @@ async function logAdminEvent(client, {
|
||||
diff?.original &&
|
||||
new MessageEmbed()
|
||||
.setColor('ORANGE')
|
||||
.setTitle(getMessage('log.admin.changes'))
|
||||
.setTitle(getMessage('log.admin.changes.title'))
|
||||
.setDescription(getMessage('log.admin.changes.description'))
|
||||
.setFields(makeDiff(diff)),
|
||||
],
|
||||
],
|
||||
|
@@ -5,7 +5,7 @@ const fields = [
|
||||
'content',
|
||||
'username',
|
||||
'displayName',
|
||||
'channelName',
|
||||
// 'channelName',
|
||||
'openingMessage',
|
||||
'description',
|
||||
'value',
|
||||
@@ -19,23 +19,50 @@ const fields = [
|
||||
const shouldEncrypt = ['create', 'createMany', 'update', 'updateMany', 'upsert'];
|
||||
const shouldDecrypt = ['findUnique', 'findFirst', 'findMany'];
|
||||
|
||||
module.exports = async (params, next) => {
|
||||
if (params.args.data && shouldEncrypt.includes(params.action)) {
|
||||
for (const field of fields) {
|
||||
if (field in params.args.data && params.args.data[field] !== null && params.args.data[field] !== undefined) {
|
||||
params.args.data[field] = cryptr.encrypt(params.args.data[field]);
|
||||
|
||||
|
||||
|
||||
module.exports = log => {
|
||||
const encrypt = obj => {
|
||||
for (const prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
if (typeof obj[prop] === 'object') {
|
||||
obj[prop] = encrypt(obj[prop]);
|
||||
} else if (typeof obj[prop] === 'string' && obj[prop].length !== 0 && fields.includes(prop)) {
|
||||
try {
|
||||
obj[prop] = cryptr.encrypt(obj[prop]);
|
||||
} catch (error) {
|
||||
log.warn(`Failed to encrypt ${prop}`);
|
||||
log.debug(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
const result = await next(params);
|
||||
|
||||
if (result && shouldDecrypt.includes(params.action)) {
|
||||
for (const field of fields) {
|
||||
if (field in result && result[field] !== null && result[field] !== undefined) {
|
||||
result[field] = cryptr.decrypt(params.result[field]);
|
||||
const decrypt = obj => {
|
||||
for (const prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
if (typeof obj[prop] === 'object') {
|
||||
obj[prop] = decrypt(obj[prop]);
|
||||
} else if (typeof obj[prop] === 'string' && obj[prop].length !== 0 && fields.includes(prop)) {
|
||||
try {
|
||||
obj[prop] = cryptr.decrypt(obj[prop]);
|
||||
} catch (error) {
|
||||
log.warn(`Failed to decrypt ${prop}`);
|
||||
log.debug(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return obj;
|
||||
};
|
||||
|
||||
return async (params, next) => {
|
||||
if (params.args.data && shouldEncrypt.includes(params.action)) params.args = encrypt(params.args);
|
||||
let result = await next(params);
|
||||
if (result && shouldDecrypt.includes(params.action)) result = decrypt(result);
|
||||
return result;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user