[Mod] Delegate send_to_owners call in initialize() to a task (#3573)

* fix(mod): delegate send_to_owners call in initialize() to a task

* enhance(mod): reorder cog's setup()
This commit is contained in:
jack1142 2020-02-19 08:12:50 +01:00 committed by GitHub
parent 9a8c134c97
commit 4956e67348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -4,5 +4,5 @@ from .mod import Mod
async def setup(bot: Red):
cog = Mod(bot)
await cog.initialize()
bot.add_cog(cog)
await cog.initialize()

View File

@ -1,6 +1,7 @@
import asyncio
from abc import ABC
from collections import defaultdict
from typing import List, Tuple
from abc import ABC
import discord
from redbot.core import Config, modlog, commands
@ -77,8 +78,14 @@ class Mod(
self.tban_expiry_task = self.bot.loop.create_task(self.check_tempban_expirations())
self.last_case: dict = defaultdict(dict)
self._ready = asyncio.Event()
async def initialize(self):
await self._maybe_update_config()
self._ready.set()
async def cog_before_invoke(self, ctx: commands.Context) -> None:
await self._ready.wait()
def cog_unload(self):
self.tban_expiry_task.cancel()
@ -102,7 +109,7 @@ class Mod(
"Please use `{prefix}moveignoredchannels` if "
"you were previously using these functions."
).format(prefix=prefixes[0])
await self.bot.send_to_owners(msg)
self.bot.loop.create_task(self.bot.send_to_owners(msg))
await self.settings.version.set(__version__)
@commands.command()