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

Annotation of /branches/2.x/src/events/guildMember/GuildMemberRemoveEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3120 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 import BaseEvent from '../../utils/structures/BaseEvent';
2     import DiscordClient from '../../client/Client';
3     import { GuildMember } from 'discord.js';
4     import UnverifiedMember from '../../models/UnverifiedMember';
5     import Punishment from '../../models/Punishment';
6     import PunishmentType from '../../types/PunishmentType';
7     import MessageEmbed from '../../client/MessageEmbed';
8    
9     export default class GuildMemberRemoveEvent extends BaseEvent {
10     constructor() {
11     super('guildMemberRemove');
12     }
13    
14     async run(client: DiscordClient, member: GuildMember) {
15     if (member.user.id === client.user!.id)
16     return;
17    
18     await client.logger.logLeft(member);
19    
20     if (member.user.bot)
21     return;
22    
23     const logs = (await member.guild.fetchAuditLogs({
24     limit: 1,
25     type: 'MEMBER_KICK',
26     })).entries.first();
27    
28     if (logs && logs.target?.id === member.id && logs.createdAt >= (member.joinedAt ?? 0)) {
29     console.log(logs?.executor);
30    
31     await Punishment.create({
32     type: PunishmentType.KICK,
33     user_id: member.user.id,
34     guild_id: member.guild!.id,
35     mod_id: logs?.executor?.id ?? client.user!.id,
36     mod_tag: logs?.executor?.tag ?? 'Unknown',
37     reason: logs.reason ?? undefined
38     });
39    
40     client.logger.log(member.guild, async channel => {
41     await channel.send({
42     embeds: [
43     new MessageEmbed({
44     author: {
45     name: member.user.tag,
46     iconURL: member.user.displayAvatarURL(),
47     },
48     title: 'Member Kicked',
49     description: 'This user has left the server, probably due to a kick.',
50     fields: [
51     {
52     name: 'Kicked by',
53     value: logs?.executor?.tag ?? 'Unknown'
54     },
55     {
56     name: 'Reason',
57     value: logs?.reason ?? '*No reason provided*'
58     }
59     ],
60     footer: {
61     text: 'Kicked'
62     }
63     })
64     .setTimestamp()
65     ]
66     });
67     });
68     }
69    
70     await client.autoClear.start(member, member.guild);
71    
72     const verificationData = await UnverifiedMember.findOne({
73     where: {
74     guild_id: member.guild.id,
75     user_id: member.id,
76     status: 'pending'
77     }
78     });
79    
80     if (verificationData) {
81     await verificationData.set('status', 'canceled');
82     await verificationData.save();
83     }
84    
85     await client.automute.onMemberLeave(member);
86     }
87     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26