Only play entrance sound when other is present + reformat
All checks were successful
Build Heidi Docker image / build-docker (push) Successful in 14s

This commit is contained in:
2023-12-09 18:04:24 +01:00
parent 876232f674
commit f2ddb4ab66
3 changed files with 32 additions and 21 deletions

5
bot.py
View File

@ -120,8 +120,7 @@ def user_entrance_sound_autocomplete(
""" """
boards: List[str] = os.listdir(SOUNDDIR) boards: List[str] = os.listdir(SOUNDDIR)
all_sounds: Dict[str, List[str]] = { all_sounds: Dict[str, List[str]] = {
board: os.listdir(f"{SOUNDDIR}/{board}/") board: os.listdir(f"{SOUNDDIR}/{board}/") for board in boards
for board in boards
} # These are all sounds, organized per board, without file extension } # 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 # @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!", "Jetzt sei doch mal sexy!",
"Stell dich nicht so an!", "Stell dich nicht so an!",
"Models müssen da halt durch!", "Models müssen da halt durch!",
"Heul doch nicht!" "Heul doch nicht!",
] ]
await interaction.response.send_message(random.choice(messages)) await interaction.response.send_message(random.choice(messages))

View File

@ -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: 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: "jeremy" in m.author.nick.lower(): self._autoreact_to_jeremy,
lambda m: "kardashian" in m.author.nick.lower() 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 # automatic actions on voice state changes
@ -109,15 +109,26 @@ class HeidiClient(discord.Client):
await message.add_reaction("💄") await message.add_reaction("💄")
async def _play_entrance_sound( async def _play_entrance_sound(
self, self,
member: Member, member: Member,
before: VoiceState, before: VoiceState,
after: VoiceState, after: VoiceState,
) -> None: ) -> 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. 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( soundpath: Union[str, None] = self.user_config["ENTRANCE.SOUND"].get(
member.name, None member.name, None
) )

View File

@ -8,12 +8,13 @@ from heidi_constants import *
print("Debug: Importing heidi_helpers.py") print("Debug: Importing heidi_helpers.py")
# @todo Normalize volume when playing # @todo Normalize volume when playing
async def play_voice_line( async def play_voice_line(
interaction: Union[Interaction, None], interaction: Union[Interaction, None],
voice_channel: VoiceChannel, voice_channel: VoiceChannel,
board: str, board: str,
sound: str, sound: str,
) -> None: ) -> None:
""" """
Play a voice line in the specified channel. Play a voice line in the specified channel.
@ -44,20 +45,20 @@ async def play_voice_line(
async def play_voice_line_for_member( async def play_voice_line_for_member(
interaction: Union[Interaction, None], interaction: Union[Interaction, None],
member: Member, member: Member,
board: str, board: str,
sound: str, sound: str,
) -> None: ) -> None:
""" """
Play a voice line in the member's current channel. 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) # Member needs to be in voice channel to hear audio (Heidi needs to know the channel to join)
if ( if (
member is None member is None
or member.voice is None or member.voice is None
or member.voice.channel is None or member.voice.channel is None
or not isinstance(member.voice.channel, VoiceChannel) or not isinstance(member.voice.channel, VoiceChannel)
): ):
print("User not in (valid) voice channel!") print("User not in (valid) voice channel!")
if interaction is not None: if interaction is not None: