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 { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame^] | 5 | if (newMessage.author.id === client.user.id) return; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 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("`", "‘") |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 10 | let attachmentJump = ""; |
| 11 | let config = (await client.database.guilds.read(newMessage.guild.id)).logging.attachments.saved[newMessage.channel.id + newMessage.id]; |
| 12 | if (config) { attachmentJump = ` [[View attachments]](${config})` } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame^] | 13 | if (newContent === oldContent) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 14 | if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) { |
| 15 | let data = { |
| 16 | meta: { |
| 17 | type: 'messageAnnounce', |
| 18 | displayName: 'Message Published', |
| 19 | calculateType: 'messageAnnounce', |
| 20 | color: NucleusColors.yellow, |
| 21 | emoji: 'MESSAGE.CREATE', |
| 22 | timestamp: newMessage.editedTimestamp |
| 23 | }, |
| 24 | separate: { |
| 25 | end: `[[Jump to message]](${newMessage.url})` |
| 26 | }, |
| 27 | list: { |
| 28 | messageId: 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 | published: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))), |
| 33 | mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size), |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 34 | attachments: entry( |
| 35 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size), |
| 36 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump |
| 37 | ) |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 38 | }, |
| 39 | hidden: { |
| 40 | guild: newMessage.channel.guild.id |
| 41 | } |
| 42 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 43 | return log(data); |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 44 | } |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 45 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 46 | if (!newMessage.editedTimestamp) { return } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 47 | if (newContent.length > 256) newContent = newContent.substring(0, 253) + '...' |
| 48 | if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + '...' |
| 49 | let data = { |
| 50 | meta: { |
| 51 | type: 'messageUpdate', |
| 52 | displayName: 'Message Edited', |
| 53 | calculateType: 'messageUpdate', |
| 54 | color: NucleusColors.yellow, |
| 55 | emoji: 'MESSAGE.EDIT', |
| 56 | timestamp: newMessage.editedTimestamp |
| 57 | }, |
| 58 | separate: { |
| 59 | start: (oldContent ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` : '**Before:** *Message had no content*\n') + |
| 60 | (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : '**After:** *Message had no content*'), |
| 61 | end: `[[Jump to message]](${newMessage.url})` |
| 62 | }, |
| 63 | list: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 64 | messageId: entry(newMessage.id, `\`${newMessage.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 65 | sentBy: entry(newMessage.author.id, renderUser(newMessage.author)), |
| 66 | sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)), |
| 67 | sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))), |
| 68 | edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))), |
| 69 | mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size), |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 70 | attachments: entry( |
| 71 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size), |
| 72 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump |
| 73 | ), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 74 | repliedTo: entry( |
| 75 | newMessage.reference.messageId || null, |
| 76 | newMessage.reference.messageId ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` : "None" |
| 77 | ) |
| 78 | }, |
| 79 | hidden: { |
| 80 | guild: newMessage.channel.guild.id |
| 81 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 82 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 83 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 84 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 85 | } |