blob: 3502963aee326f0c2e93e9ae61704d666d746905 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001export const event = 'messageUpdate'
2
3export async function callback(client, oldMessage, newMessage) {
pineafane625d782022-05-09 18:04:32 +01004 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("`", "‘")
pineafanda6e5342022-07-03 10:03:16 +010010 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 };
pineafane625d782022-05-09 18:04:32 +010041 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: {
pineafanda6e5342022-07-03 10:03:16 +010058 messageId: entry(newMessage.id, `\`${newMessage.id}\``),
pineafane625d782022-05-09 18:04:32 +010059 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 }
pineafan32767212022-03-14 21:27:39 +000073 }
pineafan4edb7762022-06-26 19:21:04 +010074 log(data);
pineafane625d782022-05-09 18:04:32 +010075 } catch {}
pineafan32767212022-03-14 21:27:39 +000076}