diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/ai.py | 8 | ||||
| -rw-r--r-- | cogs/compression.py | 5 | ||||
| -rw-r--r-- | cogs/downloader.py | 7 | ||||
| -rw-r--r-- | cogs/math.py | 1 | ||||
| -rw-r--r-- | cogs/music/join.py | 5 | ||||
| -rw-r--r-- | cogs/music/leave.py | 14 | ||||
| -rw-r--r-- | cogs/music/loop.py | 4 | ||||
| -rw-r--r-- | cogs/music/play.py | 3 | ||||
| -rw-r--r-- | cogs/music/play_compressed.py | 5 | ||||
| -rw-r--r-- | cogs/music/stop.py | 5 | ||||
| -rw-r--r-- | cogs/tts.py | 4 | ||||
| -rw-r--r-- | main.py | 4 |
12 files changed, 44 insertions, 21 deletions
| @@ -3,6 +3,9 @@ import os | |||
| 3 | import discord | 3 | import discord |
| 4 | import google.generativeai as genai | 4 | import google.generativeai as genai |
| 5 | from discord.ext import commands | 5 | from discord.ext import commands |
| 6 | import logging | ||
| 7 | |||
| 8 | logger = logging.getLogger(__name__) | ||
| 6 | 9 | ||
| 7 | 10 | ||
| 8 | class AI(commands.Cog): | 11 | class 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 | ||
| 34 | def setup(bot): | 34 | 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 | |||
| 4 | 4 | ||
| 5 | import discord | 5 | import discord |
| 6 | from discord.ext import commands | 6 | from discord.ext import commands |
| 7 | import logging | ||
| 7 | 8 | ||
| 9 | logger = logging.getLogger(__name__) | ||
| 8 | 10 | ||
| 9 | def filetype(filename): | 11 | def 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 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import tempfile | 2 | import tempfile |
| 3 | from pathlib import Path | 3 | import logging |
| 4 | 4 | ||
| 5 | import discord | 5 | import discord |
| 6 | import yt_dlp | 6 | import yt_dlp |
| 7 | from discord.ext import commands | 7 | from discord.ext import commands |
| 8 | from dotenv import load_dotenv | 8 | from dotenv import load_dotenv |
| 9 | 9 | ||
| 10 | logger = logging.getLogger(__name__) | ||
| 11 | |||
| 10 | # Load environment variables | 12 | # Load environment variables |
| 11 | load_dotenv() | 13 | load_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 | ||
| 52 | def setup(bot): | 57 | 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): | |||
| 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 @@ | |||
| 1 | from discord.ext import commands | 1 | from discord.ext import commands |
| 2 | 2 | ||
| 3 | import logging | ||
| 4 | |||
| 5 | logger = logging.getLogger(__name__) | ||
| 6 | |||
| 3 | 7 | ||
| 4 | class Join(commands.Cog): | 8 | class 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 | ||
| 13 | def setup(bot): | 18 | 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 @@ | |||
| 1 | from discord.ext import commands | ||
| 2 | |||
| 3 | |||
| 4 | class 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 | |||
| 13 | def 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 @@ | |||
| 1 | from discord.ext import commands | 1 | from discord.ext import commands |
| 2 | import logging | ||
| 3 | |||
| 4 | logger = logging.getLogger(__name__) | ||
| 2 | 5 | ||
| 3 | 6 | ||
| 4 | class Loop(commands.Cog): | 7 | class 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 | ||
| 23 | def setup(bot): | 27 | 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): | |||
| 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 | ||
| 104 | def setup(bot): | 109 | 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 @@ | |||
| 1 | from discord.ext import commands | 1 | from discord.ext import commands |
| 2 | 2 | ||
| 3 | import logging | ||
| 4 | |||
| 5 | logger = logging.getLogger(__name__) | ||
| 6 | |||
| 3 | 7 | ||
| 4 | class Stop(commands.Cog): | 8 | class 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 | ||
| 13 | def setup(bot): | 18 | 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 | |||
| 4 | import discord | 4 | import discord |
| 5 | from discord.ext import commands | 5 | from discord.ext import commands |
| 6 | from gtts import gTTS | 6 | from gtts import gTTS |
| 7 | import logging | ||
| 8 | |||
| 9 | logger = logging.getLogger(__name__) | ||
| 7 | 10 | ||
| 8 | 11 | ||
| 9 | class TTS(commands.Cog): | 12 | class 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 |
| @@ -11,7 +11,7 @@ from dotenv import load_dotenv | |||
| 11 | # Configure logging | 11 | # Configure logging |
| 12 | logging.basicConfig( | 12 | logging.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 |
| 25 | async def on_ready(): | 25 | async 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") |
