From f2ddb4ab665288ad9b65847503fff3bdfbc0bab5 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 9 Dec 2023 18:04:24 +0100 Subject: [PATCH] Only play entrance sound when other is present + reformat --- bot.py | 5 ++--- heidi_client.py | 23 +++++++++++++++++------ heidi_helpers.py | 25 +++++++++++++------------ 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/bot.py b/bot.py index 7c59959..3fa78ae 100644 --- a/bot.py +++ b/bot.py @@ -120,8 +120,7 @@ def user_entrance_sound_autocomplete( """ boards: List[str] = os.listdir(SOUNDDIR) all_sounds: Dict[str, List[str]] = { - board: os.listdir(f"{SOUNDDIR}/{board}/") - for board in boards + board: os.listdir(f"{SOUNDDIR}/{board}/") for board in boards } # These are all sounds, organized per board, without file extension # @todo Initially only suggest boards, because there are too many sounds to show them all @@ -191,7 +190,7 @@ async def heidi_exclaim(interaction: Interaction) -> None: "Jetzt sei doch mal sexy!", "Stell dich nicht so an!", "Models müssen da halt durch!", - "Heul doch nicht!" + "Heul doch nicht!", ] await interaction.response.send_message(random.choice(messages)) diff --git a/heidi_client.py b/heidi_client.py index c7d041c..df242e4 100644 --- a/heidi_client.py +++ b/heidi_client.py @@ -28,7 +28,7 @@ class HeidiClient(discord.Client): # lambda m: m.author.nick.lower() in self.models.get_in_names(): self.autoreact_to_girls, lambda m: "jeremy" in m.author.nick.lower(): self._autoreact_to_jeremy, lambda m: "kardashian" in m.author.nick.lower() - or "jenner" in m.author.nick.lower(): self._autoreact_to_kardashian, + or "jenner" in m.author.nick.lower(): self._autoreact_to_kardashian, } # automatic actions on voice state changes @@ -109,15 +109,26 @@ class HeidiClient(discord.Client): await message.add_reaction("💄") async def _play_entrance_sound( - self, - member: Member, - before: VoiceState, - after: VoiceState, + self, + member: Member, + before: VoiceState, + after: VoiceState, ) -> None: """ - Play a sound when a member joins a voice channel. + Play a sound when a member joins a voice channel (and another member is present). This function is set in on_voice_state_triggers and triggered by the on_voice_state_update event. """ + + # Don't play anything when no other users are present + if ( + member is not None + and member.voice is not None + and member.voice.channel is not None + and len(member.voice.channel.members) <= 1 + ): + print("Not playing entrance sound, as no other members are present") + return + soundpath: Union[str, None] = self.user_config["ENTRANCE.SOUND"].get( member.name, None ) diff --git a/heidi_helpers.py b/heidi_helpers.py index 8c817c3..7a81f03 100644 --- a/heidi_helpers.py +++ b/heidi_helpers.py @@ -8,12 +8,13 @@ from heidi_constants import * print("Debug: Importing heidi_helpers.py") + # @todo Normalize volume when playing async def play_voice_line( - interaction: Union[Interaction, None], - voice_channel: VoiceChannel, - board: str, - sound: str, + interaction: Union[Interaction, None], + voice_channel: VoiceChannel, + board: str, + sound: str, ) -> None: """ Play a voice line in the specified channel. @@ -44,20 +45,20 @@ async def play_voice_line( async def play_voice_line_for_member( - interaction: Union[Interaction, None], - member: Member, - board: str, - sound: str, + interaction: Union[Interaction, None], + member: Member, + board: str, + sound: str, ) -> None: """ Play a voice line in the member's current channel. """ # Member needs to be in voice channel to hear audio (Heidi needs to know the channel to join) if ( - member is None - or member.voice is None - or member.voice.channel is None - or not isinstance(member.voice.channel, VoiceChannel) + member is None + or member.voice is None + or member.voice.channel is None + or not isinstance(member.voice.channel, VoiceChannel) ): print("User not in (valid) voice channel!") if interaction is not None: