aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-16 11:43:33 -0700
committerGravatar MarkKoz <[email protected]>2020-08-16 11:43:33 -0700
commit0a6415068b782d511cafa32002922061a61b9f67 (patch)
tree907a08b7863e78671748f61c90acc8669cdf4828
parentSilence: remove event and await _get_instance_vars_task directly (diff)
Silence: rename _get_instance_vars to _init_cog
It's a more accurate name since it also reschedules unsilences now.
-rw-r--r--bot/cogs/moderation/silence.py10
-rw-r--r--tests/bot/cogs/moderation/test_silence.py8
2 files changed, 9 insertions, 9 deletions
diff --git a/bot/cogs/moderation/silence.py b/bot/cogs/moderation/silence.py
index 4910c7009..de799f64f 100644
--- a/bot/cogs/moderation/silence.py
+++ b/bot/cogs/moderation/silence.py
@@ -71,10 +71,10 @@ class Silence(commands.Cog):
self.bot = bot
self.scheduler = Scheduler(self.__class__.__name__)
- self._get_instance_vars_task = self.bot.loop.create_task(self._get_instance_vars())
+ self._init_task = self.bot.loop.create_task(self._init_cog())
- async def _get_instance_vars(self) -> None:
- """Get instance variables after they're available to get from the guild."""
+ async def _init_cog(self) -> None:
+ """Set instance attributes once the guild is available and reschedule unsilences."""
await self.bot.wait_until_guild_available()
guild = self.bot.get_guild(Guild.id)
@@ -92,7 +92,7 @@ class Silence(commands.Cog):
Duration is capped at 15 minutes, passing forever makes the silence indefinite.
Indefinitely silenced channels get added to a notifier which posts notices every 15 minutes from the start.
"""
- await self._get_instance_vars_task
+ await self._init_task
log.debug(f"{ctx.author} is silencing channel #{ctx.channel}.")
if not await self._silence(ctx.channel, persistent=(duration is None), duration=duration):
@@ -117,7 +117,7 @@ class Silence(commands.Cog):
If the channel was silenced indefinitely, notifications for the channel will stop.
"""
- await self._get_instance_vars_task
+ await self._init_task
log.debug(f"Unsilencing channel #{ctx.channel} from {ctx.author}'s command.")
await self._unsilence_wrapper(ctx.channel)
diff --git a/tests/bot/cogs/moderation/test_silence.py b/tests/bot/cogs/moderation/test_silence.py
index ab3d0742a..7c6efbfe4 100644
--- a/tests/bot/cogs/moderation/test_silence.py
+++ b/tests/bot/cogs/moderation/test_silence.py
@@ -83,19 +83,19 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
async def test_instance_vars_got_guild(self):
"""Bot got guild after it became available."""
- await self.cog._get_instance_vars()
+ await self.cog._init_cog()
self.bot.wait_until_guild_available.assert_called_once()
self.bot.get_guild.assert_called_once_with(Guild.id)
async def test_instance_vars_got_role(self):
"""Got `Roles.verified` role from guild."""
- await self.cog._get_instance_vars()
+ await self.cog._init_cog()
guild = self.bot.get_guild()
guild.get_role.assert_called_once_with(Roles.verified)
async def test_instance_vars_got_channels(self):
"""Got channels from bot."""
- await self.cog._get_instance_vars()
+ await self.cog._init_cog()
self.bot.get_channel.called_once_with(Channels.mod_alerts)
self.bot.get_channel.called_once_with(Channels.mod_log)
@@ -104,7 +104,7 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
"""Notifier was started with channel."""
mod_log = MockTextChannel()
self.bot.get_channel.side_effect = (None, mod_log)
- await self.cog._get_instance_vars()
+ await self.cog._init_cog()
notifier.assert_called_once_with(mod_log)
self.bot.get_channel.side_effect = None