From 791e75cb2beeca45a6edf52b65f7e299e03b5eaf Mon Sep 17 00:00:00 2001 From: SamlonDev Date: Sat, 14 Jun 2025 18:54:02 +0200 Subject: code-style issues --- cogs/music/join.py | 5 ++-- cogs/music/leave.py | 5 ++-- cogs/music/loop.py | 4 +++- cogs/music/play.py | 55 +++++++++++++++++++++++-------------------- cogs/music/play_compressed.py | 15 ++++++++---- cogs/music/queue.py | 6 +++-- cogs/music/skip.py | 29 ++++++++++++----------- 7 files changed, 67 insertions(+), 52 deletions(-) (limited to 'cogs/music') diff --git a/cogs/music/join.py b/cogs/music/join.py index 91a0b18..a613e81 100644 --- a/cogs/music/join.py +++ b/cogs/music/join.py @@ -1,6 +1,6 @@ -import discord from discord.ext import commands + class Join(commands.Cog): def __init__(self, bot): self.bot = bot @@ -9,5 +9,6 @@ class Join(commands.Cog): async def join(self, ctx): await ctx.voice_client.connect() + def setup(bot): - bot.add_cog(Join(bot)) \ No newline at end of file + bot.add_cog(Join(bot)) diff --git a/cogs/music/leave.py b/cogs/music/leave.py index 0be2068..7be3b60 100644 --- a/cogs/music/leave.py +++ b/cogs/music/leave.py @@ -1,6 +1,6 @@ -import discord from discord.ext import commands + class Leave(commands.Cog): def __init__(self, bot): self.bot = bot @@ -9,5 +9,6 @@ class Leave(commands.Cog): async def kick(self, ctx): await ctx.voice_client.disconnect() + def setup(bot): - bot.add_cog(Leave(bot)) \ No newline at end of file + bot.add_cog(Leave(bot)) diff --git a/cogs/music/loop.py b/cogs/music/loop.py index 5f51c7e..2331840 100644 --- a/cogs/music/loop.py +++ b/cogs/music/loop.py @@ -1,5 +1,6 @@ from discord.ext import commands + class Loop(commands.Cog): def __init__(self, bot): self.bot = bot @@ -18,5 +19,6 @@ class Loop(commands.Cog): self.set_looping(guild_id, looping) await ctx.respond(f"looping jest teraz {'włączony' if looping else 'wyłączony'}.") + def setup(bot): - bot.add_cog(Loop(bot)) \ No newline at end of file + bot.add_cog(Loop(bot)) diff --git a/cogs/music/play.py b/cogs/music/play.py index bf9d081..b47de03 100644 --- a/cogs/music/play.py +++ b/cogs/music/play.py @@ -1,12 +1,14 @@ -import discord -from discord.ext import commands import asyncio + +import discord import yt_dlp +from discord.ext import commands from youtubesearchpython import VideosSearch # Suppress noise about console usage from yt-dlp yt_dlp.utils.bug_reports_message = lambda: '' + class Play(commands.Cog): def __init__(self, bot): self.bot = bot @@ -32,15 +34,15 @@ class Play(commands.Cog): queue = self.get_queue(guild_id) if queue: title, url = queue[0] - - def after_playing(error): + + def after_playing(): if queue: queue.pop(0) if queue: next_title, next_url = queue[0] if not vc.is_playing() and not vc.is_paused(): asyncio.run_coroutine_threadsafe( - self.play_audio(ctx, vc, next_url, next_title, guild_id), + self.play_audio(ctx, vc, next_url, next_title), self.bot.loop ) else: @@ -48,11 +50,11 @@ class Play(commands.Cog): vc.disconnect(), self.bot.loop ) - + if not vc.is_playing() and not vc.is_paused(): - await self.play_audio(ctx, vc, url, title, guild_id, after=after_playing) + await self.play_audio(ctx, vc, url, title, after=after_playing) - async def play_audio(self, ctx, vc, url, title, guild_id, after=None): + async def play_audio(self, ctx, vc, url, title, after=None): try: with yt_dlp.YoutubeDL(self.ydl_opts) as ydl: info = await self.bot.loop.run_in_executor( @@ -61,59 +63,59 @@ class Play(commands.Cog): ) if 'entries' in info: info = info['entries'][0] - + url2 = info['url'] - - FFMPEG_OPTIONS = { + + ffmpeg_options = { 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn' } - - source = discord.FFmpegPCMAudio(url2, **FFMPEG_OPTIONS) + + source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) vc.play(source, after=after) await ctx.followup.send(f"gra: {title}") except Exception as e: await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}") - # Try to play next in queue if there's an error + # Try to play next in the queue if there's an error if after: after(None) @commands.slash_command(name="grajcuj", description="grajcuj melodyje") async def play(self, ctx, *, search: str): await ctx.defer() - + if not (ctx.author.voice and ctx.author.voice.channel): await ctx.followup.send("nie jesteś w kanale głosowym") return - + channel = ctx.author.voice.channel vc = ctx.voice_client or await channel.connect() - + if vc.channel != channel: await vc.move_to(channel) - + # Search for the video videos_search = VideosSearch(search, limit=1) result = videos_search.result() - + if not result['result']: await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True) return - + video = result['result'][0] title = video['title'] url = video['link'] - + # Add to queue queue = self.get_queue(ctx.guild.id) queue.append((title, url)) - + # If nothing is playing, start playing if not vc.is_playing() and not vc.is_paused(): await self.play_next(ctx, vc, ctx.guild.id) else: await ctx.followup.send(f"dodano do kolejki: {title}") - + @commands.slash_command(name="stop", description="zatrzymaj odtwarzanie i wyczyść kolejkę") async def stop(self, ctx): if ctx.voice_client: @@ -123,7 +125,7 @@ class Play(commands.Cog): await ctx.respond("Zatrzymano odtwarzanie i wyczyszczono kolejkę") else: await ctx.respond("Nie jestem połączony z kanałem głosowym") - + @commands.slash_command(name="pauza", description="wstrzymaj odtwarzanie") async def pause(self, ctx): if ctx.voice_client and ctx.voice_client.is_playing(): @@ -131,7 +133,7 @@ class Play(commands.Cog): await ctx.respond("Wstrzymano odtwarzanie") else: await ctx.respond("Nic nie jest teraz odtwarzane") - + @commands.slash_command(name="wznow", description="wznów odtwarzanie") async def resume(self, ctx): if ctx.voice_client and ctx.voice_client.is_paused(): @@ -140,5 +142,6 @@ class Play(commands.Cog): else: await ctx.respond("Nic nie jest teraz wstrzymane") + def setup(bot): - bot.add_cog(Play(bot)) \ No newline at end of file + bot.add_cog(Play(bot)) diff --git a/cogs/music/play_compressed.py b/cogs/music/play_compressed.py index 3297110..f14d75b 100644 --- a/cogs/music/play_compressed.py +++ b/cogs/music/play_compressed.py @@ -1,15 +1,18 @@ -import discord -from discord.ext import commands import asyncio import os import subprocess + +import discord +from discord.ext import commands from youtubesearchpython import VideosSearch + class GrajcujZkompresowane(commands.Cog): def __init__(self, bot): self.bot = bot - def prepend_title_to_file(self, file_path, title): + @staticmethod + def prepend_title_to_file(file_path, title): try: with open(file_path, 'rb') as original: data = original.read() @@ -19,7 +22,8 @@ class GrajcujZkompresowane(commands.Cog): except Exception as e: print(f"Failed to prepend title: {e}") - def compress_audio(self, input_path): + @staticmethod + def compress_audio(input_path): base, ext = os.path.splitext(input_path) output_path = f"{base}_compressed{ext}" ffmpeg_command = f"ffmpeg -i {input_path} -ar 8000 -ac 1 -b:a 500 -acodec libmp3lame -q:a 9 {output_path}" @@ -84,5 +88,6 @@ class GrajcujZkompresowane(commands.Cog): else: await ctx.followup.send(f"dodano do koleyjki (zkompresowane): {title}") + def setup(bot): - bot.add_cog(GrajcujZkompresowane(bot)) \ No newline at end of file + bot.add_cog(GrajcujZkompresowane(bot)) diff --git a/cogs/music/queue.py b/cogs/music/queue.py index 29f0c36..d932838 100644 --- a/cogs/music/queue.py +++ b/cogs/music/queue.py @@ -1,5 +1,6 @@ from discord.ext import commands + class Queue(commands.Cog): def __init__(self, bot): self.bot = bot @@ -13,10 +14,11 @@ class Queue(commands.Cog): guild_id = ctx.guild.id queue = self.get_queue(guild_id) if queue: - queue_str = "\n".join(f"{i+1}. {title}" for i, (_, title, _) in enumerate(queue)) + queue_str = "\n".join(f"{i + 1}. {title}" for i, (_, title, _) in enumerate(queue)) await ctx.respond(f"koleyjka:\n{queue_str}") else: await ctx.respond("koleyjka jest pustawa") + def setup(bot): - bot.add_cog(Queue(bot)) \ No newline at end of file + bot.add_cog(Queue(bot)) diff --git a/cogs/music/skip.py b/cogs/music/skip.py index 67c391e..b0023fe 100644 --- a/cogs/music/skip.py +++ b/cogs/music/skip.py @@ -1,5 +1,5 @@ from discord.ext import commands -import discord + class Skip(commands.Cog): def __init__(self, bot): @@ -9,31 +9,31 @@ class Skip(commands.Cog): async def pomin(self, ctx): """Skip the current song and play the next one in the queue.""" vc = ctx.voice_client - + if not vc or not vc.is_connected(): await ctx.respond("Nie jestem połączony z kanałem głosowym.") return - + if not vc.is_playing() and not vc.is_paused(): await ctx.respond("Nic nie jest teraz odtwarzane.") return - + # Get the play cog play_cog = self.bot.get_cog('Play') if not play_cog: await ctx.respond("Błąd: Nie można znaleźć modułu odtwarzania.") return - + queue = play_cog.get_queue(ctx.guild.id) - + if not queue: await ctx.respond("Kolejka jest pusta.") return - + # Stop the current song (this will trigger play_next in the after callback) vc.stop() await ctx.respond("Pominięto aktualną piosenkę.") - + @commands.slash_command(name="kolejka", description="pokaż aktualną kolejkę") async def queue_list(self, ctx): """Show the current queue.""" @@ -41,21 +41,22 @@ class Skip(commands.Cog): if not play_cog: await ctx.respond("Błąd: Nie można znaleźć modułu odtwarzania.") return - + queue = play_cog.get_queue(ctx.guild.id) - + if not queue: await ctx.respond("Kolejka jest pusta.") return - + queue_list = [] for i, (title, _) in enumerate(queue[:10], 1): # Show up to 10 songs queue_list.append(f"{i}. {title}") - + if len(queue) > 10: queue_list.append(f"...i {len(queue) - 10} więcej") - + await ctx.respond("\n".join(["**Kolejka:**"] + queue_list)) + def setup(bot): - bot.add_cog(Skip(bot)) \ No newline at end of file + bot.add_cog(Skip(bot)) -- cgit v1.2.3