aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamlon <stankiewiczgracjan2019@gmail.com>2025-08-11 17:39:21 +0200
committerSamlon <stankiewiczgracjan2019@gmail.com>2025-08-11 17:39:21 +0200
commitca0b4ecf005e1c1f4066460a45393ebffef1ef1c (patch)
tree4c175ba876ae35d9248dfab33d2a981fe3cfb207
parentchanged printing to proper logging (diff)
downloadsenator-sperma-ca0b4ecf005e1c1f4066460a45393ebffef1ef1c.tar.gz
senator-sperma-ca0b4ecf005e1c1f4066460a45393ebffef1ef1c.zip
more logging
-rw-r--r--cogs/ai.py8
-rw-r--r--cogs/compression.py5
-rw-r--r--cogs/downloader.py7
-rw-r--r--cogs/math.py1
-rw-r--r--cogs/music/join.py5
-rw-r--r--cogs/music/leave.py14
-rw-r--r--cogs/music/loop.py4
-rw-r--r--cogs/music/play.py3
-rw-r--r--cogs/music/play_compressed.py5
-rw-r--r--cogs/music/stop.py5
-rw-r--r--cogs/tts.py4
-rw-r--r--main.py4
12 files changed, 44 insertions, 21 deletions
diff --git a/cogs/ai.py b/cogs/ai.py
index d2af796..8c366a2 100644
--- a/cogs/ai.py
+++ b/cogs/ai.py
@@ -3,6 +3,9 @@ import os
3import discord 3import discord
4import google.generativeai as genai 4import google.generativeai as genai
5from discord.ext import commands 5from discord.ext import commands
6import logging
7
8logger = logging.getLogger(__name__)
6 9
7 10
8class AI(commands.Cog): 11class AI(commands.Cog):
@@ -18,10 +21,6 @@ class AI(commands.Cog):
18 ctx: discord.ApplicationContext, 21 ctx: discord.ApplicationContext,
19 text=discord.Option(str, "message", required=True) 22 text=discord.Option(str, "message", required=True)
20 ): 23 ):
21 """
22 OOWA this so impressive gwachan >w<
23 I can't believe you made this you are so good gwachan :3
24 """
25 await ctx.defer() 24 await ctx.defer()
26 genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) 25 genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
27 model = genai.GenerativeModel("gemini-1.5-flash") 26 model = genai.GenerativeModel("gemini-1.5-flash")
@@ -29,6 +28,7 @@ class AI(commands.Cog):
29 "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. Respond in plain text, no ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text, 28 "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. Respond in plain text, no ** or "". If the message is in Polish, respond in Polish. Respond in 100 words. Respond accordingly to this message: " + text,
30 ) 29 )
31 await ctx.respond(response.text) 30 await ctx.respond(response.text)
31 logger.info(f"AI command executed successfully")
32 32
33 33
34def setup(bot): 34def setup(bot):
diff --git a/cogs/compression.py b/cogs/compression.py
index ddfa545..75eaf7c 100644
--- a/cogs/compression.py
+++ b/cogs/compression.py
@@ -4,7 +4,9 @@ import subprocess
4 4
5import discord 5import discord
6from discord.ext import commands 6from discord.ext import commands
7import logging
7 8
9logger = logging.getLogger(__name__)
8 10
9def filetype(filename): 11def filetype(filename):
10 mime_type, _ = mimetypes.guess_type(filename) 12 mime_type, _ = mimetypes.guess_type(filename)
@@ -45,6 +47,7 @@ class Compression(commands.Cog):
45 input_path = file_path 47 input_path = file_path
46 output_path = os.path.join(temp_dir, f"better_{plik.filename}") 48 output_path = os.path.join(temp_dir, f"better_{plik.filename}")
47 file_type = filetype(file_path) 49 file_type = filetype(file_path)
50 logger.info(f"Compression started for: {file_type}")
48 if file_type == "Video": 51 if file_type == "Video":
49 # Execute ffmpeg command to compress video 52 # Execute ffmpeg command to compress video
50 ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf 51 -b:v 100 -vf 'fps=10' -preset ultrafast -c:a libopus -b:a 500 {output_path}" 53 ffmpeg_command = f"ffmpeg -i {input_path} -c:v libx264 -crf 51 -b:v 100 -vf 'fps=10' -preset ultrafast -c:a libopus -b:a 500 {output_path}"
@@ -68,12 +71,14 @@ class Compression(commands.Cog):
68 ffmpeg_command = img_command 71 ffmpeg_command = img_command
69 else: 72 else:
70 await ctx.respond("Plik jest nieobsługiwany", ephemeral=True) 73 await ctx.respond("Plik jest nieobsługiwany", ephemeral=True)
74 logger.info("Unsupported file type")
71 return 75 return
72 76
73 try: 77 try:
74 subprocess.run(ffmpeg_command, check=True, shell=True) 78 subprocess.run(ffmpeg_command, check=True, shell=True)
75 # Upload the compressed file 79 # Upload the compressed file
76 await ctx.respond(file=discord.File(output_path)) 80 await ctx.respond(file=discord.File(output_path))
81 logger.info(f"Compression completed for: {file_type}")
77 # Delete compressed file 82 # Delete compressed file
78 os.remove(input_path) 83 os.remove(input_path)
79 os.remove(output_path) 84 os.remove(output_path)
diff --git a/cogs/downloader.py b/cogs/downloader.py
index 5fb3d1c..9f825b4 100644
--- a/cogs/downloader.py
+++ b/cogs/downloader.py
@@ -1,12 +1,14 @@
1import os 1import os
2import tempfile 2import tempfile
3from pathlib import Path 3import logging
4 4
5import discord 5import discord
6import yt_dlp 6import yt_dlp
7from discord.ext import commands 7from discord.ext import commands
8from dotenv import load_dotenv 8from dotenv import load_dotenv
9 9
10logger = logging.getLogger(__name__)
11
10# Load environment variables 12# Load environment variables
11load_dotenv() 13load_dotenv()
12 14
@@ -42,11 +44,14 @@ class Downloader(commands.Cog):
42 try: 44 try:
43 file = discord.File(actual_filename) 45 file = discord.File(actual_filename)
44 await ctx.followup.send("Pobran", file=file) 46 await ctx.followup.send("Pobran", file=file)
47 logger.info(f"File downloaded: {actual_filename}")
45 except Exception as e: 48 except Exception as e:
46 await ctx.followup.send(f":(\n{str(e)}") 49 await ctx.followup.send(f":(\n{str(e)}")
50 logger.error(f"Error in download command: {e}", exc_info=True)
47 51
48 except Exception as e: 52 except Exception as e:
49 await ctx.followup.send(f":(\n{str(e)}") 53 await ctx.followup.send(f":(\n{str(e)}")
54 logger.error(f"Error in download command: {e}", exc_info=True)
50 55
51 56
52def setup(bot): 57def setup(bot):
diff --git a/cogs/math.py b/cogs/math.py
index a837ed9..123d7d0 100644
--- a/cogs/math.py
+++ b/cogs/math.py
@@ -19,6 +19,7 @@ class Math(commands.Cog):
19 try: 19 try:
20 math = subprocess.check_output(f"qalc -e {equation}", shell=True) 20 math = subprocess.check_output(f"qalc -e {equation}", shell=True)
21 await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}") 21 await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}")
22 logger.info(f"Math command executed: {equation}")
22 except Exception as e: 23 except Exception as e:
23 await ctx.respond(e, ephemeral=True) 24 await ctx.respond(e, ephemeral=True)
24 logger.error(f"Error in math command: {e}", exc_info=True) 25 logger.error(f"Error in math command: {e}", exc_info=True)
diff --git a/cogs/music/join.py b/cogs/music/join.py
index a613e81..c626897 100644
--- a/cogs/music/join.py
+++ b/cogs/music/join.py
@@ -1,5 +1,9 @@
1from discord.ext import commands 1from discord.ext import commands
2 2
3import logging
4
5logger = logging.getLogger(__name__)
6
3 7
4class Join(commands.Cog): 8class Join(commands.Cog):
5 def __init__(self, bot): 9 def __init__(self, bot):
@@ -8,6 +12,7 @@ class Join(commands.Cog):
8 @commands.slash_command(name="join", description="dołącza do kanalu") 12 @commands.slash_command(name="join", description="dołącza do kanalu")
9 async def join(self, ctx): 13 async def join(self, ctx):
10 await ctx.voice_client.connect() 14 await ctx.voice_client.connect()
15 logger.info("Bot connected to voice channel")
11 16
12 17
13def setup(bot): 18def setup(bot):
diff --git a/cogs/music/leave.py b/cogs/music/leave.py
deleted file mode 100644
index 7be3b60..0000000
--- a/cogs/music/leave.py
+++ /dev/null
@@ -1,14 +0,0 @@
1from discord.ext import commands
2
3
4class Leave(commands.Cog):
5 def __init__(self, bot):
6 self.bot = bot
7
8 @commands.slash_command(name="kick", description="kickuje bota z kanalu")
9 async def kick(self, ctx):
10 await ctx.voice_client.disconnect()
11
12
13def setup(bot):
14 bot.add_cog(Leave(bot))
diff --git a/cogs/music/loop.py b/cogs/music/loop.py
index 2331840..77f87b7 100644
--- a/cogs/music/loop.py
+++ b/cogs/music/loop.py
@@ -1,4 +1,7 @@
1from discord.ext import commands 1from discord.ext import commands
2import logging
3
4logger = logging.getLogger(__name__)
2 5
3 6
4class Loop(commands.Cog): 7class Loop(commands.Cog):
@@ -18,6 +21,7 @@ class Loop(commands.Cog):
18 looping = not self.is_looping(guild_id) 21 looping = not self.is_looping(guild_id)
19 self.set_looping(guild_id, looping) 22 self.set_looping(guild_id, looping)
20 await ctx.respond(f"looping jest teraz {'włączony' if looping else 'wyłączony'}.") 23 await ctx.respond(f"looping jest teraz {'włączony' if looping else 'wyłączony'}.")
24 logger.info(f"Looping has been {'enabled' if looping else 'disabled'} for guild {guild_id}")
21 25
22 26
23def setup(bot): 27def setup(bot):
diff --git a/cogs/music/play.py b/cogs/music/play.py
index d902cdc..5664d31 100644
--- a/cogs/music/play.py
+++ b/cogs/music/play.py
@@ -59,6 +59,7 @@ class Play(commands.Cog):
59 source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) 59 source = discord.FFmpegPCMAudio(url2, **ffmpeg_options)
60 vc.play(source, after=after_playing) 60 vc.play(source, after=after_playing)
61 await ctx.followup.send(f"gra: {title}") 61 await ctx.followup.send(f"gra: {title}")
62 logger.info(f"Playing: {title}")
62 except Exception as e: 63 except Exception as e:
63 await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}") 64 await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}")
64 65
@@ -68,6 +69,7 @@ class Play(commands.Cog):
68 69
69 if not (ctx.author.voice and ctx.author.voice.channel): 70 if not (ctx.author.voice and ctx.author.voice.channel):
70 await ctx.followup.send("nie jesteś w kanale głosowym") 71 await ctx.followup.send("nie jesteś w kanale głosowym")
72 logger.info("User is not in a voice channel")
71 return 73 return
72 74
73 channel = ctx.author.voice.channel 75 channel = ctx.author.voice.channel
@@ -82,6 +84,7 @@ class Play(commands.Cog):
82 84
83 if not result['result']: 85 if not result['result']:
84 await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True) 86 await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True)
87 logger.info(f"Could not find a video for your search: {search}")
85 return 88 return
86 89
87 video = result['result'][0] 90 video = result['result'][0]
diff --git a/cogs/music/play_compressed.py b/cogs/music/play_compressed.py
index 038a15e..dd8dfd8 100644
--- a/cogs/music/play_compressed.py
+++ b/cogs/music/play_compressed.py
@@ -31,6 +31,7 @@ class GrajcujZkompresowane(commands.Cog):
31 output_path = f"{base}_compressed.opus" 31 output_path = f"{base}_compressed.opus"
32 ffmpeg_command = f"ffmpeg -i {input_path} -ac 1 -b:a 500 -acodec libopus {output_path}" 32 ffmpeg_command = f"ffmpeg -i {input_path} -ac 1 -b:a 500 -acodec libopus {output_path}"
33 subprocess.run(ffmpeg_command, check=True, shell=True) 33 subprocess.run(ffmpeg_command, check=True, shell=True)
34 logger.info(f"Audio compressed to {output_path}")
34 return output_path 35 return output_path
35 36
36 @commands.slash_command(name="grajcuj_zkompresowane", description="grajcuj zkompresowane melodyje") 37 @commands.slash_command(name="grajcuj_zkompresowane", description="grajcuj zkompresowane melodyje")
@@ -38,10 +39,12 @@ class GrajcujZkompresowane(commands.Cog):
38 await ctx.defer() 39 await ctx.defer()
39 if not (ctx.author.voice and ctx.author.voice.channel): 40 if not (ctx.author.voice and ctx.author.voice.channel):
40 await ctx.followup.send("nie jesteś w kanale głosowym") 41 await ctx.followup.send("nie jesteś w kanale głosowym")
42 logger.info("User is not in a voice channel")
41 return 43 return
42 channel = ctx.author.voice.channel 44 channel = ctx.author.voice.channel
43 if ctx.voice_client is not None: 45 if ctx.voice_client is not None:
44 vc = ctx.voice_client 46 vc = ctx.voice_client
47 logger.info(f"User is already in a voice channel, moving to new {channel}")
45 await vc.move_to(channel) 48 await vc.move_to(channel)
46 else: 49 else:
47 vc = await channel.connect() 50 vc = await channel.connect()
@@ -81,6 +84,7 @@ class GrajcujZkompresowane(commands.Cog):
81 compressed_file_path = self.compress_audio(file_path) 84 compressed_file_path = self.compress_audio(file_path)
82 except subprocess.CalledProcessError as e: 85 except subprocess.CalledProcessError as e:
83 await ctx.followup.send(f"skompresowanie nie powiodło się: {str(e)}", ephemeral=True) 86 await ctx.followup.send(f"skompresowanie nie powiodło się: {str(e)}", ephemeral=True)
87 logger.error(f"Failed to compress audio: {e}", exc_info=True)
84 return 88 return
85 found_file = compressed_file_path 89 found_file = compressed_file_path
86 found_title = title 90 found_title = title
@@ -99,6 +103,7 @@ class GrajcujZkompresowane(commands.Cog):
99 vc.stop() 103 vc.stop()
100 vc.play(discord.FFmpegPCMAudio(found_file), after=after_playing) 104 vc.play(discord.FFmpegPCMAudio(found_file), after=after_playing)
101 await ctx.followup.send(f"gra (zkompresowane): {title}") 105 await ctx.followup.send(f"gra (zkompresowane): {title}")
106 logger.info(f"Playing audio: {title}")
102 107
103 108
104def setup(bot): 109def setup(bot):
diff --git a/cogs/music/stop.py b/cogs/music/stop.py
index e842b08..c7abfbd 100644
--- a/cogs/music/stop.py
+++ b/cogs/music/stop.py
@@ -1,5 +1,9 @@
1from discord.ext import commands 1from discord.ext import commands
2 2
3import logging
4
5logger = logging.getLogger(__name__)
6
3 7
4class Stop(commands.Cog): 8class Stop(commands.Cog):
5 def __init__(self, bot): 9 def __init__(self, bot):
@@ -8,6 +12,7 @@ class Stop(commands.Cog):
8 @commands.slash_command(name="stop", description="stopuj bota") 12 @commands.slash_command(name="stop", description="stopuj bota")
9 async def stop(self, ctx): 13 async def stop(self, ctx):
10 await ctx.voice_client.disconnect() 14 await ctx.voice_client.disconnect()
15 logger.info("Bot disconnected from voice channel")
11 16
12 17
13def setup(bot): 18def setup(bot):
diff --git a/cogs/tts.py b/cogs/tts.py
index 2481ab3..dceb26c 100644
--- a/cogs/tts.py
+++ b/cogs/tts.py
@@ -4,6 +4,9 @@ import os
4import discord 4import discord
5from discord.ext import commands 5from discord.ext import commands
6from gtts import gTTS 6from gtts import gTTS
7import logging
8
9logger = logging.getLogger(__name__)
7 10
8 11
9class TTS(commands.Cog): 12class TTS(commands.Cog):
@@ -24,6 +27,7 @@ class TTS(commands.Cog):
24 # Check if the user is in a voice channel 27 # Check if the user is in a voice channel
25 if not (ctx.author.voice and ctx.author.voice.channel): 28 if not (ctx.author.voice and ctx.author.voice.channel):
26 await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) 29 await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True)
30 logger.info("tts: User is not in a voice channel")
27 os.remove('tts.mp3') 31 os.remove('tts.mp3')
28 return 32 return
29 channel = ctx.author.voice.channel 33 channel = ctx.author.voice.channel
diff --git a/main.py b/main.py
index 592ff9c..f4b093e 100644
--- a/main.py
+++ b/main.py
@@ -11,7 +11,7 @@ from dotenv import load_dotenv
11# Configure logging 11# Configure logging
12logging.basicConfig( 12logging.basicConfig(
13 level=logging.INFO, 13 level=logging.INFO,
14 format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 14 format='%(filename)s - %(name)s - %(levelname)s - %(message)s',
15 handlers=[ 15 handlers=[
16 logging.StreamHandler(sys.stdout) 16 logging.StreamHandler(sys.stdout)
17 ] 17 ]
@@ -23,7 +23,7 @@ bot = commands.Bot(intents=discord.Intents.all())
23 23
24@bot.event 24@bot.event
25async def on_ready(): 25async def on_ready():
26 logger.info("ŁUKASZ SPERMA AKTYWACJA" + datetime.datetime.now().strftime("(%Y-%m-%d %H:%M:%S)")) 26 logger.info("ŁUKASZ SPERMA AKTYWACJA")
27 # send the message to channel ID 27 # send the message to channel ID
28 channel = bot.get_channel(1081667823799111804) 28 channel = bot.get_channel(1081667823799111804)
29 await channel.send("ŁUKASZ SPERMA AKTYWACJA") 29 await channel.send("ŁUKASZ SPERMA AKTYWACJA")