blob: 0d42fb9438b06d80171c91e768b7600c480cdaf9 [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("`", "‘")
10 if (newContent == oldContent) return;
11 if (newContent.length > 256) newContent = newContent.substring(0, 253) + '...'
12 if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + '...'
13 let data = {
14 meta: {
15 type: 'messageUpdate',
16 displayName: 'Message Edited',
17 calculateType: 'messageUpdate',
18 color: NucleusColors.yellow,
19 emoji: 'MESSAGE.EDIT',
20 timestamp: newMessage.editedTimestamp
21 },
22 separate: {
23 start: (oldContent ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` : '**Before:** *Message had no content*\n') +
24 (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : '**After:** *Message had no content*'),
25 end: `[[Jump to message]](${newMessage.url})`
26 },
27 list: {
28 id: 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 edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
33 mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
34 attachments: renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
35 repliedTo: entry(
36 newMessage.reference.messageId || null,
37 newMessage.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` : "None"
38 )
39 },
40 hidden: {
41 guild: newMessage.channel.guild.id
42 }
pineafan32767212022-03-14 21:27:39 +000043 }
pineafan4edb7762022-06-26 19:21:04 +010044 log(data);
pineafane625d782022-05-09 18:04:32 +010045 } catch {}
pineafan32767212022-03-14 21:27:39 +000046}