pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 1 | import { purgeByUser } from '../automations/tickets/delete.js'; |
| 2 | import { callback as statsChannelRemove } from '../automations/statsChannelRemove.js'; |
| 3 | |
| 4 | export const event = 'guildBanAdd'; |
| 5 | |
| 6 | export async function callback(client, ban) { |
| 7 | try { await statsChannelRemove(client, ban.user); } catch {} |
| 8 | try { purgeByUser(ban.user.id, ban.guild); } catch {} |
| 9 | try { |
| 10 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger |
| 11 | let auditLog = await getAuditLog(ban.guild, 'MEMBER_BAN_ADD') |
| 12 | let audit = auditLog.entries.filter(entry => entry.target.id == ban.user.id).first(); |
| 13 | if (audit.executor.id == client.user.id) return |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 14 | try { await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason) } catch {} |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 15 | let data = { |
| 16 | meta: { |
| 17 | type: 'memberBan', |
| 18 | displayName: 'Member Banned', |
| 19 | calculateType: 'guildMemberPunish', |
| 20 | color: NucleusColors.red, |
| 21 | emoji: "PUNISH.BAN.RED", |
| 22 | timestamp: new Date().getTime() |
| 23 | }, |
| 24 | list: { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame] | 25 | memberId: entry(ban.user.id, `\`${ban.user.id}\``), |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 26 | name: entry(ban.user.id, renderUser(ban.user)), |
| 27 | banned: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 28 | bannedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 29 | reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"), |
| 30 | accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)), |
| 31 | serverMemberCount: ban.guild.memberCount, |
| 32 | }, |
| 33 | hidden: { |
| 34 | guild: ban.guild.id |
| 35 | } |
| 36 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 37 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 38 | } catch {} |
| 39 | } |