/[sudobot]/trunk/src/automod/Automute.ts
ViewVC logotype

Contents of /trunk/src/automod/Automute.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 393 - (show annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2793 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
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;
46 }
47
48 await this.mute(member);
49
50 this.client.logger.send(member.guild, {
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 }
67
68 public async onMemberLeave(member: GuildMember) {
69 const { MuteRecord } = this;
70
71 if (!member.roles.cache.has(this.client.config.props[member.guild.id].mute_role)) {
72 return;
73 }
74
75 const muteRecord = await MuteRecord.findOne({
76 user_id: member.user.id,
77 guild_id: member.guild.id
78 });
79
80 if (!muteRecord) {
81 await MuteRecord.create({
82 user_id: member.user.id,
83 guild_id: member.guild.id,
84 createdAt: new Date()
85 });
86 }
87 }
88 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26