From 8b96a2078b45c36dc73bb1266d63b572b6589a3d Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 6 Apr 2025 12:00:40 +0700 Subject: [PATCH] Fixes --- commands/voice.py | 77 +++++++++++++++++++++++++++++++++++++++++++++ main.py | 80 +---------------------------------------------- 2 files changed, 78 insertions(+), 79 deletions(-) create mode 100644 commands/voice.py diff --git a/commands/voice.py b/commands/voice.py new file mode 100644 index 0000000..f58452e --- /dev/null +++ b/commands/voice.py @@ -0,0 +1,77 @@ +import nextcord +from nextcord.ext import commands +import yt_dlp +import os + +SquogFinalName: str = None + +SquogVideo = { + "verbose": True, + 'final_ext': 'mp3', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + }], + "outtmpl": './%(uploader)s_%(title)s.%(ext)s', + "quality": "low" +} + +SquogCurrentConnection: nextcord.VoiceClient = None + +SquogDownload = yt_dlp.YoutubeDL(SquogVideo) + +class Main(commands.Cog): + def __init__(self, bot: commands.Bot): + self.client = bot + + @commands.command(description="Join the voice channel.") + async def join(ctx: nextcord.Message): + print("Joining") + if not ctx.guild.voice_client: + if ctx.author.voice: + await ctx.author.voice.channel.connect() + await ctx.reply("Joined.") + else: + await ctx.reply("Can't join as you aren't in any voice channel.") + else: + await ctx.reply("Can't join as i'm already in a voice channel.") + + @commands.command(description="Leaves the voice channel.") + async def leave(ctx: nextcord.Message): + print("Leaving") + if ctx.guild.voice_client: + await ctx.guild.voice_client.disconnect(force=True) + await ctx.reply("Left.") + else: + await ctx.reply("Can't leave as i'm not in any voice channel.") + + @commands.command(description="Plays music in the voice channel.", usage={"link"}) + async def play(ctx: nextcord.Message, link): + global SquogEvilFilename + global SquogFinalName + SquogEvilFilename = None + if not ctx.guild.voice_client: + return await ctx.reply("I'm not in a voice channel.") + if ctx.guild.voice_client.is_playing(): + return await ctx.reply("I'm already playing music.") + print(ctx.guild.voice_client.is_connected()) + SquogVoiceClient = ctx.guild.voice_client + print(link) + SquogDownload.download(link) + SquogInfo = SquogDownload.extract_info(link, download=False) + SquogFinalName = SquogDownload.prepare_filename(SquogInfo) + SquogLength = SquogFinalName.__len__() - 4 + SquogExt = os.path.splitext(SquogFinalName) + print(SquogExt) + SquogLength = SquogFinalName.find(SquogExt[1]) + 1 + print(SquogLength) + SquogEvilFilename = f"{SquogFinalName[:SquogLength]}mp3" + SquogVoiceClient.play(nextcord.FFmpegPCMAudio(f"{SquogEvilFilename}")) + + @commands.command(description="Stops the music in voice channel") + async def stop(ctx: nextcord.Message): + if not ctx.guild.voice_client: + return await ctx.reply("I'm not in a voice channel.") + if not ctx.guild.voice_client.is_playing(): + return await ctx.reply("I'm not playing music.") + SquogCurrentConnection.stop() diff --git a/main.py b/main.py index 79074b4..24bde08 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,5 @@ -import os -import logging import nextcord -import yt_dlp -import subprocess from nextcord.ext import commands -import logging SquogServer = 1356433463854497944 SquogToken = "MTM1NjU2MTY2MjQyOTM2ODQxMQ.G8aypc.CZBX-x6e4Oad3U5zO0nUgc02d9FDIDSNFybysI" @@ -14,27 +9,6 @@ client.remove_command("help") SquogMod = None -SquogFinalName: str = None -def SquogFilename(d): - global SquogFinalName - SquogFinalName = d.get('info_dict').get('_filename') - -SquogVideo = { - "verbose":True, - "progress_hooks": [SquogFilename], - 'final_ext': 'mp3', - 'postprocessors': [{ - 'key': 'FFmpegExtractAudio', - 'preferredcodec': 'mp3', - }], - "outtmpl": './%(uploader)s_%(title)s.%(ext)s', - "quality": "low" -} - -SquogCurrentConnection: nextcord.VoiceClient = None - -SquogDownload = yt_dlp.YoutubeDL(SquogVideo) - # _____ _ # / ____| | | # | | ___ _ __ ___ _ __ ___ __ _ _ __ __| |___ @@ -54,59 +28,7 @@ async def help(ctx: nextcord.Message): async def ping(ctx: nextcord.Message): await ctx.reply("Pong!") -@client.command(description="Join the voice channel.") -async def join(ctx: nextcord.Message): - print("Joining") - if not ctx.guild.voice_client: - if ctx.author.voice: - global SquogCurrentConnection - SquogCurrentConnection = await ctx.author.voice.channel.connect() - await ctx.reply("Joined.") - else: - await ctx.reply("Can't join as you aren't in any voice channel.") - else: - await ctx.reply("Can't join as i'm already in a voice channel.") - -@client.command(description="Leaves the voice channel.") -async def leave(ctx: nextcord.Message): - print("Leaving") - if ctx.guild.voice_client: - await ctx.guild.voice_client.disconnect(force=True) - await ctx.reply("Left.") - else: - await ctx.reply("Can't leave as i'm not in any voice channel.") - -@client.command(description="Plays music in the voice channel.", usage={"link"}) -async def play(ctx: nextcord.Message, link): - global SquogEvilFilename - global SquogFinalName - SquogEvilFilename = None - if not ctx.guild.voice_client: - return await ctx.reply("I'm not in a voice channel.") - if ctx.guild.voice_client.is_playing(): - return await ctx.reply("I'm already playing music.") - print(ctx.guild.voice_client.is_connected()) - print(SquogCurrentConnection) - SquogVoiceClient = ctx.guild.voice_client - print(link) - SquogDownload.download(link) - SquogInfo = SquogDownload.extract_info(link, download=False) - SquogFinalName = SquogDownload.prepare_filename(SquogInfo) - SquogLength = SquogFinalName.__len__() - 4 - SquogExt = os.path.splitext(SquogFinalName) - print(SquogExt) - SquogLength = SquogFinalName.find(SquogExt[1]) + 1 - print(SquogLength) - SquogEvilFilename = f"{SquogFinalName[:SquogLength]}mp3" - SquogVoiceClient.play(nextcord.FFmpegPCMAudio(f"{SquogEvilFilename}")) - -@client.command(description="Stops the music in voice channel") -async def stop(ctx: nextcord.Message): - if not ctx.guild.voice_client: - return await ctx.reply("I'm not in a voice channel.") - if not ctx.guild.voice_client.is_playing(): - return await ctx.reply("I'm not playing music.") - SquogCurrentConnection.stop() +client.add_cog("Main") # ______ _ # | ____| | |