25 lines
688 B
Python
25 lines
688 B
Python
"""JARVIS warnings tasks."""
|
|
import asyncio
|
|
from datetime import datetime, timedelta
|
|
from logging import Logger
|
|
|
|
from dis_snek import Snake
|
|
from jarvis_core.db import q
|
|
from jarvis_core.db.models import Warning
|
|
|
|
|
|
async def unwarn(bot: Snake, logger: Logger) -> None:
|
|
"""
|
|
Deactivate warnings when they expire.
|
|
|
|
Args:
|
|
bot: Snake instance
|
|
logger: Global logger
|
|
"""
|
|
while True:
|
|
await asyncio.sleep(3600)
|
|
warns = Warning.find(q(active=True))
|
|
async for warn in warns:
|
|
if warn.created_at + timedelta(hours=warn.duration) < datetime.utcnow():
|
|
warn.update(q(active=False))
|
|
await warn.commit()
|