pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 1 | import { callback as statsChannelAdd } from '../automations/statsChannelAdd.js'; |
| 2 | import { callback as welcome } from '../automations/welcome.js'; |
| 3 | import log from '../utils/log.js'; |
| 4 | export const event = 'guildMemberUpdate' |
| 5 | |
| 6 | export async function callback(client, before, after) { |
| 7 | try { |
| 8 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = after.client.logger |
| 9 | if (before.nickname != after.nickname) { |
| 10 | let auditLog = await getAuditLog(after.guild, 'MEMBER_UPDATE'); |
| 11 | let audit = auditLog.entries.filter(entry => entry.target.id == after.id).first(); |
| 12 | if (audit.executor.id == client.user.id) return; |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 13 | try { await client.database.history.create( |
| 14 | "nickname", after.guild.id, after.user, audit.executor, |
| 15 | null, before.nickname || before.user.username, after.nickname || after.user.username) } catch {} |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 16 | let data = { |
| 17 | meta: { |
| 18 | type: 'memberUpdate', |
| 19 | displayName: 'Nickname Changed', |
| 20 | calculateType: 'guildMemberUpdate', |
| 21 | color: NucleusColors.yellow, |
| 22 | emoji: "PUNISH.NICKNAME.YELLOW", |
| 23 | timestamp: new Date().getTime() |
| 24 | }, |
| 25 | list: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 26 | memberId: entry(after.id, `\`${after.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 27 | before: entry(before.nickname, before.nickname ? before.nickname : '*None*'), |
| 28 | after: entry(after.nickname, after.nickname ? after.nickname : '*None*'), |
| 29 | updated: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 30 | updatedBy: entry(audit.executor.id, renderUser(audit.executor)) |
| 31 | }, |
| 32 | hidden: { |
| 33 | guild: after.guild.id |
| 34 | } |
| 35 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 36 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | } |
| 38 | } catch (e) { console.log(e) } |
| 39 | } |