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 | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 5 | const { |
| 6 | log, |
| 7 | NucleusColors, |
| 8 | entry, |
| 9 | renderUser, |
| 10 | renderDelta, |
| 11 | renderNumberDelta, |
| 12 | renderChannel |
| 13 | } = newMessage.channel.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | newMessage.reference = newMessage.reference || {}; |
| 15 | let newContent = newMessage.cleanContent.replaceAll("`", "‘"); |
| 16 | let oldContent = oldMessage.cleanContent.replaceAll("`", "‘"); |
| 17 | let attachmentJump = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 18 | const config = (await client.database.guilds.read(newMessage.guild.id)) |
| 19 | .logging.attachments.saved[newMessage.channel.id + newMessage.id]; |
| 20 | if (config) { |
| 21 | attachmentJump = ` [[View attachments]](${config})`; |
| 22 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 23 | if (newContent === oldContent) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 24 | if ( |
| 25 | !oldMessage.flags.has("CROSSPOSTED") && |
| 26 | newMessage.flags.has("CROSSPOSTED") |
| 27 | ) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 28 | const data = { |
| 29 | meta: { |
| 30 | type: "messageAnnounce", |
| 31 | displayName: "Message Published", |
| 32 | calculateType: "messageAnnounce", |
| 33 | color: NucleusColors.yellow, |
| 34 | emoji: "MESSAGE.CREATE", |
| 35 | timestamp: newMessage.editedTimestamp |
| 36 | }, |
| 37 | separate: { |
| 38 | end: `[[Jump to message]](${newMessage.url})` |
| 39 | }, |
| 40 | list: { |
| 41 | messageId: entry(newMessage.id, `\`${newMessage.id}\``), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 42 | sentBy: entry( |
| 43 | newMessage.author.id, |
| 44 | renderUser(newMessage.author) |
| 45 | ), |
| 46 | sentIn: entry( |
| 47 | newMessage.channel.id, |
| 48 | renderChannel(newMessage.channel) |
| 49 | ), |
| 50 | sent: entry( |
| 51 | new Date(newMessage.createdTimestamp), |
| 52 | renderDelta(new Date(newMessage.createdTimestamp)) |
| 53 | ), |
| 54 | published: entry( |
| 55 | new Date(newMessage.editedTimestamp), |
| 56 | renderDelta(new Date(newMessage.editedTimestamp)) |
| 57 | ), |
| 58 | mentions: renderNumberDelta( |
| 59 | oldMessage.mentions.users.size, |
| 60 | newMessage.mentions.users.size |
| 61 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 62 | attachments: entry( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 63 | renderNumberDelta( |
| 64 | oldMessage.attachments.size, |
| 65 | newMessage.attachments.size |
| 66 | ), |
| 67 | renderNumberDelta( |
| 68 | oldMessage.attachments.size, |
| 69 | newMessage.attachments.size |
| 70 | ) + attachmentJump |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 71 | ) |
| 72 | }, |
| 73 | hidden: { |
| 74 | guild: newMessage.channel.guild.id |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 75 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 76 | }; |
| 77 | return log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 78 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 79 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 80 | if (!newMessage.editedTimestamp) { |
| 81 | return; |
| 82 | } |
| 83 | if (newContent.length > 256) |
| 84 | newContent = newContent.substring(0, 253) + "..."; |
| 85 | if (oldContent.length > 256) |
| 86 | oldContent = oldContent.substring(0, 253) + "..."; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 87 | const data = { |
| 88 | meta: { |
| 89 | type: "messageUpdate", |
| 90 | displayName: "Message Edited", |
| 91 | calculateType: "messageUpdate", |
| 92 | color: NucleusColors.yellow, |
| 93 | emoji: "MESSAGE.EDIT", |
| 94 | timestamp: newMessage.editedTimestamp |
| 95 | }, |
| 96 | separate: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 97 | start: |
| 98 | (oldContent |
| 99 | ? `**Before:**\n\`\`\`\n${oldContent}\n\`\`\`\n` |
| 100 | : "**Before:** *Message had no content*\n") + |
| 101 | (newContent |
| 102 | ? `**After:**\n\`\`\`\n${newContent}\n\`\`\`` |
| 103 | : "**After:** *Message had no content*"), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 104 | end: `[[Jump to message]](${newMessage.url})` |
| 105 | }, |
| 106 | list: { |
| 107 | messageId: entry(newMessage.id, `\`${newMessage.id}\``), |
| 108 | sentBy: entry(newMessage.author.id, renderUser(newMessage.author)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 109 | sentIn: entry( |
| 110 | newMessage.channel.id, |
| 111 | renderChannel(newMessage.channel) |
| 112 | ), |
| 113 | sent: entry( |
| 114 | new Date(newMessage.createdTimestamp), |
| 115 | renderDelta(new Date(newMessage.createdTimestamp)) |
| 116 | ), |
| 117 | edited: entry( |
| 118 | new Date(newMessage.editedTimestamp), |
| 119 | renderDelta(new Date(newMessage.editedTimestamp)) |
| 120 | ), |
| 121 | mentions: renderNumberDelta( |
| 122 | oldMessage.mentions.users.size, |
| 123 | newMessage.mentions.users.size |
| 124 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 125 | attachments: entry( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 126 | renderNumberDelta( |
| 127 | oldMessage.attachments.size, |
| 128 | newMessage.attachments.size |
| 129 | ), |
| 130 | renderNumberDelta( |
| 131 | oldMessage.attachments.size, |
| 132 | newMessage.attachments.size |
| 133 | ) + attachmentJump |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 134 | ), |
| 135 | repliedTo: entry( |
| 136 | newMessage.reference.messageId || null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 137 | newMessage.reference.messageId |
| 138 | ? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${newMessage.reference.messageId})` |
| 139 | : "None" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 140 | ) |
| 141 | }, |
| 142 | hidden: { |
| 143 | guild: newMessage.channel.guild.id |
| 144 | } |
| 145 | }; |
| 146 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 147 | } |