1 |
import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js'; |
/** |
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 { CommandInteraction, GuildMember, Message, Permissions, User } from 'discord.js'; |
21 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
22 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
23 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
24 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
25 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import getUser from '../../utils/getUser'; |
|
|
import History from '../../automod/History'; |
|
26 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
|
import ms from 'ms'; |
|
27 |
|
|
28 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
29 |
|
import UnmuteQueue from '../../queues/UnmuteQueue'; |
30 |
|
|
31 |
export async function unmute(client: DiscordClient, user: GuildMember, msg: Message | CommandInteraction, d: User) { |
export async function unmute(client: DiscordClient, user: GuildMember, d: User) { |
32 |
try { |
try { |
33 |
await History.create(user.id, msg.guild!, 'unmute', msg.member!.user.id, null); |
const role = await user.guild!.roles.fetch(client.config.props[user.guild.id].mute_role); |
34 |
|
try { |
35 |
const role = await msg.guild!.roles.fetch(client.config.get('mute_role')); |
await user.roles.remove(role!, 'Unmuting user'); |
36 |
await user.roles.remove(role!); |
console.log("did that"); |
37 |
|
} |
38 |
|
catch (e) { |
39 |
|
console.log(e); |
40 |
|
} |
41 |
|
|
42 |
const { default: Punishment } = await import('../../models/Punishment'); |
const { default: Punishment } = await import('../../models/Punishment'); |
43 |
|
|
44 |
|
const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout'); |
45 |
|
|
46 |
|
const { default: Hardmute } = await import("../../models/Hardmute"); |
47 |
|
const { default: MuteRecord } = await import("../../models/MuteRecord"); |
48 |
|
|
49 |
|
const hardmute = await Hardmute.findOne({ |
50 |
|
user_id: user.id, |
51 |
|
guild_id: user.guild.id |
52 |
|
}); |
53 |
|
|
54 |
|
if (hardmute) { |
55 |
|
for await (const roleID of hardmute.roles) { |
56 |
|
try { |
57 |
|
const role = await user.guild.roles.fetch(roleID); |
58 |
|
|
59 |
|
if (role) { |
60 |
|
await user.roles.add(role, 'Adding the roles which were removed due to hardmute'); |
61 |
|
} |
62 |
|
} |
63 |
|
catch (e) { |
64 |
|
console.log(e); |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
|
await hardmute.delete(); |
69 |
|
} |
70 |
|
|
71 |
|
// const timeouts = getTimeouts(); |
72 |
|
|
73 |
|
// for (const timeout of timeouts.values()) { |
74 |
|
// if (timeout.row.params) { |
75 |
|
// try { |
76 |
|
// const json = JSON.parse(timeout.row.params); |
77 |
|
|
78 |
|
// if (json) { |
79 |
|
// if (json[1] === user.id && timeout.row.filePath.endsWith('unmute-job')) { |
80 |
|
// await clearTimeoutv2(timeout); |
81 |
|
// } |
82 |
|
// } |
83 |
|
// } |
84 |
|
// catch (e) { |
85 |
|
// console.log(e); |
86 |
|
// } |
87 |
|
// } |
88 |
|
// } |
89 |
|
|
90 |
|
for await (const queue of client.queueManager.queues.values()) { |
91 |
|
if (queue instanceof UnmuteQueue && queue.data!.memberID === user.id && queue.data!.guildID === user.guild!.id) { |
92 |
|
await queue.cancel(); |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
await Punishment.create({ |
await Punishment.create({ |
97 |
type: PunishmentType.UNMUTE, |
type: PunishmentType.UNMUTE, |
98 |
user_id: user.id, |
user_id: user.id, |
99 |
guild_id: msg.guild!.id, |
guild_id: user.guild!.id, |
100 |
mod_id: d.id, |
mod_id: d.id, |
101 |
mod_tag: d.tag, |
mod_tag: d.tag, |
102 |
|
createdAt: new Date() |
103 |
}); |
}); |
104 |
|
|
105 |
await user.send({ |
const muteRecord = await MuteRecord.findOne({ |
106 |
embeds: [ |
user_id: user.user.id, |
107 |
new MessageEmbed() |
guild_id: user.guild.id |
|
.setAuthor({ |
|
|
iconURL: <string> msg.guild!.iconURL(), |
|
|
name: `\tYou have been unmuted in ${msg.guild!.name}` |
|
|
}) |
|
|
] |
|
108 |
}); |
}); |
109 |
|
|
110 |
|
if (muteRecord) { |
111 |
|
await muteRecord.delete(); |
112 |
|
} |
113 |
|
|
114 |
|
try { |
115 |
|
await user.send({ |
116 |
|
embeds: [ |
117 |
|
new MessageEmbed() |
118 |
|
.setAuthor({ |
119 |
|
iconURL: <string> user.guild!.iconURL(), |
120 |
|
name: `\tYou have been unmuted in ${user.guild!.name}` |
121 |
|
}) |
122 |
|
] |
123 |
|
}); |
124 |
|
} |
125 |
|
catch (e) { |
126 |
|
console.log(e); |
127 |
|
} |
128 |
|
|
129 |
await client.logger.logUnmute(user, d); |
await client.logger.logUnmute(user, d); |
130 |
} |
} |
131 |
catch (e) { |
catch (e) { |
135 |
|
|
136 |
export default class UnmuteCommand extends BaseCommand { |
export default class UnmuteCommand extends BaseCommand { |
137 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
138 |
|
permissions = [Permissions.FLAGS.MODERATE_MEMBERS]; |
139 |
|
|
140 |
constructor() { |
constructor() { |
141 |
super('unmute', 'moderation', []); |
super('unmute', 'moderation', []); |
154 |
return; |
return; |
155 |
} |
} |
156 |
|
|
157 |
|
if (msg instanceof CommandInteraction) |
158 |
|
await msg.deferReply(); |
159 |
|
|
160 |
let user: GuildMember; |
let user: GuildMember; |
161 |
|
|
162 |
if (options.isInteraction) { |
if (options.isInteraction) { |
163 |
user = await <GuildMember> options.options.getMember('member'); |
user = await <GuildMember> options.options.getMember('member'); |
164 |
|
|
165 |
if (!user) { |
if (!user) { |
166 |
await msg.reply({ |
await this.deferReply(msg, { |
167 |
embeds: [ |
embeds: [ |
168 |
new MessageEmbed() |
new MessageEmbed() |
169 |
.setColor('#f14a60') |
.setColor('#f14a60') |
185 |
user = user2; |
user = user2; |
186 |
} |
} |
187 |
catch (e) { |
catch (e) { |
188 |
await msg.reply({ |
await this.deferReply(msg, { |
189 |
embeds: [ |
embeds: [ |
190 |
new MessageEmbed() |
new MessageEmbed() |
191 |
.setColor('#f14a60') |
.setColor('#f14a60') |
199 |
console.log(user); |
console.log(user); |
200 |
} |
} |
201 |
|
|
202 |
await unmute(client, user, msg, msg.member!.user as User); |
await unmute(client, user, msg.member!.user as User); |
203 |
|
|
204 |
await msg.reply({ |
await this.deferReply(msg, { |
205 |
embeds: [ |
embeds: [ |
206 |
new MessageEmbed() |
new MessageEmbed() |
207 |
.setAuthor({ |
.setAuthor({ |
218 |
] |
] |
219 |
}); |
}); |
220 |
} |
} |
|
} |
|
221 |
|
} |