diff options
Diffstat (limited to 'cogs/vclogs.py')
| -rw-r--r-- | cogs/vclogs.py | 83 |
1 files changed, 36 insertions, 47 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 0589364..f2efca7 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -54,36 +54,20 @@ class VcLogs(commands.Cog): | |||
| 54 | settings_file = 'settings.json' | 54 | settings_file = 'settings.json' |
| 55 | 55 | ||
| 56 | @staticmethod | 56 | @staticmethod |
| 57 | async def handle_state_change(member, channel, state_type, is_enabled, current_time, log_channel, activity_suffix=None): | 57 | async def handle_state_change(member, channel, state_type, is_enabled, log_channel): |
| 58 | """Helper method to handle voice state changes""" | 58 | """Helper method to handle voice state changes""" |
| 59 | state_messages = { | 59 | state_messages = { |
| 60 | 'deaf': { | 60 | 'deaf': { |
| 61 | True: ( | 61 | True: f"{member.display_name} jest bity przez ojca", |
| 62 | f"[{current_time}] {member.name} ogłuchnął się na {channel.name}", | 62 | False: f"{member.display_name} uciek od ojca" |
| 63 | f"{member.display_name} jest bity przez ojca" | ||
| 64 | ), | ||
| 65 | False: ( | ||
| 66 | f"[{current_time}] {member.name} odgłuchał się na {channel.name}", | ||
| 67 | f"{member.display_name} uciek od ojca" | ||
| 68 | ) | ||
| 69 | }, | 63 | }, |
| 70 | 'mute': { | 64 | 'mute': { |
| 71 | True: ( | 65 | True: f"{member.display_name} idzie robić jajecznice", |
| 72 | f"[{current_time}] {member.name} wyciszył się na {channel.name}", | 66 | False: f"{member.display_name} zrobił jajecznice" |
| 73 | f"{member.display_name} idzie robić jajecznice" | ||
| 74 | ), | ||
| 75 | False: ( | ||
| 76 | f"[{current_time}] {member.name} odciszył się na {channel.name}", | ||
| 77 | f"{member.display_name} zrobił jajecznice" | ||
| 78 | ) | ||
| 79 | } | 67 | } |
| 80 | } | 68 | } |
| 81 | 69 | ||
| 82 | message, tts_text = state_messages[state_type][is_enabled] | 70 | tts_text = state_messages[state_type][is_enabled] |
| 83 | if activity_suffix: | ||
| 84 | message = f"{message}\n{activity_suffix}" | ||
| 85 | await log_channel.send(message) | ||
| 86 | logger.info(f"Voice state change: {message}") | ||
| 87 | return tts_text, channel | 71 | return tts_text, channel |
| 88 | 72 | ||
| 89 | async def play_tts(self, channel, text): | 73 | async def play_tts(self, channel, text): |
| @@ -96,14 +80,15 @@ class VcLogs(commands.Cog): | |||
| 96 | logger.info("saving file") | 80 | logger.info("saving file") |
| 97 | tts.save(tts_file) | 81 | tts.save(tts_file) |
| 98 | 82 | ||
| 83 | voice_client = await voice_mgr.get_voice_client(channel.guild) | ||
| 84 | volume = 1.0 | ||
| 85 | |||
| 99 | if os.path.exists(VcLogs.settings_file): | 86 | if os.path.exists(VcLogs.settings_file): |
| 100 | async with aiofiles.open(VcLogs.settings_file) as f: | 87 | async with aiofiles.open(VcLogs.settings_file) as f: |
| 101 | content = await f.read() | 88 | content = await f.read() |
| 102 | data = json.loads(content) | 89 | data = json.loads(content) |
| 103 | volume = data.get('volume', 1.0) | 90 | volume = data.get('volume', 1.0) |
| 104 | 91 | ||
| 105 | voice_client = await voice_mgr.get_voice_client(channel.guild) | ||
| 106 | |||
| 107 | if voice_client is None: | 92 | if voice_client is None: |
| 108 | voice_client = await voice_mgr.join_channel(channel) | 93 | voice_client = await voice_mgr.join_channel(channel) |
| 109 | 94 | ||
| @@ -180,7 +165,7 @@ class VcLogs(commands.Cog): | |||
| 180 | 165 | ||
| 181 | message = ( | 166 | message = ( |
| 182 | f"[{current_time}] {member.name} rozłączył się z {before.channel.name}\n" | 167 | f"[{current_time}] {member.name} rozłączył się z {before.channel.name}\n" |
| 183 | f" Aktywny: {active_str} | AFK: {afk_str}" | 168 | f"Aktywny: {active_str} | AFK: {afk_str}" |
| 184 | ) | 169 | ) |
| 185 | tts_text = f"{member.display_name} jest chujem" | 170 | tts_text = f"{member.display_name} jest chujem" |
| 186 | tts_channel = before.channel | 171 | tts_channel = before.channel |
| @@ -206,7 +191,20 @@ class VcLogs(commands.Cog): | |||
| 206 | data['is_afk'] = False | 191 | data['is_afk'] = False |
| 207 | data['active_start'] = current_ts | 192 | data['active_start'] = current_ts |
| 208 | save_activity_data(activity_data) | 193 | save_activity_data(activity_data) |
| 194 | |||
| 195 | afk_str = format_duration(afk_duration) | ||
| 196 | |||
| 197 | if after.self_mute: | ||
| 198 | activity = "odciszył" | ||
| 199 | else: | ||
| 200 | activity = "odgłuchnął" | ||
| 201 | |||
| 202 | message = ( f"[{current_time}] {member.name} {activity} się na {after.channel.name}\n" | ||
| 203 | f"AFK: {afk_str}" ) | ||
| 204 | await log_channel.send(message) | ||
| 205 | logger.info(f"User returned from AFK: {message}") | ||
| 209 | elif not data.get('is_afk') and (after.self_mute or after.self_deaf): | 206 | elif not data.get('is_afk') and (after.self_mute or after.self_deaf): |
| 207 | active_since_start = 0 | ||
| 210 | if data.get('active_start'): | 208 | if data.get('active_start'): |
| 211 | active_since_start = current_ts - data['active_start'] | 209 | active_since_start = current_ts - data['active_start'] |
| 212 | data['total_active'] += active_since_start | 210 | data['total_active'] += active_since_start |
| @@ -214,38 +212,29 @@ class VcLogs(commands.Cog): | |||
| 214 | data['is_afk'] = True | 212 | data['is_afk'] = True |
| 215 | data['active_start'] = None | 213 | data['active_start'] = None |
| 216 | save_activity_data(activity_data) | 214 | save_activity_data(activity_data) |
| 215 | |||
| 216 | if after.self_mute: | ||
| 217 | activity = "wyciszył" | ||
| 218 | else: | ||
| 219 | activity = "ogłuchnął" | ||
| 220 | |||
| 221 | active_str = format_duration(active_since_start) | ||
| 222 | message = ( f"[{current_time}] {member.name} {activity} się na {after.channel.name}\n" | ||
| 223 | f"Aktywny: {active_str}" ) | ||
| 224 | await log_channel.send(message) | ||
| 225 | logger.info(f"User went AFK: {message}") | ||
| 217 | 226 | ||
| 218 | if before.self_deaf != after.self_deaf: | 227 | if before.self_deaf != after.self_deaf: |
| 219 | activity_suffix = None | ||
| 220 | if user_id in activity_data: | ||
| 221 | data = activity_data[user_id] | ||
| 222 | if after.self_deaf: | ||
| 223 | active_str = format_duration(data['total_active']) | ||
| 224 | activity_suffix = f" Aktywny przed AFK: {active_str}" | ||
| 225 | else: | ||
| 226 | active_str = format_duration(data['total_active']) | ||
| 227 | afk_str = format_duration(data['total_afk']) | ||
| 228 | activity_suffix = f" Był AFK: {afk_str} | Łączny aktywny: {active_str}" | ||
| 229 | tts_text, tts_channel = await self.handle_state_change( | 228 | tts_text, tts_channel = await self.handle_state_change( |
| 230 | member, after.channel, 'deaf', after.self_deaf, current_time, log_channel, activity_suffix | 229 | member, after.channel, 'deaf', after.self_deaf, log_channel |
| 231 | ) | 230 | ) |
| 232 | if tts_text and tts_channel: | 231 | if tts_text and tts_channel: |
| 233 | await self.play_tts(tts_channel, tts_text) | 232 | await self.play_tts(tts_channel, tts_text) |
| 234 | return | 233 | return |
| 235 | 234 | ||
| 236 | if before.self_mute != after.self_mute: | 235 | if before.self_mute != after.self_mute: |
| 237 | activity_suffix = None | ||
| 238 | if user_id in activity_data: | ||
| 239 | data = activity_data[user_id] | ||
| 240 | if after.self_mute: | ||
| 241 | active_str = format_duration(data['total_active']) | ||
| 242 | activity_suffix = f" Aktywny przed AFK: {active_str}" | ||
| 243 | else: | ||
| 244 | active_str = format_duration(data['total_active']) | ||
| 245 | afk_str = format_duration(data['total_afk']) | ||
| 246 | activity_suffix = f" Był AFK: {afk_str} | Łączny aktywny: {active_str}" | ||
| 247 | tts_text, tts_channel = await self.handle_state_change( | 236 | tts_text, tts_channel = await self.handle_state_change( |
| 248 | member, after.channel, 'mute', after.self_mute, current_time, log_channel, activity_suffix | 237 | member, after.channel, 'mute', after.self_mute, log_channel |
| 249 | ) | 238 | ) |
| 250 | 239 | ||
| 251 | if tts_text and tts_channel: | 240 | if tts_text and tts_channel: |
