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