blob: c83512c9bcc8afb61909cfa58151e14288d8f9eb [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 Grey75ea9172022-08-06 10:22:23 +01005 const {
6 log,
7 NucleusColors,
8 entry,
9 renderUser,
10 renderDelta,
11 renderNumberDelta,
12 renderChannel
13 } = newMessage.channel.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010014 newMessage.reference = newMessage.reference || {};
15 let newContent = newMessage.cleanContent.replaceAll("`", "‘");
16 let oldContent = oldMessage.cleanContent.replaceAll("`", "‘");
17 let attachmentJump = "";
Skyler Grey75ea9172022-08-06 10:22:23 +010018 const config = (await client.database.guilds.read(newMessage.guild.id))
19 .logging.attachments.saved[newMessage.channel.id + newMessage.id];
20 if (config) {
21 attachmentJump = ` [[View attachments]](${config})`;
22 }
pineafan63fc5e22022-08-04 22:04:10 +010023 if (newContent === oldContent) {
Skyler Grey75ea9172022-08-06 10:22:23 +010024 if (
25 !oldMessage.flags.has("CROSSPOSTED") &&
26 newMessage.flags.has("CROSSPOSTED")
27 ) {
pineafan63fc5e22022-08-04 22:04:10 +010028 const data = {
29 meta: {
30 type: "messageAnnounce",
31 displayName: "Message Published",
32 calculateType: "messageAnnounce",
33 color: NucleusColors.yellow,
34 emoji: "MESSAGE.CREATE",
35 timestamp: newMessage.editedTimestamp
36 },
37 separate: {
38 end: `[[Jump to message]](${newMessage.url})`
39 },
40 list: {
41 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
Skyler Grey75ea9172022-08-06 10:22:23 +010042 sentBy: entry(
43 newMessage.author.id,
44 renderUser(newMessage.author)
45 ),
46 sentIn: entry(
47 newMessage.channel.id,
48 renderChannel(newMessage.channel)
49 ),
50 sent: entry(
51 new Date(newMessage.createdTimestamp),
52 renderDelta(new Date(newMessage.createdTimestamp))
53 ),
54 published: entry(
55 new Date(newMessage.editedTimestamp),
56 renderDelta(new Date(newMessage.editedTimestamp))
57 ),
58 mentions: renderNumberDelta(
59 oldMessage.mentions.users.size,
60 newMessage.mentions.users.size
61 ),
pineafan63fc5e22022-08-04 22:04:10 +010062 attachments: entry(
Skyler Grey75ea9172022-08-06 10:22:23 +010063 renderNumberDelta(
64 oldMessage.attachments.size,
65 newMessage.attachments.size
66 ),
67 renderNumberDelta(
68 oldMessage.attachments.size,
69 newMessage.attachments.size
70 ) + attachmentJump
pineafan63fc5e22022-08-04 22:04:10 +010071 )
72 },
73 hidden: {
74 guild: newMessage.channel.guild.id
pineafanda6e5342022-07-03 10:03:16 +010075 }
pineafan63fc5e22022-08-04 22:04:10 +010076 };
77 return log(data);
pineafan32767212022-03-14 21:27:39 +000078 }
pineafan63fc5e22022-08-04 22:04:10 +010079 }
Skyler Grey75ea9172022-08-06 10:22:23 +010080 if (!newMessage.editedTimestamp) {
81 return;
82 }
83 if (newContent.length > 256)
84 newContent = newContent.substring(0, 253) + "...";
85 if (oldContent.length > 256)
86 oldContent = oldContent.substring(0, 253) + "...";
pineafan63fc5e22022-08-04 22:04:10 +010087 const data = {
88 meta: {
89 type: "messageUpdate",
90 displayName: "Message Edited",
91 calculateType: "messageUpdate",
92 color: NucleusColors.yellow,
93 emoji: "MESSAGE.EDIT",
94 timestamp: newMessage.editedTimestamp
95 },
96 separate: {
Skyler Grey75ea9172022-08-06 10:22:23 +010097 start:
98 (oldContent
99 ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n`
100 : "**Before:** *Message had no content*\n") +
101 (newContent
102 ? `**After:**\n\`\`\`\n${newContent}\n\`\`\``
103 : "**After:** *Message had no content*"),
pineafan63fc5e22022-08-04 22:04:10 +0100104 end: `[[Jump to message]](${newMessage.url})`
105 },
106 list: {
107 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
108 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
Skyler Grey75ea9172022-08-06 10:22:23 +0100109 sentIn: entry(
110 newMessage.channel.id,
111 renderChannel(newMessage.channel)
112 ),
113 sent: entry(
114 new Date(newMessage.createdTimestamp),
115 renderDelta(new Date(newMessage.createdTimestamp))
116 ),
117 edited: entry(
118 new Date(newMessage.editedTimestamp),
119 renderDelta(new Date(newMessage.editedTimestamp))
120 ),
121 mentions: renderNumberDelta(
122 oldMessage.mentions.users.size,
123 newMessage.mentions.users.size
124 ),
pineafan63fc5e22022-08-04 22:04:10 +0100125 attachments: entry(
Skyler Grey75ea9172022-08-06 10:22:23 +0100126 renderNumberDelta(
127 oldMessage.attachments.size,
128 newMessage.attachments.size
129 ),
130 renderNumberDelta(
131 oldMessage.attachments.size,
132 newMessage.attachments.size
133 ) + attachmentJump
pineafan63fc5e22022-08-04 22:04:10 +0100134 ),
135 repliedTo: entry(
136 newMessage.reference.messageId || null,
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 newMessage.reference.messageId
138 ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})`
139 : "None"
pineafan63fc5e22022-08-04 22:04:10 +0100140 )
141 },
142 hidden: {
143 guild: newMessage.channel.guild.id
144 }
145 };
146 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +0100147}