blob: 08730f2e19199f84b98f357c7070d9c169a86b75 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001export const event = "guildMemberUpdate";
pineafane625d782022-05-09 18:04:32 +01002
3export async function callback(client, before, after) {
4 try {
Skyler Grey11236ba2022-08-08 21:13:33 +01005 const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = after.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01006 const auditLog = await getAuditLog(after.guild, "MEMBER_UPDATE");
Skyler Grey11236ba2022-08-08 21:13:33 +01007 const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first();
pineafane23c4ec2022-07-27 21:56:27 +01008 if (audit.executor.id === client.user.id) return;
9 if (before.nickname !== after.nickname) {
pineafan63fc5e22022-08-04 22:04:10 +010010 await client.database.history.create(
Skyler Grey75ea9172022-08-06 10:22:23 +010011 "nickname",
12 after.guild.id,
13 after.user,
14 audit.executor,
15 null,
16 before.nickname || before.user.username,
17 after.nickname || after.user.username
18 );
pineafan63fc5e22022-08-04 22:04:10 +010019 const data = {
pineafane625d782022-05-09 18:04:32 +010020 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010021 type: "memberUpdate",
22 displayName: "Nickname Changed",
23 calculateType: "guildMemberUpdate",
pineafane625d782022-05-09 18:04:32 +010024 color: NucleusColors.yellow,
25 emoji: "PUNISH.NICKNAME.YELLOW",
26 timestamp: new Date().getTime()
27 },
28 list: {
pineafanda6e5342022-07-03 10:03:16 +010029 memberId: entry(after.id, `\`${after.id}\``),
pineafan73a7c4a2022-07-24 10:38:04 +010030 name: entry(after.user.id, renderUser(after.user)),
Skyler Grey11236ba2022-08-08 21:13:33 +010031 before: entry(before.nickname, before.nickname ? before.nickname : "*None*"),
32 after: entry(after.nickname, after.nickname ? after.nickname : "*None*"),
33 changed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
34 changedBy: entry(audit.executor.id, renderUser(audit.executor))
pineafane625d782022-05-09 18:04:32 +010035 },
36 hidden: {
37 guild: after.guild.id
38 }
pineafan63fc5e22022-08-04 22:04:10 +010039 };
pineafan4edb7762022-06-26 19:21:04 +010040 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +010041 } else if (
42 before.communicationDisabledUntilTimestamp < new Date().getTime() &&
43 after.communicationDisabledUntil > new Date().getTime()
44 ) {
pineafan63fc5e22022-08-04 22:04:10 +010045 await client.database.history.create(
Skyler Grey75ea9172022-08-06 10:22:23 +010046 "mute",
47 after.guild.id,
48 after.user,
49 audit.executor,
50 audit.reason,
51 null,
52 null,
53 null
pineafan63fc5e22022-08-04 22:04:10 +010054 );
55 const data = {
pineafan73a7c4a2022-07-24 10:38:04 +010056 meta: {
pineafan63fc5e22022-08-04 22:04:10 +010057 type: "memberMute",
58 displayName: "Muted",
59 calculateType: "guildMemberPunish",
pineafan73a7c4a2022-07-24 10:38:04 +010060 color: NucleusColors.yellow,
61 emoji: "PUNISH.MUTE.YELLOW",
62 timestamp: new Date().getTime()
63 },
64 list: {
65 memberId: entry(after.id, `\`${after.id}\``),
66 name: entry(after.user.id, renderUser(after.user)),
Skyler Grey75ea9172022-08-06 10:22:23 +010067 mutedUntil: entry(
68 after.communicationDisabledUntilTimestamp,
69 renderDelta(after.communicationDisabledUntilTimestamp)
70 ),
Skyler Grey11236ba2022-08-08 21:13:33 +010071 muted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
72 mutedBy: entry(audit.executor.id, renderUser(audit.executor)),
73 reason: entry(audit.reason, audit.reason ? audit.reason : "\n> *No reason provided*")
pineafan73a7c4a2022-07-24 10:38:04 +010074 },
75 hidden: {
76 guild: after.guild.id
77 }
pineafan63fc5e22022-08-04 22:04:10 +010078 };
pineafan73a7c4a2022-07-24 10:38:04 +010079 log(data);
Skyler Grey11236ba2022-08-08 21:13:33 +010080 client.database.eventScheduler.schedule("naturalUnmute", after.communicationDisabledUntil, {
81 guild: after.guild.id,
82 user: after.id,
83 expires: after.communicationDisabledUntilTimestamp
84 });
pineafan73a7c4a2022-07-24 10:38:04 +010085 } else if (
Skyler Grey75ea9172022-08-06 10:22:23 +010086 after.communicationDisabledUntil === null &&
87 before.communicationDisabledUntilTimestamp !== null &&
pineafan73a7c4a2022-07-24 10:38:04 +010088 new Date().getTime() >= audit.createdTimestamp
89 ) {
pineafan63fc5e22022-08-04 22:04:10 +010090 await client.database.history.create(
Skyler Grey75ea9172022-08-06 10:22:23 +010091 "unmute",
92 after.guild.id,
93 after.user,
94 audit.executor,
95 null,
96 null,
97 null,
98 null
pineafan63fc5e22022-08-04 22:04:10 +010099 );
100 const data = {
pineafan73a7c4a2022-07-24 10:38:04 +0100101 meta: {
pineafan63fc5e22022-08-04 22:04:10 +0100102 type: "memberUnmute",
103 displayName: "Unmuted",
104 calculateType: "guildMemberPunish",
pineafan73a7c4a2022-07-24 10:38:04 +0100105 color: NucleusColors.green,
106 emoji: "PUNISH.MUTE.GREEN",
107 timestamp: new Date().getTime()
108 },
109 list: {
110 memberId: entry(after.id, `\`${after.id}\``),
111 name: entry(after.user.id, renderUser(after.user)),
Skyler Grey11236ba2022-08-08 21:13:33 +0100112 unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
113 unmutedBy: entry(audit.executor.id, renderUser(audit.executor))
pineafan73a7c4a2022-07-24 10:38:04 +0100114 },
115 hidden: {
116 guild: after.guild.id
117 }
pineafan63fc5e22022-08-04 22:04:10 +0100118 };
pineafan73a7c4a2022-07-24 10:38:04 +0100119 log(data);
Skyler Grey75ea9172022-08-06 10:22:23 +0100120 client.database.eventScheduler.cancel("naturalUnmute", {
121 guild: after.guild.id,
122 user: after.id,
123 expires: before.communicationDisabledUntilTimestamp
124 });
pineafane625d782022-05-09 18:04:32 +0100125 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100126 } catch (e) {
127 console.log(e);
128 }
pineafane625d782022-05-09 18:04:32 +0100129}