aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2020-11-24 20:36:48 +0300
committerGravatar Hassan Abouelela <[email protected]>2020-11-24 20:36:48 +0300
commitd2d7db69c4e54120d36146e2334f702f4259ed6b (patch)
tree15fb24bd4baf63a818d5ee29b7aeca8ccd29b8da
parentRefractors SendMessage Function (diff)
Moves VoiceChat Sync Out of Overwrites Function
VoiceChat sync only needs to be called when the command is invoked, instead of while updating permissions. Moved call to command function to reflect that, and fixed failing tests. Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r--bot/exts/moderation/silence.py11
-rw-r--r--tests/bot/exts/moderation/test_silence.py12
2 files changed, 14 insertions, 9 deletions
diff --git a/bot/exts/moderation/silence.py b/bot/exts/moderation/silence.py
index 7bc51ee93..64ffaa347 100644
--- a/bot/exts/moderation/silence.py
+++ b/bot/exts/moderation/silence.py
@@ -134,9 +134,10 @@ class Silence(commands.Cog):
await source_channel.send(source_reply)
# Reply to target channel
- if alert_target and source_channel != target_channel and source_channel != voice_chat:
- if isinstance(target_channel, VoiceChannel) and (voice_chat is not None or voice_chat != source_channel):
- await voice_chat.send(message.replace("current channel", target_channel.mention))
+ if alert_target and source_channel not in [target_channel, voice_chat]:
+ if isinstance(target_channel, VoiceChannel):
+ if voice_chat is not None:
+ await voice_chat.send(message.replace("current channel", target_channel.mention))
else:
await target_channel.send(message)
@@ -167,6 +168,9 @@ class Silence(commands.Cog):
await self.send_message(MSG_SILENCE_FAIL, ctx.channel, channel)
return
+ if isinstance(channel, VoiceChannel):
+ await self._force_voice_sync(channel, kick=kick)
+
await self._schedule_unsilence(ctx, channel, duration)
if duration is None:
@@ -244,7 +248,6 @@ class Silence(commands.Cog):
overwrite.update(connect=False)
await channel.set_permissions(self._verified_voice_role, overwrite=overwrite)
- await self._force_voice_sync(channel, kick=kick)
await self.previous_overwrites.set(channel.id, json.dumps(prev_overwrites))
diff --git a/tests/bot/exts/moderation/test_silence.py b/tests/bot/exts/moderation/test_silence.py
index 70678d207..aab607392 100644
--- a/tests/bot/exts/moderation/test_silence.py
+++ b/tests/bot/exts/moderation/test_silence.py
@@ -446,11 +446,13 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
async def test_sent_to_correct_channel(self):
"""Test function sends messages to the correct channels."""
text_channel = MockTextChannel()
+ voice_channel = MockVoiceChannel()
ctx = MockContext()
test_cases = (
(None, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
(text_channel, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
+ (voice_channel, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
(ctx.channel, silence.MSG_SILENCE_SUCCESS.format(duration=10)),
)
@@ -460,14 +462,14 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
await self.cog.silence.callback(self.cog, ctx, 10, False, channel=target)
if ctx.channel == target or target is None:
ctx.channel.send.assert_called_once_with(message)
+
else:
- ctx.channel.send.assert_called_once_with(
- message.replace("current channel", text_channel.mention)
- )
- target.send.assert_called_once_with(message)
+ ctx.channel.send.assert_called_once_with(message.replace("current channel", target.mention))
+ if isinstance(target, MockTextChannel):
+ target.send.assert_called_once_with(message)
ctx.channel.send.reset_mock()
- if target is not None:
+ if target is not None and isinstance(target, MockTextChannel):
target.send.reset_mock()
async def test_skipped_already_silenced(self):