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