pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | export const event = "guildMemberUpdate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 2 | |
| 3 | export async function callback(client, before, after) { |
| 4 | try { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 5 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = after.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | const auditLog = await getAuditLog(after.guild, "MEMBER_UPDATE"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 7 | const audit = auditLog.entries.filter((entry) => entry.target.id === after.id).first(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 8 | if (audit.executor.id === client.user.id) return; |
| 9 | if (before.nickname !== after.nickname) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | await client.database.history.create( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 11 | "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 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 19 | const data = { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 20 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 21 | type: "memberUpdate", |
| 22 | displayName: "Nickname Changed", |
| 23 | calculateType: "guildMemberUpdate", |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 24 | color: NucleusColors.yellow, |
| 25 | emoji: "PUNISH.NICKNAME.YELLOW", |
| 26 | timestamp: new Date().getTime() |
| 27 | }, |
| 28 | list: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 29 | memberId: entry(after.id, `\`${after.id}\``), |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 30 | name: entry(after.user.id, renderUser(after.user)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 31 | 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)) |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 35 | }, |
| 36 | hidden: { |
| 37 | guild: after.guild.id |
| 38 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 39 | }; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 40 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 41 | } else if ( |
| 42 | before.communicationDisabledUntilTimestamp < new Date().getTime() && |
| 43 | after.communicationDisabledUntil > new Date().getTime() |
| 44 | ) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 45 | await client.database.history.create( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 46 | "mute", |
| 47 | after.guild.id, |
| 48 | after.user, |
| 49 | audit.executor, |
| 50 | audit.reason, |
| 51 | null, |
| 52 | null, |
| 53 | null |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 54 | ); |
| 55 | const data = { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 56 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 57 | type: "memberMute", |
| 58 | displayName: "Muted", |
| 59 | calculateType: "guildMemberPunish", |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 60 | 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 67 | mutedUntil: entry( |
| 68 | after.communicationDisabledUntilTimestamp, |
| 69 | renderDelta(after.communicationDisabledUntilTimestamp) |
| 70 | ), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 71 | 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*") |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 74 | }, |
| 75 | hidden: { |
| 76 | guild: after.guild.id |
| 77 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 78 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 79 | log(data); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 80 | client.database.eventScheduler.schedule("naturalUnmute", after.communicationDisabledUntil, { |
| 81 | guild: after.guild.id, |
| 82 | user: after.id, |
| 83 | expires: after.communicationDisabledUntilTimestamp |
| 84 | }); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 85 | } else if ( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 86 | after.communicationDisabledUntil === null && |
| 87 | before.communicationDisabledUntilTimestamp !== null && |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 88 | new Date().getTime() >= audit.createdTimestamp |
| 89 | ) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 90 | await client.database.history.create( |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 91 | "unmute", |
| 92 | after.guild.id, |
| 93 | after.user, |
| 94 | audit.executor, |
| 95 | null, |
| 96 | null, |
| 97 | null, |
| 98 | null |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 99 | ); |
| 100 | const data = { |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 101 | meta: { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 102 | type: "memberUnmute", |
| 103 | displayName: "Unmuted", |
| 104 | calculateType: "guildMemberPunish", |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 105 | 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 Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 112 | unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 113 | unmutedBy: entry(audit.executor.id, renderUser(audit.executor)) |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 114 | }, |
| 115 | hidden: { |
| 116 | guild: after.guild.id |
| 117 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 118 | }; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 119 | log(data); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 120 | client.database.eventScheduler.cancel("naturalUnmute", { |
| 121 | guild: after.guild.id, |
| 122 | user: after.id, |
| 123 | expires: before.communicationDisabledUntilTimestamp |
| 124 | }); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 125 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 126 | } catch (e) { |
| 127 | console.log(e); |
| 128 | } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 129 | } |