pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | export const event = 'messageUpdate' |
| 2 | |
| 3 | export async function callback(client, oldMessage, newMessage) { |
| 4 | if (newMessage.author.id == client.user.id) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 5 | const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = newMessage.channel.client.logger |
| 6 | newMessage.reference = newMessage.reference || {} |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 7 | let newContent = newMessage.cleanContent.replaceAll("`", "‘") |
| 8 | let oldContent = oldMessage.cleanContent.replaceAll("`", "‘") |
| 9 | if (newContent == oldContent) return; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 10 | 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: { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 22 | 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*'), |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 24 | 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 | } |