new log diff

This commit is contained in:
Isaac
2022-07-17 14:13:44 +01:00
parent 574d101637
commit 5aac998bee
6 changed files with 33 additions and 7 deletions

View File

@@ -1,4 +1,20 @@
const { MessageEmbed } = require('discord.js');
const { diff: getDiff } = require('object-diffy');
function makeDiff({
original, updated,
}) {
const diff = getDiff(original, updated);
const fields = [];
for (const key in diff) {
if (key === 'createdAt') continue; // object-diffy doesn't like dates
fields.push({
name: key,
value: `\`\`\`diff\n${diff[key].from && `- ${diff[key].from}\n`}\n${diff[key].to && `+ ${diff[key].to}\n`}\n\`\`\``,
});
}
return fields;
}
/**
* @param {import("client")} client
@@ -57,6 +73,7 @@ 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: [
new MessageEmbed()
@@ -81,11 +98,11 @@ async function logAdminEvent(client, {
// text: settings.footer,
// }),
...[
action === 'update' && diff &&
diff &&
new MessageEmbed()
.setColor('ORANGE')
.setTitle(getMessage('log.admin.differences'))
.setDescription(`\`\`\`json\n${JSON.stringify(diff)}\n\`\`\``),
.setFields(makeDiff(diff)),
],
],
});