aboutsummaryrefslogtreecommitdiffstats
path: root/cogs
diff options
context:
space:
mode:
authorSamlon <stankiewiczgracjan2019@gmail.com>2025-08-11 17:16:33 +0200
committerSamlon <stankiewiczgracjan2019@gmail.com>2025-08-11 17:16:33 +0200
commit0eb1a48fca5668c7c5c35ef81d247b4511d8e78a (patch)
tree1ac1ed8f62ac0d641b6527141afd6f06eb3f8ade /cogs
parentfixing not working skip (diff)
downloadsenator-sperma-0eb1a48fca5668c7c5c35ef81d247b4511d8e78a.tar.gz
senator-sperma-0eb1a48fca5668c7c5c35ef81d247b4511d8e78a.zip
changed printing to proper logging
Diffstat (limited to '')
-rw-r--r--cogs/math.py7
-rw-r--r--cogs/music/play.py7
-rw-r--r--cogs/music/play_compressed.py9
-rw-r--r--cogs/vclogs.py13
4 files changed, 24 insertions, 12 deletions
diff --git a/cogs/math.py b/cogs/math.py
index 53340f2..a837ed9 100644
--- a/cogs/math.py
+++ b/cogs/math.py
@@ -1,8 +1,11 @@
1import logging
1import subprocess 2import subprocess
2 3
3from discord import (ApplicationContext) 4from discord import ApplicationContext
4from discord.ext import commands 5from discord.ext import commands
5 6
7logger = logging.getLogger(__name__)
8
6 9
7class Math(commands.Cog): 10class Math(commands.Cog):
8 def __init__(self, bot): 11 def __init__(self, bot):
@@ -18,7 +21,7 @@ class Math(commands.Cog):
18 await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}") 21 await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}")
19 except Exception as e: 22 except Exception as e:
20 await ctx.respond(e, ephemeral=True) 23 await ctx.respond(e, ephemeral=True)
21 print(e) 24 logger.error(f"Error in math command: {e}", exc_info=True)
22 25
23 26
24def setup(bot): 27def setup(bot):
diff --git a/cogs/music/play.py b/cogs/music/play.py
index 5d82127..d902cdc 100644
--- a/cogs/music/play.py
+++ b/cogs/music/play.py
@@ -1,10 +1,13 @@
1import asyncio 1import asyncio
2import logging
2 3
3import discord 4import discord
4import yt_dlp 5import yt_dlp
5from discord.ext import commands 6from discord.ext import commands
6from youtubesearchpython import VideosSearch 7from youtubesearchpython import VideosSearch
7 8
9logger = logging.getLogger(__name__)
10
8# Suppress noise about console usage from yt-dlp 11# Suppress noise about console usage from yt-dlp
9yt_dlp.utils.bug_reports_message = lambda: '' 12yt_dlp.utils.bug_reports_message = lambda: ''
10 13
@@ -45,13 +48,13 @@ class Play(commands.Cog):
45 48
46 def after_playing(error): 49 def after_playing(error):
47 if error: 50 if error:
48 print(f'Player error: {error}') 51 logger.error(f'Player error: {error}')
49 coro = vc.disconnect() 52 coro = vc.disconnect()
50 fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) 53 fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop)
51 try: 54 try:
52 fut.result() 55 fut.result()
53 except Exception as e: 56 except Exception as e:
54 print(f'Error disconnecting: {e}') 57 logger.error(f'Error disconnecting: {e}', exc_info=True)
55 58
56 source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) 59 source = discord.FFmpegPCMAudio(url2, **ffmpeg_options)
57 vc.play(source, after=after_playing) 60 vc.play(source, after=after_playing)
diff --git a/cogs/music/play_compressed.py b/cogs/music/play_compressed.py
index 0d4901c..038a15e 100644
--- a/cogs/music/play_compressed.py
+++ b/cogs/music/play_compressed.py
@@ -1,4 +1,5 @@
1import asyncio 1import asyncio
2import logging
2import os 3import os
3import subprocess 4import subprocess
4 5
@@ -6,6 +7,8 @@ import discord
6from discord.ext import commands 7from discord.ext import commands
7from youtubesearchpython import VideosSearch 8from youtubesearchpython import VideosSearch
8 9
10logger = logging.getLogger(__name__)
11
9 12
10class GrajcujZkompresowane(commands.Cog): 13class GrajcujZkompresowane(commands.Cog):
11 def __init__(self, bot): 14 def __init__(self, bot):
@@ -20,7 +23,7 @@ class GrajcujZkompresowane(commands.Cog):
20 modified.write(f"{title}\n".encode('utf-8')) 23 modified.write(f"{title}\n".encode('utf-8'))
21 modified.write(data) 24 modified.write(data)
22 except Exception as e: 25 except Exception as e:
23 print(f"Failed to prepend title: {e}") 26 logger.error(f"Failed to prepend title: {e}", exc_info=True)
24 27
25 @staticmethod 28 @staticmethod
26 def compress_audio(input_path): 29 def compress_audio(input_path):
@@ -84,13 +87,13 @@ class GrajcujZkompresowane(commands.Cog):
84 title = found_title 87 title = found_title
85 def after_playing(error): 88 def after_playing(error):
86 if error: 89 if error:
87 print(f'Player error: {error}') 90 logger.error(f'Player error: {error}')
88 coro = vc.disconnect() 91 coro = vc.disconnect()
89 fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) 92 fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop)
90 try: 93 try:
91 fut.result() 94 fut.result()
92 except Exception as e: 95 except Exception as e:
93 print(f'Error disconnecting: {e}') 96 logger.error(f'Error disconnecting: {e}', exc_info=True)
94 97
95 if vc.is_playing() or vc.is_paused(): 98 if vc.is_playing() or vc.is_paused():
96 vc.stop() 99 vc.stop()
diff --git a/cogs/vclogs.py b/cogs/vclogs.py
index 4bc7104..ed0737b 100644
--- a/cogs/vclogs.py
+++ b/cogs/vclogs.py
@@ -1,11 +1,14 @@
1import datetime 1import datetime
2import json 2import json
3import logging
3import os 4import os
4 5
5import discord 6import discord
6from discord.ext import commands 7from discord.ext import commands
7from gtts import gTTS 8from gtts import gTTS
8 9
10logger = logging.getLogger(__name__)
11
9 12
10class VcLogs(commands.Cog): 13class VcLogs(commands.Cog):
11 def __init__(self, bot): 14 def __init__(self, bot):
@@ -39,7 +42,7 @@ class VcLogs(commands.Cog):
39 42
40 message, tts_text = state_messages[state_type][is_enabled] 43 message, tts_text = state_messages[state_type][is_enabled]
41 await log_channel.send(message) 44 await log_channel.send(message)
42 print(message) 45 logger.info(f"Voice state change: {message}")
43 return tts_text, channel 46 return tts_text, channel
44 47
45 async def play_tts(self, channel, text): 48 async def play_tts(self, channel, text):
@@ -80,10 +83,10 @@ class VcLogs(commands.Cog):
80 json.dump({'volume': '5'}, f, indent=4) 83 json.dump({'volume': '5'}, f, indent=4)
81 with open('settings.json', 'w') as f: 84 with open('settings.json', 'w') as f:
82 json.dump({"volume": volume}, f, indent=4) 85 json.dump({"volume": volume}, f, indent=4)
83 await ctx.send(f"Volume has been set to: {volume}") 86 await ctx.followup.send(f"Volume has been set to: {volume}")
84 except Exception as e: 87 except Exception as e:
85 await ctx.respond(e, ephemeral=True) 88 await ctx.respond(e, ephemeral=True)
86 print(e) 89 logger.error(f"Error in volume command: {e}", exc_info=True)
87 90
88 @commands.Cog.listener() 91 @commands.Cog.listener()
89 async def on_voice_state_update(self, member, before, after): 92 async def on_voice_state_update(self, member, before, after):
@@ -101,13 +104,13 @@ class VcLogs(commands.Cog):
101 tts_text = f"{member.display_name} sie zespawnił" 104 tts_text = f"{member.display_name} sie zespawnił"
102 tts_channel = after.channel 105 tts_channel = after.channel
103 await log_channel.send(message) 106 await log_channel.send(message)
104 print(message) 107 logger.info(f"User joined voice channel: {message}")
105 elif before.channel is not None and after.channel is None: 108 elif before.channel is not None and after.channel is None:
106 message = f"[{current_time}] {member.name} rozłączył się z {before.channel.name}" 109 message = f"[{current_time}] {member.name} rozłączył się z {before.channel.name}"
107 tts_text = f"{member.display_name} jest chujem" 110 tts_text = f"{member.display_name} jest chujem"
108 tts_channel = before.channel 111 tts_channel = before.channel
109 await log_channel.send(message) 112 await log_channel.send(message)
110 print(message) 113 logger.info(f"User left voice channel: {message}")
111 114
112 if before.self_deaf != after.self_deaf: 115 if before.self_deaf != after.self_deaf:
113 tts_text, tts_channel = await self.handle_state_change( 116 tts_text, tts_channel = await self.handle_state_change(