/[sudobot]/branches/6.x/src/events/guildMember/GuildMemberRemoveEvent.ts
ViewVC logotype

Contents of /branches/6.x/src/events/guildMember/GuildMemberRemoveEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months, 1 week ago) by rakinar2
File MIME type: application/typescript
File size: 2688 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2023 OSN Developers.
5 *
6 * SudoBot is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SudoBot is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 import { InfractionType } from "@prisma/client";
21 import { AuditLogEvent, GuildMember } from "discord.js";
22 import EventListener from "../../core/EventListener";
23 import { Events } from "../../types/ClientEvents";
24 import { logError } from "../../utils/logger";
25
26 export default class GuildMemberRemoveEvent extends EventListener<Events.GuildMemberRemove> {
27 public readonly name = Events.GuildMemberRemove;
28
29 async execute(member: GuildMember) {
30 super.execute(member);
31 await this.client.logger.logGuildMemberRemove(member);
32
33 setTimeout(async () => {
34 try {
35 const auditLog = (
36 await member.guild.fetchAuditLogs({
37 limit: 1,
38 type: AuditLogEvent.MemberKick
39 })
40 ).entries.first();
41
42 if (
43 auditLog?.executor?.id &&
44 auditLog.executor.id !== this.client.user?.id &&
45 auditLog.targetId === member.user.id
46 ) {
47 const infraction = await this.client.prisma.infraction.create({
48 data: {
49 guildId: member.guild.id,
50 moderatorId: auditLog.executor.id,
51 type: InfractionType.KICK,
52 userId: member.user.id,
53 reason: auditLog.reason ?? undefined
54 }
55 });
56
57 await this.client.logger.logMemberKick({
58 moderator: auditLog.executor,
59 id: infraction.id.toString(),
60 reason: auditLog.reason ?? undefined,
61 guild: member.guild,
62 member
63 });
64 }
65 } catch (e) {
66 logError(e);
67 }
68 }, 2000);
69 }
70 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26