blob: d5556477fffaa8c3a26a43edbbb64b8ec32467d2 [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001export const event = 'guildMemberUpdate'
2
3export async function callback(client, before, after) {
4 try {
5 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = after.client.logger
pineafan73a7c4a2022-07-24 10:38:04 +01006 let auditLog = await getAuditLog(after.guild, 'MEMBER_UPDATE');
pineafane23c4ec2022-07-27 21:56:27 +01007 let audit = auditLog.entries.filter(entry => entry.target.id === after.id).first();
8 if (audit.executor.id === client.user.id) return;
9 if (before.nickname !== after.nickname) {
pineafan4edb7762022-06-26 19:21:04 +010010 try { await client.database.history.create(
11 "nickname", after.guild.id, after.user, audit.executor,
12 null, before.nickname || before.user.username, after.nickname || after.user.username) } catch {}
pineafane625d782022-05-09 18:04:32 +010013 let data = {
14 meta: {
15 type: 'memberUpdate',
16 displayName: 'Nickname Changed',
17 calculateType: 'guildMemberUpdate',
18 color: NucleusColors.yellow,
19 emoji: "PUNISH.NICKNAME.YELLOW",
20 timestamp: new Date().getTime()
21 },
22 list: {
pineafanda6e5342022-07-03 10:03:16 +010023 memberId: entry(after.id, `\`${after.id}\``),
pineafan73a7c4a2022-07-24 10:38:04 +010024 name: entry(after.user.id, renderUser(after.user)),
pineafane625d782022-05-09 18:04:32 +010025 before: entry(before.nickname, before.nickname ? before.nickname : '*None*'),
26 after: entry(after.nickname, after.nickname ? after.nickname : '*None*'),
pineafan73a7c4a2022-07-24 10:38:04 +010027 changed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
28 changedBy: entry(audit.executor.id, renderUser(audit.executor))
pineafane625d782022-05-09 18:04:32 +010029 },
30 hidden: {
31 guild: after.guild.id
32 }
33 }
pineafan4edb7762022-06-26 19:21:04 +010034 log(data);
pineafan73a7c4a2022-07-24 10:38:04 +010035 } else if (before.communicationDisabledUntilTimestamp < new Date().getTime() && after.communicationDisabledUntil > new Date().getTime()) {
36 try { await client.database.history.create(
37 "mute", after.guild.id, after.user, audit.executor, audit.reason, null, null, null
38 )} catch {}
39 let data = {
40 meta: {
41 type: 'memberMute',
42 displayName: 'Muted',
43 calculateType: 'guildMemberPunish',
44 color: NucleusColors.yellow,
45 emoji: "PUNISH.MUTE.YELLOW",
46 timestamp: new Date().getTime()
47 },
48 list: {
49 memberId: entry(after.id, `\`${after.id}\``),
50 name: entry(after.user.id, renderUser(after.user)),
51 mutedUntil: entry(after.communicationDisabledUntilTimestamp, renderDelta(after.communicationDisabledUntilTimestamp)),
52 muted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
53 mutedBy: entry(audit.executor.id, renderUser(audit.executor)),
54 reason: entry(audit.reason, audit.reason ? audit.reason : '\n> *No reason provided*')
55 },
56 hidden: {
57 guild: after.guild.id
58 }
59 }
60 log(data);
61 client.database.eventScheduler.schedule("naturalUnmute", after.communicationDisabledUntil,
62 {guild: after.guild.id, user: after.id, expires: after.communicationDisabledUntilTimestamp}
63 );
64 } else if (
65 after.communicationDisabledUntil === null && before.communicationDisabledUntilTimestamp !== null &&
66 new Date().getTime() >= audit.createdTimestamp
67 ) {
68 try { await client.database.history.create(
69 "unmute", after.guild.id, after.user, audit.executor, null, null, null, null
70 )} catch {}
71 let data = {
72 meta: {
73 type: 'memberUnmute',
74 displayName: 'Unmuted',
75 calculateType: 'guildMemberPunish',
76 color: NucleusColors.green,
77 emoji: "PUNISH.MUTE.GREEN",
78 timestamp: new Date().getTime()
79 },
80 list: {
81 memberId: entry(after.id, `\`${after.id}\``),
82 name: entry(after.user.id, renderUser(after.user)),
83 unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
84 unmutedBy: entry(audit.executor.id, renderUser(audit.executor))
85 },
86 hidden: {
87 guild: after.guild.id
88 }
89 }
90 log(data);
91 client.database.eventScheduler.cancel("naturalUnmute", {guild: after.guild.id, user: after.id, expires: before.communicationDisabledUntilTimestamp});
pineafane625d782022-05-09 18:04:32 +010092 }
93 } catch (e) { console.log(e) }
94}