aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/vclogs.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cogs/vclogs.py30
1 files changed, 15 insertions, 15 deletions
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):
69 return tts_text, channel 69 return tts_text, channel
70 70
71 async def play_tts(self, channel, text): 71 async def play_tts(self, channel, text):
72 from cogs.utils.temp import get_temp_dir
73
72 voice_mgr = self.get_voice_manager() 74 voice_mgr = self.get_voice_manager()
73 75 temp_dir = get_temp_dir()
74 temp_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'temp')
75 os.makedirs(temp_dir, exist_ok=True)
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 79
80 loop = asyncio.get_event_loop() 80 loop = asyncio.get_event_loop()
81 await loop.run_in_executor(None, tts.save, tts_file) 81 await loop.run_in_executor(None, tts.save, tts_file)
82 82
@@ -85,21 +85,21 @@ class VcLogs(commands.Cog):
85 voice_client = voice_status[0] if voice_status else None 85 voice_client = voice_status[0] if voice_status else None
86 is_connected = voice_status[1] if voice_status else False 86 is_connected = voice_status[1] if voice_status else False
87 is_playing = voice_status[2] if voice_status else False 87 is_playing = voice_status[2] if voice_status else False
88 88
89 if not is_connected: 89 if not is_connected:
90 voice_client = await voice_mgr.join_channel(channel) 90 voice_client = await voice_mgr.join_channel(channel)
91 voice_status = await voice_mgr.get_voice_status(channel.guild) 91 voice_status = await voice_mgr.get_voice_status(channel.guild)
92 voice_client = voice_status[0] if voice_status else None 92 voice_client = voice_status[0] if voice_status else None
93 is_connected = voice_status[1] if voice_status else False 93 is_connected = voice_status[1] if voice_status else False
94 is_playing = voice_status[2] if voice_status else False 94 is_playing = voice_status[2] if voice_status else False
95 95
96 if not is_connected or voice_client is None: 96 if not is_connected or voice_client is None:
97 logger.error("Failed to join voice channel") 97 logger.error("Failed to join voice channel")
98 return 98 return
99 99
100 volume = get_volume() 100 volume = get_volume()
101 logger.info(f"connected: {voice_client}") 101 logger.info(f"connected: {voice_client}")
102 102
103 if voice_client and not is_playing: 103 if voice_client and not is_playing:
104 logger.info("preparing to play audio") 104 logger.info("preparing to play audio")
105 audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') 105 audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"')
@@ -118,7 +118,7 @@ class VcLogs(commands.Cog):
118 async def volume(self, ctx: discord.ApplicationContext, volume: int): 118 async def volume(self, ctx: discord.ApplicationContext, volume: int):
119 from cogs.utils.settings import get_settings 119 from cogs.utils.settings import get_settings
120 settings = get_settings() 120 settings = get_settings()
121 settings['volume'] = volume 121 settings.volume = volume
122 await save_settings() 122 await save_settings()
123 await ctx.followup.send(f"Volume has been set to: {volume}") 123 await ctx.followup.send(f"Volume has been set to: {volume}")
124 logger.info(f"Volume changed to: {volume}") 124 logger.info(f"Volume changed to: {volume}")
@@ -159,17 +159,17 @@ class VcLogs(commands.Cog):
159 elif before.channel is not None and after.channel is None: 159 elif before.channel is not None and after.channel is None:
160 if user_id in activity_data: 160 if user_id in activity_data:
161 data = activity_data[user_id] 161 data = activity_data[user_id]
162 162
163 if data.get('is_afk') and data.get('afk_start'): 163 if data.get('is_afk') and data.get('afk_start'):
164 afk_duration = current_ts - data['afk_start'] 164 afk_duration = current_ts - data['afk_start']
165 data['total_afk'] += afk_duration 165 data['total_afk'] += afk_duration
166 elif data.get('active_start'): 166 elif data.get('active_start'):
167 active_since_start = current_ts - data['active_start'] 167 active_since_start = current_ts - data['active_start']
168 data['total_active'] += active_since_start 168 data['total_active'] += active_since_start
169 169
170 active_str = format_duration(data['total_active']) 170 active_str = format_duration(data['total_active'])
171 afk_str = format_duration(data['total_afk']) 171 afk_str = format_duration(data['total_afk'])
172 172
173 message = ( 173 message = (
174 f"[{current_time}] {member.name} rozłączył się z {before.channel.name}\n" 174 f"[{current_time}] {member.name} rozłączył się z {before.channel.name}\n"
175 f"Aktywny: {active_str} | AFK: {afk_str}" 175 f"Aktywny: {active_str} | AFK: {afk_str}"
@@ -178,7 +178,7 @@ class VcLogs(commands.Cog):
178 tts_channel = before.channel 178 tts_channel = before.channel
179 await log_channel.send(message) 179 await log_channel.send(message)
180 logger.info(f"User left voice channel: {message}") 180 logger.info(f"User left voice channel: {message}")
181 181
182 del activity_data[user_id] 182 del activity_data[user_id]
183 save_activity_data(activity_data) 183 save_activity_data(activity_data)
184 else: 184 else:
@@ -190,7 +190,7 @@ class VcLogs(commands.Cog):
190 190
191 elif user_id in activity_data: 191 elif user_id in activity_data:
192 data = activity_data[user_id] 192 data = activity_data[user_id]
193 193
194 if data.get('is_afk') and not (after.self_mute or after.self_deaf): 194 if data.get('is_afk') and not (after.self_mute or after.self_deaf):
195 afk_duration = current_ts - data['afk_start'] 195 afk_duration = current_ts - data['afk_start']
196 data['total_afk'] += afk_duration 196 data['total_afk'] += afk_duration
@@ -198,7 +198,7 @@ class VcLogs(commands.Cog):
198 data['is_afk'] = False 198 data['is_afk'] = False
199 data['active_start'] = current_ts 199 data['active_start'] = current_ts
200 save_activity_data(activity_data) 200 save_activity_data(activity_data)
201 201
202 afk_str = format_duration(afk_duration) 202 afk_str = format_duration(afk_duration)
203 203
204 if after.self_mute: 204 if after.self_mute:
@@ -219,7 +219,7 @@ class VcLogs(commands.Cog):
219 data['is_afk'] = True 219 data['is_afk'] = True
220 data['active_start'] = None 220 data['active_start'] = None
221 save_activity_data(activity_data) 221 save_activity_data(activity_data)
222 222
223 if after.self_mute: 223 if after.self_mute:
224 activity = "wyciszył" 224 activity = "wyciszył"
225 else: 225 else: