blob: 147083296a8fa3f81908a80526dd3aadcd2e334c [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001export const event = "messageUpdate";
pineafan32767212022-03-14 21:27:39 +00002
3export async function callback(client, oldMessage, newMessage) {
pineafan63fc5e22022-08-04 22:04:10 +01004 if (newMessage.author.id === client.user.id) return;
Skyler Grey11236ba2022-08-08 21:13:33 +01005 const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } =
6 newMessage.channel.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01007 newMessage.reference = newMessage.reference || {};
8 let newContent = newMessage.cleanContent.replaceAll("`", "‘");
9 let oldContent = oldMessage.cleanContent.replaceAll("`", "‘");
10 let attachmentJump = "";
Skyler Grey11236ba2022-08-08 21:13:33 +010011 const config = (await client.database.guilds.read(newMessage.guild.id)).logging.attachments.saved[
12 newMessage.channel.id + newMessage.id
13 ];
Skyler Grey75ea9172022-08-06 10:22:23 +010014 if (config) {
15 attachmentJump = ` [[View attachments]](${config})`;
16 }
pineafan63fc5e22022-08-04 22:04:10 +010017 if (newContent === oldContent) {
Skyler Grey11236ba2022-08-08 21:13:33 +010018 if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) {
pineafan63fc5e22022-08-04 22:04:10 +010019 const data = {
20 meta: {
21 type: "messageAnnounce",
22 displayName: "Message Published",
23 calculateType: "messageAnnounce",
24 color: NucleusColors.yellow,
25 emoji: "MESSAGE.CREATE",
26 timestamp: newMessage.editedTimestamp
27 },
28 separate: {
29 end: `[[Jump to message]](${newMessage.url})`
30 },
31 list: {
32 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
Skyler Grey11236ba2022-08-08 21:13:33 +010033 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
34 sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
Skyler Grey75ea9172022-08-06 10:22:23 +010035 sent: entry(
36 new Date(newMessage.createdTimestamp),
37 renderDelta(new Date(newMessage.createdTimestamp))
38 ),
39 published: entry(
40 new Date(newMessage.editedTimestamp),
41 renderDelta(new Date(newMessage.editedTimestamp))
42 ),
Skyler Grey11236ba2022-08-08 21:13:33 +010043 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
pineafan63fc5e22022-08-04 22:04:10 +010044 attachments: entry(
Skyler Grey11236ba2022-08-08 21:13:33 +010045 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
46 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
pineafan63fc5e22022-08-04 22:04:10 +010047 )
48 },
49 hidden: {
50 guild: newMessage.channel.guild.id
pineafanda6e5342022-07-03 10:03:16 +010051 }
pineafan63fc5e22022-08-04 22:04:10 +010052 };
53 return log(data);
pineafan32767212022-03-14 21:27:39 +000054 }
pineafan63fc5e22022-08-04 22:04:10 +010055 }
Skyler Grey75ea9172022-08-06 10:22:23 +010056 if (!newMessage.editedTimestamp) {
57 return;
58 }
Skyler Grey11236ba2022-08-08 21:13:33 +010059 if (newContent.length > 256) newContent = newContent.substring(0, 253) + "...";
60 if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + "...";
pineafan63fc5e22022-08-04 22:04:10 +010061 const data = {
62 meta: {
63 type: "messageUpdate",
64 displayName: "Message Edited",
65 calculateType: "messageUpdate",
66 color: NucleusColors.yellow,
67 emoji: "MESSAGE.EDIT",
68 timestamp: newMessage.editedTimestamp
69 },
70 separate: {
Skyler Grey75ea9172022-08-06 10:22:23 +010071 start:
72 (oldContent
73 ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n`
74 : "**Before:** *Message had no content*\n") +
Skyler Grey11236ba2022-08-08 21:13:33 +010075 (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : "**After:** *Message had no content*"),
pineafan63fc5e22022-08-04 22:04:10 +010076 end: `[[Jump to message]](${newMessage.url})`
77 },
78 list: {
79 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
80 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
Skyler Grey11236ba2022-08-08 21:13:33 +010081 sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
82 sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
83 edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
84 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
pineafan63fc5e22022-08-04 22:04:10 +010085 attachments: entry(
Skyler Grey11236ba2022-08-08 21:13:33 +010086 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
87 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
pineafan63fc5e22022-08-04 22:04:10 +010088 ),
89 repliedTo: entry(
90 newMessage.reference.messageId || null,
Skyler Grey75ea9172022-08-06 10:22:23 +010091 newMessage.reference.messageId
92 ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})`
93 : "None"
pineafan63fc5e22022-08-04 22:04:10 +010094 )
95 },
96 hidden: {
97 guild: newMessage.channel.guild.id
98 }
99 };
100 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +0100101}