diff options
| author | SamlonDev <stankiewiczgracjan2019@gmail.com> | 2025-06-14 18:54:02 +0200 |
|---|---|---|
| committer | SamlonDev <stankiewiczgracjan2019@gmail.com> | 2025-06-14 18:54:02 +0200 |
| commit | 791e75cb2beeca45a6edf52b65f7e299e03b5eaf (patch) | |
| tree | cfee93211b7f8ac1c985325aaf8d9399b7a357ca /cogs/ping_commands.py | |
| parent | temp downloads the files instead (diff) | |
| download | senator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.tar.gz senator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.zip | |
code-style issues
Diffstat (limited to 'cogs/ping_commands.py')
| -rw-r--r-- | cogs/ping_commands.py | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/cogs/ping_commands.py b/cogs/ping_commands.py deleted file mode 100644 index beb9685..0000000 --- a/cogs/ping_commands.py +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | import discord | ||
| 2 | from discord.ext import commands | ||
| 3 | import asyncio | ||
| 4 | from yt_dlp import VideosSearch | ||
| 5 | |||
| 6 | class PingCommands(commands.Cog): | ||
| 7 | def __init__(self, bot): | ||
| 8 | self.bot = bot | ||
| 9 | |||
| 10 | @commands.Cog.command() | ||
| 11 | async def vc(self, ctx): | ||
| 12 | # join voice channel | ||
| 13 | pass | ||
| 14 | |||
| 15 | @commands.slash_command(name="grajcuj", description="grajcuj melodyje") | ||
| 16 | async def play(self, ctx, *, search: str): | ||
| 17 | await ctx.defer() | ||
| 18 | if not (ctx.author.voice and ctx.author.voice.channel): | ||
| 19 | await ctx.followup.send("nie jesteś w kanale głosowym") | ||
| 20 | return | ||
| 21 | channel = ctx.author.voice.channel | ||
| 22 | if ctx.voice_client is not None: | ||
| 23 | vc = ctx.voice_client | ||
| 24 | await vc.move_to(channel) | ||
| 25 | else: | ||
| 26 | vc = await channel.connect() | ||
| 27 | videos_search = VideosSearch(search, limit=1) | ||
| 28 | result = videos_search.result() | ||
| 29 | if not result['result']: | ||
| 30 | await ctx.followup.send("nie znaleziono wideo dla twojego wyszukiwania.", ephemeral=True) | ||
| 31 | return | ||
| 32 | video = result['result'][0] | ||
| 33 | title = video['title'] | ||
| 34 | url = video['link'] | ||
| 35 | |||
| 36 | # Get direct audio stream URL | ||
| 37 | proc = await asyncio.create_subprocess_exec( | ||
| 38 | "yt-dlp", "-f", "bestaudio", "-g", url, | ||
| 39 | stdout=asyncio.subprocess.PIPE | ||
| 40 | ) | ||
| 41 | stdout, _ = await proc.communicate() | ||
| 42 | stream_url = stdout.decode().strip() | ||
| 43 | |||
| 44 | ffmpeg_options = { | ||
| 45 | "before_options": "-probesize 32k -analyzeduration 0 -reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5", | ||
| 46 | "options": "-vn" | ||
| 47 | } | ||
| 48 | audio = discord.FFmpegPCMAudio( | ||
| 49 | stream_url, | ||
| 50 | before_options=ffmpeg_options["before_options"], | ||
| 51 | options=ffmpeg_options["options"] | ||
| 52 | ) | ||
| 53 | if not vc.is_playing(): | ||
| 54 | vc.play(audio) | ||
| 55 | await ctx.followup.send(f"gra: {title}") | ||
| 56 | else: | ||
| 57 | await ctx.followup.send(f"dodano do koleyjki: {title}") | ||
| 58 | |||
| 59 | |||
| 60 | |||
