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

Contents of /branches/4.x/src/automod/Automute.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 2839 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-2022 OSN Inc.
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 { GuildMember } from "discord.js";
21 import DiscordClient from "../client/Client";
22 import MessageEmbed from "../client/MessageEmbed";
23 import Service from "../utils/structures/Service";
24
25 export default class Automute extends Service {
26 MuteRecord: typeof import("../models/MuteRecord").default;
27
28 constructor(client: DiscordClient) {
29 super(client);
30 this.MuteRecord = require("../models/MuteRecord").default;
31 }
32
33 public async mute(member: GuildMember) {
34 await member.roles.add(this.client.config.props[member.guild.id].mute_role);
35 }
36
37 public async onMemberJoin(member: GuildMember) {
38 const { MuteRecord } = this;
39 const muteRecord = await MuteRecord.findOne({
40 user_id: member.user.id,
41 guild_id: member.guild.id
42 });
43
44 if (!muteRecord) {
45 return true;
46 }
47
48 await this.mute(member);
49
50 this.client.logger.loggingChannel(member.guild.id)?.send({
51 embeds: [
52 new MessageEmbed({
53 author: {
54 name: member.user.tag,
55 iconURL: member.user.displayAvatarURL(),
56 },
57 description: 'This user had left the server when they were muted. They\'ve been muted again.',
58 color: 'GOLD',
59 footer: { text: 'Auto Mute' }
60 })
61 .setTimestamp()
62 ]
63 });
64
65 await muteRecord.delete();
66 return false;
67 }
68
69 public async onMemberLeave(member: GuildMember) {
70 const { MuteRecord } = this;
71
72 if (!member.roles.cache.has(this.client.config.props[member.guild.id].mute_role)) {
73 return;
74 }
75
76 const muteRecord = await MuteRecord.findOne({
77 user_id: member.user.id,
78 guild_id: member.guild.id
79 });
80
81 if (!muteRecord) {
82 await MuteRecord.create({
83 user_id: member.user.id,
84 guild_id: member.guild.id,
85 createdAt: new Date()
86 });
87 }
88 }
89 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26