-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempCheck.js
33 lines (31 loc) · 1.18 KB
/
tempCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { moderations } = require("./db.js")
module.exports = (client) => {
const check = async () => {
let tempmutes = await moderations.find({action: "tempmute", active: true})
let tempbans = await moderations.find({action: "tempban", active: true})
tempmutes.forEach(mute => {
console.log(`Now checking ${mute.moderationId}. Expiration: ${mute.expiration}. Current time: ${Date.now()}`)
console.log(mute.expiration <= Date.now())
if (mute.expiration <= Date.now()) {
let target = client.guilds.resolve(mute.guild).members.resolve(mute.user)
mute.active = false
const returnroles = mute.previousroles
for (i=0; i<returnroles.length;i++){
target.roles.add(returnroles[i],"Tempmute end")
}
}
mute.save()
})
tempbans.forEach(ban => {
console.log(`Now checking ${ban.moderationId}. Expiration: ${ban.expiration}. Current time: ${Date.now()}`)
console.log(ban.expiration <= Date.now())
if (ban.expiration <= Date.now()) {
client.guilds.resolve(ban.guild).bans.remove(ban.user).catch(console.log)
ban.active = false
}
ban.save()
})
}
setInterval(check, 60000)
check()
}