blob: 2175aaf5dc3a8e3ff3fa0c1f0195b7b1a39f1b9d [file] [log] [blame]
pineafane625d782022-05-09 18:04:32 +01001import { callback as statsChannelAdd } from '../automations/statsChannelAdd.js';
2import { callback as welcome } from '../automations/welcome.js';
3import log from '../utils/log.js';
4export const event = 'guildMemberUpdate'
5
6export 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;
pineafan4edb7762022-06-26 19:21:04 +010013 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 {}
pineafane625d782022-05-09 18:04:32 +010016 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: {
26 id: entry(after.id, `\`${after.id}\``),
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 }
pineafan4edb7762022-06-26 19:21:04 +010036 log(data);
pineafane625d782022-05-09 18:04:32 +010037 }
38 } catch (e) { console.log(e) }
39}