From ca0b4ecf005e1c1f4066460a45393ebffef1ef1c Mon Sep 17 00:00:00 2001 From: Samlon Date: Mon, 11 Aug 2025 17:39:21 +0200 Subject: more logging --- cogs/ai.py | 8 ++++---- cogs/compression.py | 5 +++++ cogs/downloader.py | 7 ++++++- cogs/math.py | 1 + cogs/music/join.py | 5 +++++ cogs/music/leave.py | 14 -------------- cogs/music/loop.py | 4 ++++ cogs/music/play.py | 3 +++ cogs/music/play_compressed.py | 5 +++++ cogs/music/stop.py | 5 +++++ cogs/tts.py | 4 ++++ 11 files changed, 42 insertions(+), 19 deletions(-) delete mode 100644 cogs/music/leave.py (limited to 'cogs') 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 import discord import google.generativeai as genai from discord.ext import commands +import logging + +logger = logging.getLogger(__name__) class AI(commands.Cog): @@ -18,10 +21,6 @@ class AI(commands.Cog): ctx: discord.ApplicationContext, text=discord.Option(str, "message", required=True) ): - """ - OOWA this so impressive gwachan >w< - I can't believe you made this you are so good gwachan :3 - """ await ctx.defer() genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) model = genai.GenerativeModel("gemini-1.5-flash") @@ -29,6 +28,7 @@ class AI(commands.Cog): "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, ) await ctx.respond(response.text) + logger.info(f"AI command executed successfully") def 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 import discord from discord.ext import commands +import logging +logger = logging.getLogger(__name__) def filetype(filename): mime_type, _ = mimetypes.guess_type(filename) @@ -45,6 +47,7 @@ class Compression(commands.Cog): input_path = file_path output_path = os.path.join(temp_dir, f"better_{plik.filename}") file_type = filetype(file_path) + logger.info(f"Compression started for: {file_type}") if file_type == "Video": # Execute ffmpeg command to compress video 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): ffmpeg_command = img_command else: await ctx.respond("Plik jest nieobsługiwany", ephemeral=True) + logger.info("Unsupported file type") return try: subprocess.run(ffmpeg_command, check=True, shell=True) # Upload the compressed file await ctx.respond(file=discord.File(output_path)) + logger.info(f"Compression completed for: {file_type}") # Delete compressed file os.remove(input_path) 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 @@ import os import tempfile -from pathlib import Path +import logging import discord import yt_dlp from discord.ext import commands from dotenv import load_dotenv +logger = logging.getLogger(__name__) + # Load environment variables load_dotenv() @@ -42,11 +44,14 @@ class Downloader(commands.Cog): try: file = discord.File(actual_filename) await ctx.followup.send("Pobran", file=file) + logger.info(f"File downloaded: {actual_filename}") except Exception as e: await ctx.followup.send(f":(\n{str(e)}") + logger.error(f"Error in download command: {e}", exc_info=True) except Exception as e: await ctx.followup.send(f":(\n{str(e)}") + logger.error(f"Error in download command: {e}", exc_info=True) def 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): try: math = subprocess.check_output(f"qalc -e {equation}", shell=True) await ctx.respond(f"{equation} = {math.decode('utf-8').strip()}") + logger.info(f"Math command executed: {equation}") except Exception as e: await ctx.respond(e, ephemeral=True) 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 @@ from discord.ext import commands +import logging + +logger = logging.getLogger(__name__) + class Join(commands.Cog): def __init__(self, bot): @@ -8,6 +12,7 @@ class Join(commands.Cog): @commands.slash_command(name="join", description="dołącza do kanalu") async def join(self, ctx): await ctx.voice_client.connect() + logger.info("Bot connected to voice channel") def 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 @@ -from discord.ext import commands - - -class Leave(commands.Cog): - def __init__(self, bot): - self.bot = bot - - @commands.slash_command(name="kick", description="kickuje bota z kanalu") - async def kick(self, ctx): - await ctx.voice_client.disconnect() - - -def setup(bot): - 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 @@ from discord.ext import commands +import logging + +logger = logging.getLogger(__name__) class Loop(commands.Cog): @@ -18,6 +21,7 @@ class Loop(commands.Cog): looping = not self.is_looping(guild_id) self.set_looping(guild_id, looping) await ctx.respond(f"looping jest teraz {'włączony' if looping else 'wyłączony'}.") + logger.info(f"Looping has been {'enabled' if looping else 'disabled'} for guild {guild_id}") def 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): source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) vc.play(source, after=after_playing) await ctx.followup.send(f"gra: {title}") + logger.info(f"Playing: {title}") except Exception as e: await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}") @@ -68,6 +69,7 @@ class Play(commands.Cog): if not (ctx.author.voice and ctx.author.voice.channel): await ctx.followup.send("nie jesteś w kanale głosowym") + logger.info("User is not in a voice channel") return channel = ctx.author.voice.channel @@ -82,6 +84,7 @@ class Play(commands.Cog): if not result['result']: await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True) + logger.info(f"Could not find a video for your search: {search}") return 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): output_path = f"{base}_compressed.opus" ffmpeg_command = f"ffmpeg -i {input_path} -ac 1 -b:a 500 -acodec libopus {output_path}" subprocess.run(ffmpeg_command, check=True, shell=True) + logger.info(f"Audio compressed to {output_path}") return output_path @commands.slash_command(name="grajcuj_zkompresowane", description="grajcuj zkompresowane melodyje") @@ -38,10 +39,12 @@ class GrajcujZkompresowane(commands.Cog): await ctx.defer() if not (ctx.author.voice and ctx.author.voice.channel): await ctx.followup.send("nie jesteś w kanale głosowym") + logger.info("User is not in a voice channel") return channel = ctx.author.voice.channel if ctx.voice_client is not None: vc = ctx.voice_client + logger.info(f"User is already in a voice channel, moving to new {channel}") await vc.move_to(channel) else: vc = await channel.connect() @@ -81,6 +84,7 @@ class GrajcujZkompresowane(commands.Cog): compressed_file_path = self.compress_audio(file_path) except subprocess.CalledProcessError as e: await ctx.followup.send(f"skompresowanie nie powiodło się: {str(e)}", ephemeral=True) + logger.error(f"Failed to compress audio: {e}", exc_info=True) return found_file = compressed_file_path found_title = title @@ -99,6 +103,7 @@ class GrajcujZkompresowane(commands.Cog): vc.stop() vc.play(discord.FFmpegPCMAudio(found_file), after=after_playing) await ctx.followup.send(f"gra (zkompresowane): {title}") + logger.info(f"Playing audio: {title}") def 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 @@ from discord.ext import commands +import logging + +logger = logging.getLogger(__name__) + class Stop(commands.Cog): def __init__(self, bot): @@ -8,6 +12,7 @@ class Stop(commands.Cog): @commands.slash_command(name="stop", description="stopuj bota") async def stop(self, ctx): await ctx.voice_client.disconnect() + logger.info("Bot disconnected from voice channel") def 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 import discord from discord.ext import commands from gtts import gTTS +import logging + +logger = logging.getLogger(__name__) class TTS(commands.Cog): @@ -24,6 +27,7 @@ class TTS(commands.Cog): # Check if the user is in a voice channel if not (ctx.author.voice and ctx.author.voice.channel): await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) + logger.info("tts: User is not in a voice channel") os.remove('tts.mp3') return channel = ctx.author.voice.channel -- cgit v1.2.3