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; |
| 5 | if (!newMessage.content || !oldMessage.content) return; |
| 6 | const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = newMessage.channel.client.logger |
| 7 | newMessage.reference = newMessage.reference || {} |
| 8 | let newContent = newMessage.cleanContent |
| 9 | let oldContent = oldMessage.cleanContent |
| 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: { |
| 22 | start: `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n**After:**\n\`\`\`\n${newContent}\n\`\`\``, |
| 23 | end: `[[Jump to message]](${newMessage.url})` |
| 24 | }, |
| 25 | list: { |
| 26 | id: entry(newMessage.id, `\`${newMessage.id}\``), |
| 27 | sentBy: entry(newMessage.author.id, renderUser(newMessage.author)), |
| 28 | sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)), |
| 29 | sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))), |
| 30 | edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))), |
| 31 | mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size), |
| 32 | attachments: renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size), |
| 33 | repliedTo: entry( |
| 34 | newMessage.reference.messageId || null, |
| 35 | newMessage.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` : "None" |
| 36 | ) |
| 37 | }, |
| 38 | hidden: { |
| 39 | guild: newMessage.channel.guild.id |
| 40 | } |
| 41 | } |
| 42 | log(data, client); |
| 43 | } |