MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/events/messageUpdate.js:12–54  ·  view source on GitHub ↗
(oldMessage, newMessage)

Source from the content-addressed store, hash-verified

10 once: false,
11
12 async execute(oldMessage, newMessage) {
13 try {
14 if (!newMessage.guild || newMessage.author?.bot) return;
15
16 if (oldMessage.content === newMessage.content) return;
17
18 const metaLines = [
19 formatLogLine('Channel', newMessage.channel ? `${newMessage.channel.name} ${newMessage.channel.toString()}` : 'Unknown'),
20 formatLogLine('Message ID', `\`${newMessage.id}\``),
21 formatLogLine('Message author', newMessage.author ? newMessage.author.toString() : 'Unknown'),
22 formatLogLine('Message created', `<t:${Math.floor(newMessage.createdTimestamp / 1000)}:R>`),
23 ];
24
25 const oldContent = oldMessage.content || '*(empty message)*';
26 const newContent = newMessage.content || '*(empty message)*';
27 const oldContentTruncated = oldContent.length > MAX_LOGGED_EDIT_CONTENT_LENGTH
28 ? `${oldContent.substring(0, MAX_LOGGED_EDIT_CONTENT_LENGTH - 3)}...`
29 : oldContent;
30 const newContentTruncated = newContent.length > MAX_LOGGED_EDIT_CONTENT_LENGTH
31 ? `${newContent.substring(0, MAX_LOGGED_EDIT_CONTENT_LENGTH - 3)}...`
32 : newContent;
33
34 await logEvent({
35 client: newMessage.client,
36 guildId: newMessage.guild.id,
37 eventType: EVENT_TYPES.MESSAGE_EDIT,
38 data: {
39 title: 'Message edited',
40 lines: metaLines,
41 quoted: true,
42 fields: [
43 { name: 'Before', value: oldContentTruncated, inline: true },
44 { name: 'After', value: newContentTruncated, inline: true },
45 ],
46 userId: newMessage.author?.id,
47 channelId: newMessage.channel.id,
48 }
49 });
50
51 } catch (error) {
52 logger.error('Error in messageUpdate event:', error);
53 }
54 }
55};

Callers

nothing calls this directly

Calls 2

formatLogLineFunction · 0.90
logEventFunction · 0.90

Tested by

no test coverage detected