17 |
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
*/ |
*/ |
19 |
|
|
20 |
import { CommandInteraction, GuildMember, Message, Permissions, User } from 'discord.js'; |
import { CommandInteraction, Guild, 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'; |
27 |
import ms from 'ms'; |
import ms from 'ms'; |
28 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
29 |
import { hasPermission, shouldNotModerate } from '../../utils/util'; |
import { hasPermission, shouldNotModerate } from '../../utils/util'; |
30 |
|
import UnmuteQueue from '../../queues/UnmuteQueue'; |
31 |
|
|
32 |
export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) { |
export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction | { guild: Guild, member: GuildMember, editReply?: undefined }, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) { |
33 |
try { |
try { |
34 |
const { default: Punishment } = await import('../../models/Punishment'); |
const { default: Punishment } = await import('../../models/Punishment'); |
35 |
|
|
55 |
} |
} |
56 |
|
|
57 |
if (dateTime && timeInterval) { |
if (dateTime && timeInterval) { |
58 |
await setTimeoutv2('unmute-job', timeInterval, msg.guild!.id, `unmute ${user.id}`, msg.guild!.id, user.id); |
// await setTimeoutv2('unmute-job', timeInterval, msg.guild!.id, `unmute ${user.id}`, msg.guild!.id, user.id); |
59 |
|
for await (const queue of client.queueManager.queues.values()) { |
60 |
|
if (queue instanceof UnmuteQueue && queue.data!.memberID === user.id && queue.data!.guildID === msg.guild!.id) { |
61 |
|
await queue.cancel(); |
62 |
|
} |
63 |
|
} |
64 |
|
|
65 |
|
await client.queueManager.addQueue(UnmuteQueue, { |
66 |
|
data: { |
67 |
|
guildID: msg.guild!.id, |
68 |
|
memberID: user.id |
69 |
|
}, |
70 |
|
runAt: new Date(Date.now() + timeInterval) |
71 |
|
}); |
72 |
} |
} |
73 |
|
|
74 |
if (hard) { |
if (hard) { |
84 |
}); |
}); |
85 |
} |
} |
86 |
|
|
87 |
const role = await msg.guild!.roles.fetch(client.config.get('mute_role')); |
const role = await msg.guild!.roles.fetch(client.config.props[msg.guild!.id].mute_role); |
88 |
await user.roles.add(role!, reason); |
await user.roles.add(role!, reason); |
89 |
|
|
90 |
await Punishment.create({ |
await Punishment.create({ |
129 |
.setDescription("Failed to assign the muted role to this user. Maybe missing permisions/roles or I'm not allowed to assign roles this user?") |
.setDescription("Failed to assign the muted role to this user. Maybe missing permisions/roles or I'm not allowed to assign roles this user?") |
130 |
] |
] |
131 |
}); |
}); |
132 |
else |
else if (msg.editReply) |
133 |
await msg.editReply({ |
await msg.editReply({ |
134 |
embeds: [ |
embeds: [ |
135 |
new MessageEmbed() |
new MessageEmbed() |