aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/moderation/management.py4
-rw-r--r--bot/cogs/moderation/scheduler.py4
-rw-r--r--bot/cogs/moderation/superstarify.py2
-rw-r--r--bot/cogs/reminders.py11
-rw-r--r--bot/utils/scheduling.py4
5 files changed, 9 insertions, 16 deletions
diff --git a/bot/cogs/moderation/management.py b/bot/cogs/moderation/management.py
index f2964cd78..279c8b809 100644
--- a/bot/cogs/moderation/management.py
+++ b/bot/cogs/moderation/management.py
@@ -1,4 +1,3 @@
-import asyncio
import logging
import textwrap
import typing as t
@@ -133,8 +132,7 @@ class ModManagement(commands.Cog):
# If the infraction was not marked as permanent, schedule a new expiration task
if request_data['expires_at']:
- loop = asyncio.get_event_loop()
- self.infractions_cog.schedule_task(loop, new_infraction['id'], new_infraction)
+ self.infractions_cog.schedule_task(new_infraction['id'], new_infraction)
log_text += f"""
Previous expiry: {old_infraction['expires_at'] or "Permanent"}
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py
index e14c302cb..62b040d1f 100644
--- a/bot/cogs/moderation/scheduler.py
+++ b/bot/cogs/moderation/scheduler.py
@@ -48,7 +48,7 @@ class InfractionScheduler(Scheduler):
)
for infraction in infractions:
if infraction["expires_at"] is not None and infraction["type"] in supported_infractions:
- self.schedule_task(self.bot.loop, infraction["id"], infraction)
+ self.schedule_task(infraction["id"], infraction)
async def reapply_infraction(
self,
@@ -150,7 +150,7 @@ class InfractionScheduler(Scheduler):
await action_coro
if expiry:
# Schedule the expiration of the infraction.
- self.schedule_task(ctx.bot.loop, infraction["id"], infraction)
+ self.schedule_task(infraction["id"], infraction)
except discord.HTTPException as e:
# Accordingly display that applying the infraction failed.
confirm_msg = f":x: failed to apply"
diff --git a/bot/cogs/moderation/superstarify.py b/bot/cogs/moderation/superstarify.py
index 050c847ac..d94ee6891 100644
--- a/bot/cogs/moderation/superstarify.py
+++ b/bot/cogs/moderation/superstarify.py
@@ -145,7 +145,7 @@ class Superstarify(InfractionScheduler, Cog):
log.debug(f"Changing nickname of {member} to {forced_nick}.")
self.mod_log.ignore(constants.Event.member_update, member.id)
await member.edit(nick=forced_nick, reason=reason)
- self.schedule_task(ctx.bot.loop, id_, infraction)
+ self.schedule_task(id_, infraction)
# Send a DM to the user to notify them of their new infraction.
await utils.notify_infraction(
diff --git a/bot/cogs/reminders.py b/bot/cogs/reminders.py
index 45bf9a8f4..d96dedd20 100644
--- a/bot/cogs/reminders.py
+++ b/bot/cogs/reminders.py
@@ -1,4 +1,3 @@
-import asyncio
import logging
import random
import textwrap
@@ -42,7 +41,6 @@ class Reminders(Scheduler, Cog):
)
now = datetime.utcnow()
- loop = asyncio.get_event_loop()
for reminder in response:
remind_at = datetime.fromisoformat(reminder['expiration'][:-1])
@@ -53,7 +51,7 @@ class Reminders(Scheduler, Cog):
await self.send_reminder(reminder, late)
else:
- self.schedule_task(loop, reminder["id"], reminder)
+ self.schedule_task(reminder["id"], reminder)
@staticmethod
async def _send_confirmation(ctx: Context, on_success: str) -> None:
@@ -88,10 +86,8 @@ class Reminders(Scheduler, Cog):
async def _reschedule_reminder(self, reminder: dict) -> None:
"""Reschedule a reminder object."""
- loop = asyncio.get_event_loop()
-
self.cancel_task(reminder["id"])
- self.schedule_task(loop, reminder["id"], reminder)
+ self.schedule_task(reminder["id"], reminder)
async def send_reminder(self, reminder: dict, late: relativedelta = None) -> None:
"""Send the reminder."""
@@ -185,8 +181,7 @@ class Reminders(Scheduler, Cog):
on_success=f"Your reminder will arrive in {humanize_delta(relativedelta(expiration, now))}!"
)
- loop = asyncio.get_event_loop()
- self.schedule_task(loop, reminder["id"], reminder)
+ self.schedule_task(reminder["id"], reminder)
@remind_group.command(name="list")
async def list_reminders(self, ctx: Context) -> Optional[Message]:
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
index adf10d683..a16900066 100644
--- a/bot/utils/scheduling.py
+++ b/bot/utils/scheduling.py
@@ -29,7 +29,7 @@ class Scheduler(metaclass=CogABCMeta):
then make a site API request to delete the reminder from the database.
"""
- def schedule_task(self, loop: asyncio.AbstractEventLoop, task_id: str, task_data: dict) -> None:
+ def schedule_task(self, task_id: str, task_data: dict) -> None:
"""
Schedules a task.
@@ -41,7 +41,7 @@ class Scheduler(metaclass=CogABCMeta):
)
return
- task = loop.create_task(self._scheduled_task(task_data))
+ task = asyncio.create_task(self._scheduled_task(task_data))
task.add_done_callback(_suppress_cancelled_error)
self.scheduled_tasks[task_id] = task