/[sudobot]/branches/2.x/src/automod/Automute.ts
ViewVC logotype

Annotation of /branches/2.x/src/automod/Automute.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: 2076 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 import { GuildMember } from "discord.js";
2     import DiscordClient from "../client/Client";
3     import MessageEmbed from "../client/MessageEmbed";
4     import Service from "../utils/structures/Service";
5    
6     export default class Automute extends Service {
7     MuteRecord: any;
8    
9     constructor(client: DiscordClient) {
10     super(client);
11     this.MuteRecord = require("../models/MuteRecord").default;
12     }
13    
14     public async mute(member: GuildMember) {
15     await member.roles.add(this.client.config.props[member.guild.id].mute_role);
16     }
17    
18     public async onMemberJoin(member: GuildMember) {
19     const { MuteRecord } = this;
20     const muteRecord = await MuteRecord.findOne({
21     where: {
22     user_id: member.user.id,
23     guild_id: member.guild.id
24     }
25     });
26    
27     if (!muteRecord) {
28     return;
29     }
30    
31     await this.mute(member);
32    
33     this.client.logger.send(member.guild, {
34     embeds: [
35     new MessageEmbed({
36     author: {
37     name: member.user.tag,
38     iconURL: member.user.displayAvatarURL(),
39     },
40     description: 'This user had left the server when they were muted. They\'ve been muted again.',
41     color: 'GOLD',
42     footer: { text: 'Auto Mute' }
43     })
44     .setTimestamp()
45     ]
46     });
47    
48     await muteRecord.destroy();
49     }
50    
51     public async onMemberLeave(member: GuildMember) {
52     const { MuteRecord } = this;
53    
54     if (!member.roles.cache.has(this.client.config.props[member.guild.id].mute_role)) {
55     return;
56     }
57    
58     const muteRecord = await MuteRecord.findOne({
59     where: {
60     user_id: member.user.id,
61     guild_id: member.guild.id
62     }
63     });
64    
65     if (!muteRecord) {
66     await MuteRecord.create({
67     user_id: member.user.id,
68     guild_id: member.guild.id
69     });
70     }
71     }
72     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26