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