From a2b5b10625126b7e98643af9fe40569c9e004047 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 18 Apr 2026 00:24:50 +0200 Subject: refactor + preparing bot for public use Signed-off-by: salmonik --- cogs/vclogs.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'cogs/vclogs.py') diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 274d6ca..397d296 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py @@ -69,14 +69,14 @@ class VcLogs(commands.Cog): return tts_text, channel async def play_tts(self, channel, text): + from cogs.utils.temp import get_temp_dir + voice_mgr = self.get_voice_manager() - - temp_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'temp') - os.makedirs(temp_dir, exist_ok=True) + temp_dir = get_temp_dir() tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}.mp3") tts = gTTS(text=text, lang='pl') logger.info("saving file") - + loop = asyncio.get_event_loop() await loop.run_in_executor(None, tts.save, tts_file) @@ -85,21 +85,21 @@ class VcLogs(commands.Cog): voice_client = voice_status[0] if voice_status else None is_connected = voice_status[1] if voice_status else False is_playing = voice_status[2] if voice_status else False - + if not is_connected: voice_client = await voice_mgr.join_channel(channel) voice_status = await voice_mgr.get_voice_status(channel.guild) voice_client = voice_status[0] if voice_status else None is_connected = voice_status[1] if voice_status else False is_playing = voice_status[2] if voice_status else False - + if not is_connected or voice_client is None: logger.error("Failed to join voice channel") return volume = get_volume() logger.info(f"connected: {voice_client}") - + if voice_client and not is_playing: logger.info("preparing to play audio") audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') @@ -118,7 +118,7 @@ class VcLogs(commands.Cog): async def volume(self, ctx: discord.ApplicationContext, volume: int): from cogs.utils.settings import get_settings settings = get_settings() - settings['volume'] = volume + settings.volume = volume await save_settings() await ctx.followup.send(f"Volume has been set to: {volume}") logger.info(f"Volume changed to: {volume}") @@ -159,17 +159,17 @@ class VcLogs(commands.Cog): elif before.channel is not None and after.channel is None: if user_id in activity_data: data = activity_data[user_id] - + if data.get('is_afk') and data.get('afk_start'): afk_duration = current_ts - data['afk_start'] data['total_afk'] += afk_duration elif data.get('active_start'): active_since_start = current_ts - data['active_start'] data['total_active'] += active_since_start - + active_str = format_duration(data['total_active']) afk_str = format_duration(data['total_afk']) - + message = ( f"[{current_time}] {member.name} rozłączył się z {before.channel.name}\n" f"Aktywny: {active_str} | AFK: {afk_str}" @@ -178,7 +178,7 @@ class VcLogs(commands.Cog): tts_channel = before.channel await log_channel.send(message) logger.info(f"User left voice channel: {message}") - + del activity_data[user_id] save_activity_data(activity_data) else: @@ -190,7 +190,7 @@ class VcLogs(commands.Cog): elif user_id in activity_data: data = activity_data[user_id] - + if data.get('is_afk') and not (after.self_mute or after.self_deaf): afk_duration = current_ts - data['afk_start'] data['total_afk'] += afk_duration @@ -198,7 +198,7 @@ class VcLogs(commands.Cog): data['is_afk'] = False data['active_start'] = current_ts save_activity_data(activity_data) - + afk_str = format_duration(afk_duration) if after.self_mute: @@ -219,7 +219,7 @@ class VcLogs(commands.Cog): data['is_afk'] = True data['active_start'] = None save_activity_data(activity_data) - + if after.self_mute: activity = "wyciszył" else: -- cgit v1.2.3