From ca886b1c71bacd26ee75c8d820a8b3d9705f0caf Mon Sep 17 00:00:00 2001 From: insert Date: Thu, 18 Jul 2024 07:44:41 -0400 Subject: [PATCH] add shuffle play --- bot.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bot.py b/bot.py index ac5e270..ee963b3 100644 --- a/bot.py +++ b/bot.py @@ -4,6 +4,7 @@ from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from time import sleep import disnake +import random from urllib.parse import urlparse from disnake.ext import commands from disnake import TextInputStyle @@ -19,6 +20,7 @@ handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(me logger.addHandler(handler) queue = [] +shuffle = False load_dotenv() options = Options() options.profile = webdriver.FirefoxProfile(os.getenv("PROFILE_PATH")) @@ -81,6 +83,23 @@ async def play(inter: disnake.AppCmdInter, link: str): await inter.edit_original_response(f"This bot only accepts youtube links") return +@bot.slash_command( + name="shuffle", + description="toggles shuffle on or off, the queue cannot be unshuffled once it is shuffled", +) +async def shuffleplay(inter: disnake.AppCmdInter, toggle: str = commands.Param(choices=["on", "off"])): + await inter.response.defer(ephemeral=True) + if toggle == "on": + global shuffle + shuffle = True + await inter.edit_original_response(f"shuffle enabled") + return + else: + global shuffle + shuffle = False + await inter.edit_original_response(f"shuffle disabled") + return + @bot.slash_command( name="queue", description="list the videos in queue", @@ -144,7 +163,11 @@ async def remove(inter: disnake.AppCmdInter, toremove: int): async def queuehandler(): loop = asyncio.get_running_loop() + global queue while queue: + if shuffle: + random.shuffle(queue) + print(queue) driver.maximize_window() await loop.run_in_executor(None, play_video, queue[0]) queue.pop(0)