diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-19 15:43:32 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-19 15:43:32 +0200 |
| commit | 1dcdbe3cf03ff16b3ff2e2e6d572e0b3c72c18c0 (patch) | |
| tree | f11dc45777d8b3c8ff0e2ca16be83f85b272bd48 /cogs/tts.py | |
| parent | test: add cron tests + improve existing tests (diff) | |
| download | senator-sperma-1dcdbe3cf03ff16b3ff2e2e6d572e0b3c72c18c0.tar.gz senator-sperma-1dcdbe3cf03ff16b3ff2e2e6d572e0b3c72c18c0.zip | |
refactor: simplify cogs, reduce complexity
- Remove unused imports and dead code
- Cleaner error handling
- Reduce cognitive complexity
Diffstat (limited to '')
| -rw-r--r-- | cogs/tts.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/cogs/tts.py b/cogs/tts.py index 3dc4c09..68eb27f 100644 --- a/cogs/tts.py +++ b/cogs/tts.py | |||
| @@ -54,19 +54,17 @@ class TTS(commands.Cog): | |||
| 54 | if not voice_client: | 54 | if not voice_client: |
| 55 | await ctx.respond("Failed to connect to voice channel", ephemeral=True) | 55 | await ctx.respond("Failed to connect to voice channel", ephemeral=True) |
| 56 | return | 56 | return |
| 57 | 57 | ||
| 58 | # Play the TTS audio with volume adjustment | 58 | if voice_client.is_playing(): |
| 59 | await ctx.respond("Audio is already playing, try again later", ephemeral=True) | ||
| 60 | return | ||
| 61 | |||
| 59 | audio_source = discord.FFmpegPCMAudio( | 62 | audio_source = discord.FFmpegPCMAudio( |
| 60 | temp_path, | 63 | temp_path, |
| 61 | options=f'-filter:a "volume={volume}"' | 64 | options=f'-filter:a "volume={volume}"' |
| 62 | ) | 65 | ) |
| 63 | voice_client.play(audio_source) | ||
| 64 | logger.info(f"Playing TTS: {text}") | 66 | logger.info(f"Playing TTS: {text}") |
| 65 | 67 | ||
| 66 | # Wait for the audio to finish playing | ||
| 67 | while voice_client.is_playing(): | ||
| 68 | await asyncio.sleep(0.1) | ||
| 69 | |||
| 70 | except Exception as e: | 68 | except Exception as e: |
| 71 | logger.error(f"Error in voice channel handling: {e}") | 69 | logger.error(f"Error in voice channel handling: {e}") |
| 72 | await ctx.respond("eror :c", ephemeral=True) | 70 | await ctx.respond("eror :c", ephemeral=True) |
