diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-17 15:36:12 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-17 15:36:12 +0200 |
| commit | d135265798da8c2698f363237f4cb74b682f3f9e (patch) | |
| tree | bca914d297e74a6188478a773ba7333c10fe4a34 /cogs/vclogs.py | |
| parent | Merge branch 'main' of https://codeberg.org/salmonik/senator-sperma (diff) | |
| download | senator-sperma-d135265798da8c2698f363237f4cb74b682f3f9e.tar.gz senator-sperma-d135265798da8c2698f363237f4cb74b682f3f9e.zip | |
make voice great again
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to 'cogs/vclogs.py')
| -rw-r--r-- | cogs/vclogs.py | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 477aa1c..274d6ca 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -76,40 +76,41 @@ class VcLogs(commands.Cog): | |||
| 76 | tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}.mp3") | 76 | tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}.mp3") |
| 77 | tts = gTTS(text=text, lang='pl') | 77 | tts = gTTS(text=text, lang='pl') |
| 78 | logger.info("saving file") | 78 | logger.info("saving file") |
| 79 | tts.save(tts_file) | ||
| 80 | |||
| 81 | # Get voice status using our new method | ||
| 82 | voice_status = await voice_mgr.get_voice_status(channel.guild) | ||
| 83 | voice_client = voice_status[0] if voice_status else None | ||
| 84 | is_connected = voice_status[1] if voice_status else False | ||
| 85 | is_playing = voice_status[2] if voice_status else False | ||
| 86 | 79 | ||
| 87 | # Ensure we have a connected voice client | 80 | loop = asyncio.get_event_loop() |
| 88 | if not is_connected: | 81 | await loop.run_in_executor(None, tts.save, tts_file) |
| 89 | voice_client = await voice_mgr.join_channel(channel) | 82 | |
| 90 | # Update status after joining | 83 | try: |
| 91 | voice_status = await voice_mgr.get_voice_status(channel.guild) | 84 | voice_status = await voice_mgr.get_voice_status(channel.guild) |
| 92 | voice_client = voice_status[0] if voice_status else None | 85 | voice_client = voice_status[0] if voice_status else None |
| 93 | is_connected = voice_status[1] if voice_status else False | 86 | is_connected = voice_status[1] if voice_status else False |
| 94 | is_playing = voice_status[2] if voice_status else False | 87 | is_playing = voice_status[2] if voice_status else False |
| 95 | 88 | ||
| 96 | if not is_connected or voice_client is None: | 89 | if not is_connected: |
| 97 | logger.error("Failed to join voice channel") | 90 | voice_client = await voice_mgr.join_channel(channel) |
| 91 | voice_status = await voice_mgr.get_voice_status(channel.guild) | ||
| 92 | voice_client = voice_status[0] if voice_status else None | ||
| 93 | is_connected = voice_status[1] if voice_status else False | ||
| 94 | is_playing = voice_status[2] if voice_status else False | ||
| 95 | |||
| 96 | if not is_connected or voice_client is None: | ||
| 97 | logger.error("Failed to join voice channel") | ||
| 98 | return | ||
| 99 | |||
| 100 | volume = get_volume() | ||
| 101 | logger.info(f"connected: {voice_client}") | ||
| 102 | |||
| 103 | if voice_client and not is_playing: | ||
| 104 | logger.info("preparing to play audio") | ||
| 105 | audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') | ||
| 106 | voice_client.play(audio_source) | ||
| 107 | while voice_client.is_playing(): | ||
| 108 | await asyncio.sleep(0.5) | ||
| 109 | except Exception as e: | ||
| 110 | logger.error(f"TTS playback error: {e}") | ||
| 111 | finally: | ||
| 98 | if os.path.exists(tts_file): | 112 | if os.path.exists(tts_file): |
| 99 | os.remove(tts_file) | 113 | os.remove(tts_file) |
| 100 | return | ||
| 101 | |||
| 102 | volume = get_volume() | ||
| 103 | logger.info(f"connected: {voice_client}") | ||
| 104 | |||
| 105 | if voice_client and not is_playing: | ||
| 106 | logger.info("preparing to play audio") | ||
| 107 | audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') | ||
| 108 | voice_client.play(audio_source) | ||
| 109 | while voice_client.is_playing(): | ||
| 110 | await asyncio.sleep(0.5) | ||
| 111 | if os.path.exists(tts_file): | ||
| 112 | os.remove(tts_file) | ||
| 113 | 114 | ||
| 114 | @commands.slash_command( | 115 | @commands.slash_command( |
| 115 | name="log_volume" | 116 | name="log_volume" |
