9 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
10 |
import ms from 'ms'; |
import ms from 'ms'; |
11 |
import { unmute } from './UnmuteCommand'; |
import { unmute } from './UnmuteCommand'; |
12 |
|
import PunishmentType from '../../types/PunishmentType'; |
13 |
|
|
14 |
export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined) { |
export async function mute(client: DiscordClient, dateTime: number | undefined, user: GuildMember, msg: Message | CommandInteraction, timeInterval: number | undefined, reason: string | undefined) { |
15 |
try { |
try { |
16 |
if (dateTime) { |
const { default: Punishment } = await import('../../models/Punishment'); |
17 |
|
|
18 |
|
const { getTimeouts, clearTimeoutv2, setTimeoutv2 } = await import('../../utils/setTimeout'); |
19 |
|
|
20 |
|
const timeouts = getTimeouts(); |
21 |
|
|
22 |
|
for (const timeout of timeouts.values()) { |
23 |
|
if (timeout.row.params) { |
24 |
|
try { |
25 |
|
const json = JSON.parse(timeout.row.params); |
26 |
|
|
27 |
|
if (json) { |
28 |
|
if (json[1] === user.id) { |
29 |
|
await clearTimeoutv2(timeout); |
30 |
|
} |
31 |
|
} |
32 |
|
} |
33 |
|
catch (e) { |
34 |
|
console.log(e); |
35 |
|
} |
36 |
|
} |
37 |
|
} |
38 |
|
|
39 |
|
if (dateTime && timeInterval) { |
40 |
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 client.db.get("INSERT INTO unmutes(user_id, guild_id, time) VALUES(?, ?, ?)", [user.id, msg.guild!.id, new Date(dateTime).toISOString()], async (err: any) => { |
41 |
if (err) |
if (err) |
42 |
console.log(err); |
console.log(err); |
43 |
|
|
44 |
console.log('A timeout has been set.'); |
console.log('A timeout has been set.'); |
45 |
|
|
46 |
setTimeout(async () => { |
await setTimeoutv2('unmute-job', timeInterval, msg.guild!.id, `unmute ${user.id}`, msg.guild!.id, user.id); |
|
await client.db.get("SELECT * FROM unmutes WHERE time = ?", [new Date(dateTime!).toISOString()], async (err: any, data: any) => { |
|
|
if (err) |
|
|
console.log(err); |
|
|
|
|
|
if (data) { |
|
|
await client.db.get('DELETE FROM unmutes WHERE id = ?', [data.id], async (err: any) => { |
|
|
let guild = await client.guilds.cache.find(g => g.id === data.guild_id); |
|
|
let member = await guild?.members.cache.find(m => m.id === data.user_id); |
|
|
|
|
|
if (member) { |
|
|
await unmute(client, member, msg, client.user!); |
|
|
await History.create(member.id, msg.guild!, 'unmute', client.user!.id, null); |
|
|
} |
|
|
|
|
|
console.log(data); |
|
|
}); |
|
|
} |
|
|
}); |
|
|
}, timeInterval); |
|
47 |
}); |
}); |
48 |
} |
} |
49 |
|
|
50 |
const role = await msg.guild!.roles.fetch(client.config.get('mute_role')); |
const role = await msg.guild!.roles.fetch(client.config.get('mute_role')); |
51 |
await user.roles.add(role!); |
await user.roles.add(role!); |
52 |
|
|
53 |
|
await Punishment.create({ |
54 |
|
type: PunishmentType.MUTE, |
55 |
|
user_id: user.id, |
56 |
|
guild_id: msg.guild!.id, |
57 |
|
mod_id: msg.member!.user.id, |
58 |
|
mod_tag: (msg.member!.user as User).tag, |
59 |
|
reason, |
60 |
|
meta: { |
61 |
|
time: timeInterval ? ms(timeInterval) : undefined |
62 |
|
} |
63 |
|
}); |
64 |
|
|
65 |
await History.create(user.id, msg.guild!, 'mute', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
await History.create(user.id, msg.guild!, 'mute', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
66 |
await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User); |
await client.logger.logMute(user, reason === undefined || reason.trim() === '' ? "*No reason provided*" : reason, timeInterval, msg.member!.user as User); |
67 |
await user.send({ |
await user.send({ |