pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | export const event = "messageUpdate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 2 | |
| 3 | export async function callback(client, oldMessage, newMessage) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | if (newMessage.author.id === client.user.id) return; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 5 | const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = |
| 6 | newMessage.channel.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 7 | newMessage.reference = newMessage.reference || {}; |
| 8 | let newContent = newMessage.cleanContent.replaceAll("`", "‘"); |
| 9 | let oldContent = oldMessage.cleanContent.replaceAll("`", "‘"); |
| 10 | let attachmentJump = ""; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 11 | const config = (await client.database.guilds.read(newMessage.guild.id)).logging.attachments.saved[ |
| 12 | newMessage.channel.id + newMessage.id |
| 13 | ]; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 14 | if (config) { |
| 15 | attachmentJump = ` [[View attachments]](${config})`; |
| 16 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | if (newContent === oldContent) { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 18 | if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 19 | const data = { |
| 20 | meta: { |
| 21 | type: "messageAnnounce", |
| 22 | displayName: "Message Published", |
| 23 | calculateType: "messageAnnounce", |
| 24 | color: NucleusColors.yellow, |
| 25 | emoji: "MESSAGE.CREATE", |
| 26 | timestamp: newMessage.editedTimestamp |
| 27 | }, |
| 28 | separate: { |
| 29 | end: `[[Jump to message]](${newMessage.url})` |
| 30 | }, |
| 31 | list: { |
| 32 | messageId: entry(newMessage.id, `\`${newMessage.id}\``), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 33 | sentBy: entry(newMessage.author.id, renderUser(newMessage.author)), |
| 34 | sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | sent: entry( |
| 36 | new Date(newMessage.createdTimestamp), |
| 37 | renderDelta(new Date(newMessage.createdTimestamp)) |
| 38 | ), |
| 39 | published: entry( |
| 40 | new Date(newMessage.editedTimestamp), |
| 41 | renderDelta(new Date(newMessage.editedTimestamp)) |
| 42 | ), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 43 | mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | attachments: entry( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 45 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size), |
| 46 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 47 | ) |
| 48 | }, |
| 49 | hidden: { |
| 50 | guild: newMessage.channel.guild.id |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 51 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 52 | }; |
| 53 | return log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 54 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 55 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 56 | if (!newMessage.editedTimestamp) { |
| 57 | return; |
| 58 | } |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 59 | if (newContent.length > 256) newContent = newContent.substring(0, 253) + "..."; |
| 60 | if (oldContent.length > 256) oldContent = oldContent.substring(0, 253) + "..."; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 61 | const data = { |
| 62 | meta: { |
| 63 | type: "messageUpdate", |
| 64 | displayName: "Message Edited", |
| 65 | calculateType: "messageUpdate", |
| 66 | color: NucleusColors.yellow, |
| 67 | emoji: "MESSAGE.EDIT", |
| 68 | timestamp: newMessage.editedTimestamp |
| 69 | }, |
| 70 | separate: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 71 | start: |
| 72 | (oldContent |
| 73 | ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` |
| 74 | : "**Before:** *Message had no content*\n") + |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 75 | (newContent ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` : "**After:** *Message had no content*"), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 76 | end: `[[Jump to message]](${newMessage.url})` |
| 77 | }, |
| 78 | list: { |
| 79 | messageId: entry(newMessage.id, `\`${newMessage.id}\``), |
| 80 | sentBy: entry(newMessage.author.id, renderUser(newMessage.author)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 81 | sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)), |
| 82 | sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))), |
| 83 | edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))), |
| 84 | mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 85 | attachments: entry( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 86 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size), |
| 87 | renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 88 | ), |
| 89 | repliedTo: entry( |
| 90 | newMessage.reference.messageId || null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 91 | newMessage.reference.messageId |
| 92 | ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` |
| 93 | : "None" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 94 | ) |
| 95 | }, |
| 96 | hidden: { |
| 97 | guild: newMessage.channel.guild.id |
| 98 | } |
| 99 | }; |
| 100 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 101 | } |