1 |
import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js'; |
import { CommandInteraction, GuildMember, Message, Permissions, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import getUser from '../../utils/getUser'; |
|
|
import History from '../../automod/History'; |
|
7 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
8 |
import ms from 'ms'; |
import ms from 'ms'; |
|
import { unmute } from './UnmuteCommand'; |
|
9 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
10 |
|
import { hasPermission, shouldNotModerate } from '../../utils/util'; |
11 |
|
|
12 |
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, timeInterval: number | undefined, reason: string | undefined, hard: boolean = false) { |
13 |
try { |
try { |
35 |
} |
} |
36 |
|
|
37 |
if (dateTime && timeInterval) { |
if (dateTime && timeInterval) { |
38 |
await client.db.get("INSERT INTO unmutes(user_id, guild_id, time) VALUES(?, ?, ?)", [user.id, msg.guild!.id, new Date(dateTime).toISOString()], async (err: any) => { |
await setTimeoutv2('unmute-job', timeInterval, msg.guild!.id, `unmute ${user.id}`, msg.guild!.id, user.id); |
|
if (err) |
|
|
console.log(err); |
|
|
|
|
|
console.log('A timeout has been set.'); |
|
|
|
|
|
await setTimeoutv2('unmute-job', timeInterval, msg.guild!.id, `unmute ${user.id}`, msg.guild!.id, user.id); |
|
|
}); |
|
39 |
} |
} |
40 |
|
|
41 |
if (hard) { |
if (hard) { |
47 |
user_id: user.id, |
user_id: user.id, |
48 |
roles: roles.map(role => role.id), |
roles: roles.map(role => role.id), |
49 |
guild_id: msg.guild!.id, |
guild_id: msg.guild!.id, |
50 |
|
createdAt: new Date() |
51 |
}); |
}); |
52 |
} |
} |
53 |
|
|
63 |
reason, |
reason, |
64 |
meta: { |
meta: { |
65 |
time: timeInterval ? ms(timeInterval) : undefined |
time: timeInterval ? ms(timeInterval) : undefined |
66 |
} |
}, |
67 |
|
createdAt: new Date() |
68 |
}); |
}); |
69 |
|
|
70 |
await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User, hard); |
await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User, hard); |
71 |
await user.send({ |
|
72 |
embeds: [ |
try { |
73 |
new MessageEmbed() |
await user.send({ |
74 |
.setAuthor({ |
embeds: [ |
75 |
iconURL: <string> msg.guild!.iconURL(), |
new MessageEmbed() |
76 |
name: `\tYou have been muted in ${msg.guild!.name}` |
.setAuthor({ |
77 |
}) |
iconURL: <string> msg.guild!.iconURL(), |
78 |
.addField("Reason", reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason) |
name: `\tYou have been muted in ${msg.guild!.name}` |
79 |
] |
}) |
80 |
}); |
.addField("Reason", reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason) |
81 |
|
] |
82 |
|
}); |
83 |
|
} |
84 |
|
catch (e) { |
85 |
|
console.log(e); |
86 |
|
} |
87 |
} |
} |
88 |
catch (e) { |
catch (e) { |
89 |
console.log(e); |
console.log(e); |
111 |
|
|
112 |
export default class MuteCommand extends BaseCommand { |
export default class MuteCommand extends BaseCommand { |
113 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
114 |
|
permissions = [Permissions.FLAGS.MODERATE_MEMBERS]; |
115 |
|
|
116 |
constructor() { |
constructor() { |
117 |
super('mute', 'moderation', []); |
super('mute', 'moderation', []); |
233 |
dateTime = Date.now() + timeInterval; |
dateTime = Date.now() + timeInterval; |
234 |
} |
} |
235 |
|
|
236 |
|
if (!(await hasPermission(client, user, msg, null, "You don't have permission to mute this user."))) { |
237 |
|
return; |
238 |
|
} |
239 |
|
|
240 |
|
if (shouldNotModerate(client, user)) { |
241 |
|
await msg.reply({ |
242 |
|
embeds: [ |
243 |
|
{ |
244 |
|
description: "This user cannot be muted." |
245 |
|
} |
246 |
|
] |
247 |
|
}); |
248 |
|
|
249 |
|
return; |
250 |
|
} |
251 |
|
|
252 |
await mute(client, dateTime, user, msg, timeInterval, reason, hard); |
await mute(client, dateTime, user, msg, timeInterval, reason, hard); |
253 |
|
|
254 |
const fields = [ |
const fields = [ |
284 |
] |
] |
285 |
}); |
}); |
286 |
} |
} |
|
} |
|
287 |
|
} |