1 |
rakinar2 |
577 |
import { TextChannel } from "discord.js"; |
2 |
|
|
import DiscordClient from "../client/Client"; |
3 |
|
|
import { unmute } from "../commands/moderation/UnmuteCommand"; |
4 |
|
|
import MuteRecord from "../models/MuteRecord"; |
5 |
|
|
|
6 |
|
|
export default async function unmuteJob(client: DiscordClient, guild_id: string, user_id: string) { |
7 |
|
|
console.log('top-level'); |
8 |
|
|
|
9 |
|
|
const guild = await client.guilds.cache.get(guild_id); |
10 |
|
|
|
11 |
|
|
console.log(guild_id, user_id); |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
// await client.db.get("SELECT * FROM unmutes WHERE time = ?", [new Date(dateTime!).toISOString()], async (err: any, data: any) => { |
15 |
|
|
// if (err) |
16 |
|
|
// console.log(err); |
17 |
|
|
|
18 |
|
|
// if (data) { |
19 |
|
|
// await client.db.get('DELETE FROM unmutes WHERE id = ?', [data.id], async (err: any) => { |
20 |
|
|
// let guild = await client.guilds.cache.find(g => g.id === data.guild_id); |
21 |
|
|
// let member = await guild?.members.cache.find(m => m.id === data.user_id); |
22 |
|
|
|
23 |
|
|
// if (member) { |
24 |
|
|
// await unmute(client, member, client.user!); |
25 |
|
|
// await History.create(member.id, msg.guild!, 'unmute', client.user!.id, null); |
26 |
|
|
// } |
27 |
|
|
|
28 |
|
|
// console.log(data); |
29 |
|
|
// }); |
30 |
|
|
// } |
31 |
|
|
// }); |
32 |
|
|
|
33 |
|
|
if (guild) { |
34 |
|
|
console.log('here'); |
35 |
|
|
|
36 |
|
|
try { |
37 |
|
|
const member = await guild.members.fetch(user_id); |
38 |
|
|
|
39 |
|
|
if (member) { |
40 |
|
|
console.log('here2'); |
41 |
|
|
|
42 |
|
|
await unmute(client, member, client.user!); |
43 |
|
|
} |
44 |
|
|
else { |
45 |
|
|
throw new Error(); |
46 |
|
|
} |
47 |
|
|
} |
48 |
|
|
catch (e) { |
49 |
|
|
console.log(e); |
50 |
|
|
|
51 |
|
|
const muteRecord = await MuteRecord.findOne({ |
52 |
|
|
where: { |
53 |
|
|
user_id, |
54 |
|
|
guild_id |
55 |
|
|
} |
56 |
|
|
}); |
57 |
|
|
|
58 |
|
|
if (muteRecord) { |
59 |
|
|
await muteRecord.destroy(); |
60 |
|
|
} |
61 |
|
|
} |
62 |
|
|
} |
63 |
|
|
} |