blob: 5e637978b8700261573b5054e8f20d7b8ce99970 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001export const event = 'messageUpdate'
2
3export async function callback(client, oldMessage, newMessage) {
pineafane625d782022-05-09 18:04:32 +01004 try {
5 if (newMessage.author.id == client.user.id) return;
6 const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = newMessage.channel.client.logger
7 newMessage.reference = newMessage.reference || {}
8 let newContent = newMessage.cleanContent.replaceAll("`", "‘")
9 let oldContent = oldMessage.cleanContent.replaceAll("`", "‘")
pineafan73a7c4a2022-07-24 10:38:04 +010010 let attachmentJump = "";
11 let config = (await client.database.guilds.read(newMessage.guild.id)).logging.attachments.saved[newMessage.channel.id + newMessage.id];
12 if (config) { attachmentJump = ` [[View attachments]](${config})` }
pineafanda6e5342022-07-03 10:03:16 +010013 if (newContent == oldContent) {
14 if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) {
15 let data = {
16 meta: {
17 type: 'messageAnnounce',
18 displayName: 'Message Published',
19 calculateType: 'messageAnnounce',
20 color: NucleusColors.yellow,
21 emoji: 'MESSAGE.CREATE',
22 timestamp: newMessage.editedTimestamp
23 },
24 separate: {
25 end: `[[Jump to message]](${newMessage.url})`
26 },
27 list: {
28 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
29 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
30 sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
31 sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
32 published: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
33 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
pineafan73a7c4a2022-07-24 10:38:04 +010034 attachments: entry(
35 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
36 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
37 )
pineafanda6e5342022-07-03 10:03:16 +010038 },
39 hidden: {
40 guild: newMessage.channel.guild.id
41 }
42 }
pineafan73a7c4a2022-07-24 10:38:04 +010043 return log(data);
pineafanda6e5342022-07-03 10:03:16 +010044 }
pineafanda6e5342022-07-03 10:03:16 +010045 };
pineafan73a7c4a2022-07-24 10:38:04 +010046 if (!newMessage.editedTimestamp) { return }
pineafane625d782022-05-09 18:04:32 +010047 if (newContent.length > 256) newContent = newContent.substring(0, 253) + '...'
48 if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + '...'
49 let data = {
50 meta: {
51 type: 'messageUpdate',
52 displayName: 'Message Edited',
53 calculateType: 'messageUpdate',
54 color: NucleusColors.yellow,
55 emoji: 'MESSAGE.EDIT',
56 timestamp: newMessage.editedTimestamp
57 },
58 separate: {
59 start: (oldContent ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` : '**Before:** *Message had no content*\n') +
60 (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : '**After:** *Message had no content*'),
61 end: `[[Jump to message]](${newMessage.url})`
62 },
63 list: {
pineafanda6e5342022-07-03 10:03:16 +010064 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
pineafane625d782022-05-09 18:04:32 +010065 sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
66 sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
67 sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
68 edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
69 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
pineafan73a7c4a2022-07-24 10:38:04 +010070 attachments: entry(
71 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
72 renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
73 ),
pineafane625d782022-05-09 18:04:32 +010074 repliedTo: entry(
75 newMessage.reference.messageId || null,
76 newMessage.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` : "None"
77 )
78 },
79 hidden: {
80 guild: newMessage.channel.guild.id
81 }
pineafan32767212022-03-14 21:27:39 +000082 }
pineafan4edb7762022-06-26 19:21:04 +010083 log(data);
pineafane625d782022-05-09 18:04:32 +010084 } catch {}
pineafan32767212022-03-14 21:27:39 +000085}