Remove unmute task

This commit is contained in:
Zeva Rose 2022-02-02 19:54:09 -07:00
parent 97c83aa370
commit ab0e24129d
2 changed files with 1 additions and 29 deletions

View file

@ -1,10 +1,9 @@
"""J.A.R.V.I.S. background task handlers.""" """J.A.R.V.I.S. background task handlers."""
from jarvis.tasks import unban, unlock, unmute, unwarn from jarvis.tasks import unban, unlock, unwarn
def init() -> None: def init() -> None:
"""Start the background task handlers.""" """Start the background task handlers."""
unban.unban.start() unban.unban.start()
unlock.unlock.start() unlock.unlock.start()
unmute.unmute.start()
unwarn.unwarn.start() unwarn.unwarn.start()

View file

@ -1,27 +0,0 @@
"""J.A.R.V.I.S. unmute background task handler."""
from datetime import datetime, timedelta
from discord.ext.tasks import loop
import jarvis
from jarvis.db.models import Mute, Setting
@loop(minutes=1)
async def unmute() -> None:
"""J.A.R.V.I.S. unmute background task."""
mutes = Mute.objects(duration__gt=0, active=True)
mute_roles = Setting.objects(setting="mute")
for mute in mutes:
if mute.created_at + timedelta(minutes=mute.duration) < datetime.utcnow():
mute_role = [x.value for x in mute_roles if x.guild == mute.guild][0]
guild = await jarvis.jarvis.fetch_guild(mute.guild)
role = guild.get_role(mute_role)
user = await guild.fetch_member(mute.user)
if user:
if role in user.roles:
await user.remove_roles(role, reason="Mute expired")
# Objects can't handle bulk_write, so handle it via raw methods
mute.active = False
mute.save