pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 1 | import humanizeDuration from 'humanize-duration'; |
| 2 | import { purgeByUser } from '../automations/tickets/delete.js'; |
| 3 | import { callback as statsChannelRemove } from '../automations/statsChannelRemove.js'; |
| 4 | |
| 5 | export const event = 'guildBanRemove'; |
| 6 | |
| 7 | export async function callback(client, ban) { |
| 8 | try { await statsChannelRemove(client, ban.user); } catch {} |
| 9 | try { purgeByUser(ban.user.id, ban.guild); } catch {} |
| 10 | try { |
| 11 | const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = ban.user.client.logger |
| 12 | let auditLog = await getAuditLog(ban.guild, 'MEMBER_BAN_REMOVE') |
| 13 | let audit = auditLog.entries.filter(entry => entry.target.id == ban.user.id).first(); |
| 14 | if (audit.executor.id == client.user.id) return |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 15 | try { await client.database.history.create("unban", ban.guild.id, ban.user, audit.executor, audit.reason) } catch {} |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 16 | let data = { |
| 17 | meta: { |
| 18 | type: 'memberUnban', |
| 19 | displayName: 'Member Unbanned', |
| 20 | calculateType: 'guildMemberPunish', |
| 21 | color: NucleusColors.green, |
| 22 | emoji: "PUNISH.BAN.GREEN", |
| 23 | timestamp: new Date().getTime() |
| 24 | }, |
| 25 | list: { |
| 26 | id: entry(ban.user.id, `\`${ban.user.id}\``), |
| 27 | name: entry(ban.user.id, renderUser(ban.user)), |
| 28 | unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 29 | unbannedBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 30 | accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)), |
| 31 | }, |
| 32 | hidden: { |
| 33 | guild: ban.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 | } catch (e) {console.log(e)} |
| 38 | } |