aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2025-04-06 15:05:00 +0100
committerGravatar GitHub <[email protected]>2025-04-06 14:05:00 +0000
commit0d005e7bbfd52c802012e54709b0cbf64b7435e2 (patch)
treef5f8d5a839437ea7e6679d1a9f6486d54d046477
parentAllow moving the numbers elsewhere (diff)
Cleaner number move (#320)
* Use move_to for moving numbers * Stop transmitting numbers on exit
-rw-r--r--arthur/exts/fun/numbers.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/arthur/exts/fun/numbers.py b/arthur/exts/fun/numbers.py
index a4df5a8..10f4951 100644
--- a/arthur/exts/fun/numbers.py
+++ b/arthur/exts/fun/numbers.py
@@ -9,19 +9,23 @@ class Numbers(commands.GroupCog):
def __init__(self, bot: commands.Bot):
self.bot = bot
+ self.devops_vc: discord.VoiceChannel | discord.StageChannel | None = None
async def cog_load(self) -> None:
"""Join devops channel on cog load."""
devops_vc = self.bot.get_channel(CONFIG.devops_vc_id)
- await self._join_and_play_numbers(devops_vc) # type: ignore[union-attr]
+ if not isinstance(devops_vc, (discord.VoiceChannel, discord.StageChannel)):
+ return
- async def _join_and_play_numbers(
- self,
- channel: discord.VoiceChannel | discord.StageChannel,
- ) -> None:
- vc = await channel.connect(self_deaf=True, self_mute=False)
+ self.devops_vc = devops_vc
+ vc = await devops_vc.connect(self_deaf=True, self_mute=False)
vc.play(discord.FFmpegOpusAudio(CONFIG.numbers_url))
+ async def cog_unload(self) -> None:
+ """Disconnect from devops channel on cog unload."""
+ if self.devops_vc and (vc := self.devops_vc.guild.voice_client):
+ await vc.disconnect(force=True)
+
@commands.group(invoke_without_command=True)
async def numbers(
self,
@@ -44,9 +48,14 @@ class Numbers(commands.GroupCog):
return
if vc := ctx.guild.voice_client:
- await vc.disconnect(force=True)
+ # Should always be the case, but I wanted type hinting
+ if isinstance(vc, discord.VoiceClient):
+ await vc.move_to(channel)
+ await ctx.message.add_reaction("🔊")
+ return
- await self._join_and_play_numbers(channel)
+ vc = await channel.connect(self_deaf=True, self_mute=False)
+ vc.play(discord.FFmpegOpusAudio(CONFIG.numbers_url))
await ctx.message.add_reaction("🔊")
@numbers.command()