From 01102088cc98b25b9ad01d192f57468b4a782c53 Mon Sep 17 00:00:00 2001 From: Alexander Terry Date: Thu, 5 Oct 2023 21:34:38 -0800 Subject: [PATCH] better sleep handling --- alexBot/cogs/voiceCommands.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/alexBot/cogs/voiceCommands.py b/alexBot/cogs/voiceCommands.py index a155037..4845538 100644 --- a/alexBot/cogs/voiceCommands.py +++ b/alexBot/cogs/voiceCommands.py @@ -366,29 +366,30 @@ async def vcShake(self, interaction: discord.Interaction, target: str): async def sleep(self, interaction: discord.Interaction): # deafen everyone in the channel, and mute people who req to be muted via userconfig if interaction.user.voice is None: - return await interaction.followup.send("you're not in a voice channel", ephemeral=True) - await interaction.response.defer(thinking=True) + return await interaction.response.send_message("you're not in a voice channel", ephemeral=True) vc = interaction.user.voice.channel if vc is None: # this should never happen tbh - return await interaction.followup.send("you're not in a voice channel", ephemeral=True) + return await interaction.response.send_message("you're not in a voice channel", ephemeral=True) + await interaction.response.defer(thinking=True) async with async_session() as session: uds = await session.scalars(select(UserConfig).where(UserConfig.userId.in_([z.id for z in vc.members]))) for user in vc.members: - await user.edit(deafen=True) # get the user config for this user ud = next((x for x in uds if x.userId == user.id), None) if not ud: ud = UserConfig(user.id) - if ud.voiceSleepMute: - await user.edit(deafen=True, mute=True) - if ud.dontVoiceSleep: - if ud.voiceSleepMute: - await user.edit(deafen=False, mute=True) - - else: - await user.edit(deafen=True, mute=False) - await interaction.followup.send("ok, sleep well :zzz:", ephemeral=True) + + if ud.voiceSleepMute and ud.dontVoiceSleep: + await user.edit(reason=f"sleep requested by {interaction.user}", mute=True) + elif ud.voiceSleepMute and not ud.dontVoiceSleep: + await user.edit(reason=f"sleep requested by {interaction.user}", mute=True, deafen=True) + elif not ud.voiceSleepMute and ud.dontVoiceSleep: + await user.edit(reason=f"sleep requested by {interaction.user}", deafen=True) + elif not ud.voiceSleepMute and not ud.dontVoiceSleep: + pass # do nothing + + await interaction.followup.send("ok, sleep well :zzz:", ephemeral=False) async def setup(bot):