34 lines
991 B
Python
34 lines
991 B
Python
from datetime import datetime, timedelta
|
|
|
|
import pymongo
|
|
from discord.ext.tasks import loop
|
|
|
|
import jarvis
|
|
from jarvis.db.types import Ban
|
|
|
|
|
|
@loop(minutes=10)
|
|
async def unban():
|
|
bans = Ban.get_active(type="temp")
|
|
updates = []
|
|
for ban in bans:
|
|
if ban.created_at + timedelta(
|
|
hours=ban.duration
|
|
) < datetime.utcnow() + timedelta(minutes=10):
|
|
guild = await jarvis.jarvis.fetch_guild(ban.guild)
|
|
user = await jarvis.jarvis.fetch_user(ban.user)
|
|
if user:
|
|
guild.unban(user)
|
|
updates.append(
|
|
pymongo.UpdateOne(
|
|
{
|
|
"user": user.id,
|
|
"guild": guild.id,
|
|
"created_at": ban.created_at,
|
|
"type": "temp",
|
|
},
|
|
{"$set": {"active": False}},
|
|
)
|
|
)
|
|
if updates:
|
|
jarvis.jarvis_db.bans.bulk_write(updates)
|