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) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 4 | 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 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 43 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 44 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 45 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 46 | } |