diff options
Diffstat (limited to 'cogs/vclogs.py')
| -rw-r--r-- | cogs/vclogs.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 397d296..fb0a2e0 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -14,9 +14,11 @@ from gtts import gTTS | |||
| 14 | from cogs.voice import get_voice_manager | 14 | from cogs.voice import get_voice_manager |
| 15 | from cogs.utils.settings import get_volume, save_settings | 15 | from cogs.utils.settings import get_volume, save_settings |
| 16 | 16 | ||
| 17 | import tempfile | ||
| 18 | |||
| 17 | logger = logging.getLogger(__name__) | 19 | logger = logging.getLogger(__name__) |
| 18 | 20 | ||
| 19 | ACTIVITY_FILE = 'temp/voice_activity.json' | 21 | ACTIVITY_FILE = os.path.join(tempfile.gettempdir(), 'voice_activity.json') |
| 20 | 22 | ||
| 21 | 23 | ||
| 22 | def load_activity_data(): | 24 | def load_activity_data(): |
| @@ -100,12 +102,20 @@ class VcLogs(commands.Cog): | |||
| 100 | volume = get_volume() | 102 | volume = get_volume() |
| 101 | logger.info(f"connected: {voice_client}") | 103 | logger.info(f"connected: {voice_client}") |
| 102 | 104 | ||
| 103 | if voice_client and not is_playing: | 105 | if voice_client: |
| 106 | if is_playing: | ||
| 107 | logger.info("voice already playing, stopping current audio") | ||
| 108 | voice_client.stop() | ||
| 109 | await asyncio.sleep(0.1) | ||
| 110 | |||
| 104 | logger.info("preparing to play audio") | 111 | logger.info("preparing to play audio") |
| 105 | audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') | 112 | audio_source = discord.FFmpegPCMAudio(tts_file) |
| 113 | if volume != 1.0: | ||
| 114 | audio_source = discord.PCMVolumeTransformer(audio_source) | ||
| 115 | audio_source.volume = volume | ||
| 106 | voice_client.play(audio_source) | 116 | voice_client.play(audio_source) |
| 107 | while voice_client.is_playing(): | 117 | while voice_client.is_playing(): |
| 108 | await asyncio.sleep(0.5) | 118 | await asyncio.sleep(0.1) |
| 109 | except Exception as e: | 119 | except Exception as e: |
| 110 | logger.error(f"TTS playback error: {e}") | 120 | logger.error(f"TTS playback error: {e}") |
| 111 | finally: | 121 | finally: |
| @@ -125,7 +135,16 @@ class VcLogs(commands.Cog): | |||
| 125 | 135 | ||
| 126 | @commands.Cog.listener() | 136 | @commands.Cog.listener() |
| 127 | async def on_voice_state_update(self, member, before, after): | 137 | async def on_voice_state_update(self, member, before, after): |
| 128 | log_channel = self.bot.get_channel(1213843195457183885) | 138 | log_channel_id = os.getenv("STATUS_CHANNEL_ID") |
| 139 | if not log_channel_id: | ||
| 140 | logger.warning("STATUS_CHANNEL_ID not set in environment") | ||
| 141 | return | ||
| 142 | |||
| 143 | log_channel = self.bot.get_channel(int(log_channel_id)) | ||
| 144 | if log_channel is None: | ||
| 145 | logger.warning("Log channel not found or not accessible") | ||
| 146 | return | ||
| 147 | |||
| 129 | current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | 148 | current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
| 130 | current_ts = datetime.datetime.now().timestamp() | 149 | current_ts = datetime.datetime.now().timestamp() |
| 131 | tts_text = None | 150 | tts_text = None |
