blob: 148cdb7112506d61d52b2677db97ed98cfeb6a62 [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;
5 const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = newMessage.channel.client.logger;
6 newMessage.reference = newMessage.reference || {};
7 let newContent = newMessage.cleanContent.replaceAll("`", "‘");
8 let oldContent = oldMessage.cleanContent.replaceAll("`", "‘");
9 let attachmentJump = "";
10 const config = (await client.database.guilds.read(newMessage.guild.id)).logging.attachments.saved[newMessage.channel.id + newMessage.id];
11 if (config) { attachmentJump = ` [[View attachments]](${config})`; }
12 if (newContent === oldContent) {
13 if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) {
14 const data = {
15 meta: {
16 type: "messageAnnounce",
17 displayName: "Message Published",
18 calculateType: "messageAnnounce",
19 color: NucleusColors.yellow,
20 emoji: "MESSAGE.CREATE",
21 timestamp: newMessage.editedTimestamp
22 },
23 separate: {
24 end: `[[Jump to message]](${newMessage.url})`
25 },
26 list: {
27 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
28 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
29 sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
30 sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
31 published: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
32 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
33 attachments: entry(
34 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
35 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
36 )
37 },
38 hidden: {
39 guild: newMessage.channel.guild.id
pineafanda6e5342022-07-03 10:03:16 +010040 }
pineafan63fc5e22022-08-04 22:04:10 +010041 };
42 return log(data);
pineafan32767212022-03-14 21:27:39 +000043 }
pineafan63fc5e22022-08-04 22:04:10 +010044 }
45 if (!newMessage.editedTimestamp) { return; }
46 if (newContent.length > 256) newContent = newContent.substring(0, 253) + "...";
47 if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + "...";
48 const data = {
49 meta: {
50 type: "messageUpdate",
51 displayName: "Message Edited",
52 calculateType: "messageUpdate",
53 color: NucleusColors.yellow,
54 emoji: "MESSAGE.EDIT",
55 timestamp: newMessage.editedTimestamp
56 },
57 separate: {
58 start: (oldContent ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` : "**Before:** *Message had no content*\n") +
59 (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : "**After:** *Message had no content*"),
60 end: `[[Jump to message]](${newMessage.url})`
61 },
62 list: {
63 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
64 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
65 sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
66 sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
67 edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
68 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
69 attachments: entry(
70 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
71 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
72 ),
73 repliedTo: entry(
74 newMessage.reference.messageId || null,
75 newMessage.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` : "None"
76 )
77 },
78 hidden: {
79 guild: newMessage.channel.guild.id
80 }
81 };
82 log(data);
83}