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