aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/music
diff options
context:
space:
mode:
authorSamlonDev <stankiewiczgracjan2019@gmail.com>2025-06-14 18:54:02 +0200
committerSamlonDev <stankiewiczgracjan2019@gmail.com>2025-06-14 18:54:02 +0200
commit791e75cb2beeca45a6edf52b65f7e299e03b5eaf (patch)
treecfee93211b7f8ac1c985325aaf8d9399b7a357ca /cogs/music
parenttemp downloads the files instead (diff)
downloadsenator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.tar.gz
senator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.zip
code-style issues
Diffstat (limited to '')
-rw-r--r--cogs/music/join.py5
-rw-r--r--cogs/music/leave.py5
-rw-r--r--cogs/music/loop.py4
-rw-r--r--cogs/music/play.py55
-rw-r--r--cogs/music/play_compressed.py15
-rw-r--r--cogs/music/queue.py6
-rw-r--r--cogs/music/skip.py29
7 files changed, 67 insertions, 52 deletions
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 @@
1import discord
2from discord.ext import commands 1from discord.ext import commands
3 2
3
4class Join(commands.Cog): 4class Join(commands.Cog):
5 def __init__(self, bot): 5 def __init__(self, bot):
6 self.bot = bot 6 self.bot = bot
@@ -9,5 +9,6 @@ class Join(commands.Cog):
9 async def join(self, ctx): 9 async def join(self, ctx):
10 await ctx.voice_client.connect() 10 await ctx.voice_client.connect()
11 11
12
12def setup(bot): 13def setup(bot):
13 bot.add_cog(Join(bot)) \ No newline at end of file 14 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 @@
1import discord
2from discord.ext import commands 1from discord.ext import commands
3 2
3
4class Leave(commands.Cog): 4class Leave(commands.Cog):
5 def __init__(self, bot): 5 def __init__(self, bot):
6 self.bot = bot 6 self.bot = bot
@@ -9,5 +9,6 @@ class Leave(commands.Cog):
9 async def kick(self, ctx): 9 async def kick(self, ctx):
10 await ctx.voice_client.disconnect() 10 await ctx.voice_client.disconnect()
11 11
12
12def setup(bot): 13def setup(bot):
13 bot.add_cog(Leave(bot)) \ No newline at end of file 14 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 @@
1from discord.ext import commands 1from discord.ext import commands
2 2
3
3class Loop(commands.Cog): 4class Loop(commands.Cog):
4 def __init__(self, bot): 5 def __init__(self, bot):
5 self.bot = bot 6 self.bot = bot
@@ -18,5 +19,6 @@ class Loop(commands.Cog):
18 self.set_looping(guild_id, looping) 19 self.set_looping(guild_id, looping)
19 await ctx.respond(f"looping jest teraz {'włączony' if looping else 'wyłączony'}.") 20 await ctx.respond(f"looping jest teraz {'włączony' if looping else 'wyłączony'}.")
20 21
22
21def setup(bot): 23def setup(bot):
22 bot.add_cog(Loop(bot)) \ No newline at end of file 24 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 @@
1import discord
2from discord.ext import commands
3import asyncio 1import asyncio
2
3import discord
4import yt_dlp 4import yt_dlp
5from discord.ext import commands
5from youtubesearchpython import VideosSearch 6from youtubesearchpython import VideosSearch
6 7
7# Suppress noise about console usage from yt-dlp 8# Suppress noise about console usage from yt-dlp
8yt_dlp.utils.bug_reports_message = lambda: '' 9yt_dlp.utils.bug_reports_message = lambda: ''
9 10
11
10class Play(commands.Cog): 12class Play(commands.Cog):
11 def __init__(self, bot): 13 def __init__(self, bot):
12 self.bot = bot 14 self.bot = bot
@@ -32,15 +34,15 @@ class Play(commands.Cog):
32 queue = self.get_queue(guild_id) 34 queue = self.get_queue(guild_id)
33 if queue: 35 if queue:
34 title, url = queue[0] 36 title, url = queue[0]
35 37
36 def after_playing(error): 38 def after_playing():
37 if queue: 39 if queue:
38 queue.pop(0) 40 queue.pop(0)
39 if queue: 41 if queue:
40 next_title, next_url = queue[0] 42 next_title, next_url = queue[0]
41 if not vc.is_playing() and not vc.is_paused(): 43 if not vc.is_playing() and not vc.is_paused():
42 asyncio.run_coroutine_threadsafe( 44 asyncio.run_coroutine_threadsafe(
43 self.play_audio(ctx, vc, next_url, next_title, guild_id), 45 self.play_audio(ctx, vc, next_url, next_title),
44 self.bot.loop 46 self.bot.loop
45 ) 47 )
46 else: 48 else:
@@ -48,11 +50,11 @@ class Play(commands.Cog):
48 vc.disconnect(), 50 vc.disconnect(),
49 self.bot.loop 51 self.bot.loop
50 ) 52 )
51 53
52 if not vc.is_playing() and not vc.is_paused(): 54 if not vc.is_playing() and not vc.is_paused():
53 await self.play_audio(ctx, vc, url, title, guild_id, after=after_playing) 55 await self.play_audio(ctx, vc, url, title, after=after_playing)
54 56
55 async def play_audio(self, ctx, vc, url, title, guild_id, after=None): 57 async def play_audio(self, ctx, vc, url, title, after=None):
56 try: 58 try:
57 with yt_dlp.YoutubeDL(self.ydl_opts) as ydl: 59 with yt_dlp.YoutubeDL(self.ydl_opts) as ydl:
58 info = await self.bot.loop.run_in_executor( 60 info = await self.bot.loop.run_in_executor(
@@ -61,59 +63,59 @@ class Play(commands.Cog):
61 ) 63 )
62 if 'entries' in info: 64 if 'entries' in info:
63 info = info['entries'][0] 65 info = info['entries'][0]
64 66
65 url2 = info['url'] 67 url2 = info['url']
66 68
67 FFMPEG_OPTIONS = { 69 ffmpeg_options = {
68 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 70 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
69 'options': '-vn' 71 'options': '-vn'
70 } 72 }
71 73
72 source = discord.FFmpegPCMAudio(url2, **FFMPEG_OPTIONS) 74 source = discord.FFmpegPCMAudio(url2, **ffmpeg_options)
73 vc.play(source, after=after) 75 vc.play(source, after=after)
74 await ctx.followup.send(f"gra: {title}") 76 await ctx.followup.send(f"gra: {title}")
75 except Exception as e: 77 except Exception as e:
76 await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}") 78 await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}")
77 # Try to play next in queue if there's an error 79 # Try to play next in the queue if there's an error
78 if after: 80 if after:
79 after(None) 81 after(None)
80 82
81 @commands.slash_command(name="grajcuj", description="grajcuj melodyje") 83 @commands.slash_command(name="grajcuj", description="grajcuj melodyje")
82 async def play(self, ctx, *, search: str): 84 async def play(self, ctx, *, search: str):
83 await ctx.defer() 85 await ctx.defer()
84 86
85 if not (ctx.author.voice and ctx.author.voice.channel): 87 if not (ctx.author.voice and ctx.author.voice.channel):
86 await ctx.followup.send("nie jesteś w kanale głosowym") 88 await ctx.followup.send("nie jesteś w kanale głosowym")
87 return 89 return
88 90
89 channel = ctx.author.voice.channel 91 channel = ctx.author.voice.channel
90 vc = ctx.voice_client or await channel.connect() 92 vc = ctx.voice_client or await channel.connect()
91 93
92 if vc.channel != channel: 94 if vc.channel != channel:
93 await vc.move_to(channel) 95 await vc.move_to(channel)
94 96
95 # Search for the video 97 # Search for the video
96 videos_search = VideosSearch(search, limit=1) 98 videos_search = VideosSearch(search, limit=1)
97 result = videos_search.result() 99 result = videos_search.result()
98 100
99 if not result['result']: 101 if not result['result']:
100 await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True) 102 await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True)
101 return 103 return
102 104
103 video = result['result'][0] 105 video = result['result'][0]
104 title = video['title'] 106 title = video['title']
105 url = video['link'] 107 url = video['link']
106 108
107 # Add to queue 109 # Add to queue
108 queue = self.get_queue(ctx.guild.id) 110 queue = self.get_queue(ctx.guild.id)
109 queue.append((title, url)) 111 queue.append((title, url))
110 112
111 # If nothing is playing, start playing 113 # If nothing is playing, start playing
112 if not vc.is_playing() and not vc.is_paused(): 114 if not vc.is_playing() and not vc.is_paused():
113 await self.play_next(ctx, vc, ctx.guild.id) 115 await self.play_next(ctx, vc, ctx.guild.id)
114 else: 116 else:
115 await ctx.followup.send(f"dodano do kolejki: {title}") 117 await ctx.followup.send(f"dodano do kolejki: {title}")
116 118
117 @commands.slash_command(name="stop", description="zatrzymaj odtwarzanie i wyczyść kolejkę") 119 @commands.slash_command(name="stop", description="zatrzymaj odtwarzanie i wyczyść kolejkę")
118 async def stop(self, ctx): 120 async def stop(self, ctx):
119 if ctx.voice_client: 121 if ctx.voice_client:
@@ -123,7 +125,7 @@ class Play(commands.Cog):
123 await ctx.respond("Zatrzymano odtwarzanie i wyczyszczono kolejkę") 125 await ctx.respond("Zatrzymano odtwarzanie i wyczyszczono kolejkę")
124 else: 126 else:
125 await ctx.respond("Nie jestem połączony z kanałem głosowym") 127 await ctx.respond("Nie jestem połączony z kanałem głosowym")
126 128
127 @commands.slash_command(name="pauza", description="wstrzymaj odtwarzanie") 129 @commands.slash_command(name="pauza", description="wstrzymaj odtwarzanie")
128 async def pause(self, ctx): 130 async def pause(self, ctx):
129 if ctx.voice_client and ctx.voice_client.is_playing(): 131 if ctx.voice_client and ctx.voice_client.is_playing():
@@ -131,7 +133,7 @@ class Play(commands.Cog):
131 await ctx.respond("Wstrzymano odtwarzanie") 133 await ctx.respond("Wstrzymano odtwarzanie")
132 else: 134 else:
133 await ctx.respond("Nic nie jest teraz odtwarzane") 135 await ctx.respond("Nic nie jest teraz odtwarzane")
134 136
135 @commands.slash_command(name="wznow", description="wznów odtwarzanie") 137 @commands.slash_command(name="wznow", description="wznów odtwarzanie")
136 async def resume(self, ctx): 138 async def resume(self, ctx):
137 if ctx.voice_client and ctx.voice_client.is_paused(): 139 if ctx.voice_client and ctx.voice_client.is_paused():
@@ -140,5 +142,6 @@ class Play(commands.Cog):
140 else: 142 else:
141 await ctx.respond("Nic nie jest teraz wstrzymane") 143 await ctx.respond("Nic nie jest teraz wstrzymane")
142 144
145
143def setup(bot): 146def setup(bot):
144 bot.add_cog(Play(bot)) \ No newline at end of file 147 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 @@
1import discord
2from discord.ext import commands
3import asyncio 1import asyncio
4import os 2import os
5import subprocess 3import subprocess
4
5import discord
6from discord.ext import commands
6from youtubesearchpython import VideosSearch 7from youtubesearchpython import VideosSearch
7 8
9
8class GrajcujZkompresowane(commands.Cog): 10class GrajcujZkompresowane(commands.Cog):
9 def __init__(self, bot): 11 def __init__(self, bot):
10 self.bot = bot 12 self.bot = bot
11 13
12 def prepend_title_to_file(self, file_path, title): 14 @staticmethod
15 def prepend_title_to_file(file_path, title):
13 try: 16 try:
14 with open(file_path, 'rb') as original: 17 with open(file_path, 'rb') as original:
15 data = original.read() 18 data = original.read()
@@ -19,7 +22,8 @@ class GrajcujZkompresowane(commands.Cog):
19 except Exception as e: 22 except Exception as e:
20 print(f"Failed to prepend title: {e}") 23 print(f"Failed to prepend title: {e}")
21 24
22 def compress_audio(self, input_path): 25 @staticmethod
26 def compress_audio(input_path):
23 base, ext = os.path.splitext(input_path) 27 base, ext = os.path.splitext(input_path)
24 output_path = f"{base}_compressed{ext}" 28 output_path = f"{base}_compressed{ext}"
25 ffmpeg_command = f"ffmpeg -i {input_path} -ar 8000 -ac 1 -b:a 500 -acodec libmp3lame -q:a 9 {output_path}" 29 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):
84 else: 88 else:
85 await ctx.followup.send(f"dodano do koleyjki (zkompresowane): {title}") 89 await ctx.followup.send(f"dodano do koleyjki (zkompresowane): {title}")
86 90
91
87def setup(bot): 92def setup(bot):
88 bot.add_cog(GrajcujZkompresowane(bot)) \ No newline at end of file 93 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 @@
1from discord.ext import commands 1from discord.ext import commands
2 2
3
3class Queue(commands.Cog): 4class Queue(commands.Cog):
4 def __init__(self, bot): 5 def __init__(self, bot):
5 self.bot = bot 6 self.bot = bot
@@ -13,10 +14,11 @@ class Queue(commands.Cog):
13 guild_id = ctx.guild.id 14 guild_id = ctx.guild.id
14 queue = self.get_queue(guild_id) 15 queue = self.get_queue(guild_id)
15 if queue: 16 if queue:
16 queue_str = "\n".join(f"{i+1}. {title}" for i, (_, title, _) in enumerate(queue)) 17 queue_str = "\n".join(f"{i + 1}. {title}" for i, (_, title, _) in enumerate(queue))
17 await ctx.respond(f"koleyjka:\n{queue_str}") 18 await ctx.respond(f"koleyjka:\n{queue_str}")
18 else: 19 else:
19 await ctx.respond("koleyjka jest pustawa") 20 await ctx.respond("koleyjka jest pustawa")
20 21
22
21def setup(bot): 23def setup(bot):
22 bot.add_cog(Queue(bot)) \ No newline at end of file 24 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 @@
1from discord.ext import commands 1from discord.ext import commands
2import discord 2
3 3
4class Skip(commands.Cog): 4class Skip(commands.Cog):
5 def __init__(self, bot): 5 def __init__(self, bot):
@@ -9,31 +9,31 @@ class Skip(commands.Cog):
9 async def pomin(self, ctx): 9 async def pomin(self, ctx):
10 """Skip the current song and play the next one in the queue.""" 10 """Skip the current song and play the next one in the queue."""
11 vc = ctx.voice_client 11 vc = ctx.voice_client
12 12
13 if not vc or not vc.is_connected(): 13 if not vc or not vc.is_connected():
14 await ctx.respond("Nie jestem połączony z kanałem głosowym.") 14 await ctx.respond("Nie jestem połączony z kanałem głosowym.")
15 return 15 return
16 16
17 if not vc.is_playing() and not vc.is_paused(): 17 if not vc.is_playing() and not vc.is_paused():
18 await ctx.respond("Nic nie jest teraz odtwarzane.") 18 await ctx.respond("Nic nie jest teraz odtwarzane.")
19 return 19 return
20 20
21 # Get the play cog 21 # Get the play cog
22 play_cog = self.bot.get_cog('Play') 22 play_cog = self.bot.get_cog('Play')
23 if not play_cog: 23 if not play_cog:
24 await ctx.respond("Błąd: Nie można znaleźć modułu odtwarzania.") 24 await ctx.respond("Błąd: Nie można znaleźć modułu odtwarzania.")
25 return 25 return
26 26
27 queue = play_cog.get_queue(ctx.guild.id) 27 queue = play_cog.get_queue(ctx.guild.id)
28 28
29 if not queue: 29 if not queue:
30 await ctx.respond("Kolejka jest pusta.") 30 await ctx.respond("Kolejka jest pusta.")
31 return 31 return
32 32
33 # Stop the current song (this will trigger play_next in the after callback) 33 # Stop the current song (this will trigger play_next in the after callback)
34 vc.stop() 34 vc.stop()
35 await ctx.respond("Pominięto aktualną piosenkę.") 35 await ctx.respond("Pominięto aktualną piosenkę.")
36 36
37 @commands.slash_command(name="kolejka", description="pokaż aktualną kolejkę") 37 @commands.slash_command(name="kolejka", description="pokaż aktualną kolejkę")
38 async def queue_list(self, ctx): 38 async def queue_list(self, ctx):
39 """Show the current queue.""" 39 """Show the current queue."""
@@ -41,21 +41,22 @@ class Skip(commands.Cog):
41 if not play_cog: 41 if not play_cog:
42 await ctx.respond("Błąd: Nie można znaleźć modułu odtwarzania.") 42 await ctx.respond("Błąd: Nie można znaleźć modułu odtwarzania.")
43 return 43 return
44 44
45 queue = play_cog.get_queue(ctx.guild.id) 45 queue = play_cog.get_queue(ctx.guild.id)
46 46
47 if not queue: 47 if not queue:
48 await ctx.respond("Kolejka jest pusta.") 48 await ctx.respond("Kolejka jest pusta.")
49 return 49 return
50 50
51 queue_list = [] 51 queue_list = []
52 for i, (title, _) in enumerate(queue[:10], 1): # Show up to 10 songs 52 for i, (title, _) in enumerate(queue[:10], 1): # Show up to 10 songs
53 queue_list.append(f"{i}. {title}") 53 queue_list.append(f"{i}. {title}")
54 54
55 if len(queue) > 10: 55 if len(queue) > 10:
56 queue_list.append(f"...i {len(queue) - 10} więcej") 56 queue_list.append(f"...i {len(queue) - 10} więcej")
57 57
58 await ctx.respond("\n".join(["**Kolejka:**"] + queue_list)) 58 await ctx.respond("\n".join(["**Kolejka:**"] + queue_list))
59 59
60
60def setup(bot): 61def setup(bot):
61 bot.add_cog(Skip(bot)) \ No newline at end of file 62 bot.add_cog(Skip(bot))