blob: 318b0ef3e6a9aeb5e78162aa8e8bed98e09d0f50 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001export const event = 'messageUpdate'
2
3export async function callback(client, oldMessage, newMessage) {
4 if (newMessage.author.id == client.user.id) return;
pineafan32767212022-03-14 21:27:39 +00005 const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = newMessage.channel.client.logger
6 newMessage.reference = newMessage.reference || {}
pineafan377794f2022-04-18 19:01:01 +01007 let newContent = newMessage.cleanContent.replaceAll("`", "‘")
8 let oldContent = oldMessage.cleanContent.replaceAll("`", "‘")
9 if (newContent == oldContent) return;
pineafan32767212022-03-14 21:27:39 +000010 if (newContent.length > 256) newContent = newContent.substring(0, 253) + '...'
11 if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + '...'
12 let data = {
13 meta: {
14 type: 'messageUpdate',
15 displayName: 'Message Edited',
16 calculateType: 'messageUpdate',
17 color: NucleusColors.yellow,
18 emoji: 'MESSAGE.EDIT',
19 timestamp: newMessage.editedTimestamp
20 },
21 separate: {
pineafan377794f2022-04-18 19:01:01 +010022 start: (oldContent ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` : '**Before:** *Message had no content*\n') +
23 (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : '**After:** *Message had no content*'),
pineafan32767212022-03-14 21:27:39 +000024 end: `[[Jump to message]](${newMessage.url})`
25 },
26 list: {
27 id: 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 edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
32 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
33 attachments: renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
34 repliedTo: entry(
35 newMessage.reference.messageId || null,
36 newMessage.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` : "None"
37 )
38 },
39 hidden: {
40 guild: newMessage.channel.guild.id
41 }
42 }
43 log(data, client);
44}