Add warning task
This commit is contained in:
parent
3782cda364
commit
a87ec0adf0
1 changed files with 23 additions and 0 deletions
23
jarvis_tasks/tasks/warning.py
Normal file
23
jarvis_tasks/tasks/warning.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
"""JARVIS warnings tasks."""
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from dis_snek import Snake
|
||||
from jarvis_core.db import q
|
||||
from jarvis_core.db.models import Warning
|
||||
|
||||
|
||||
async def unwarn(bot: Snake) -> None:
|
||||
"""
|
||||
Deactivate warnings when they expire.
|
||||
|
||||
Args:
|
||||
bot: Snake instance
|
||||
"""
|
||||
while True:
|
||||
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()
|
Loading…
Add table
Reference in a new issue