From 4242f1586fb56d155683ebf70ea26d37f0491630 Mon Sep 17 00:00:00 2001 From: Parker Date: Sun, 31 Mar 2024 00:12:16 -0500 Subject: [PATCH] Create `shuffle on/off` ccommands --- code/cogs/shuffle.py | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 code/cogs/shuffle.py diff --git a/code/cogs/shuffle.py b/code/cogs/shuffle.py new file mode 100644 index 0000000..88e81da --- /dev/null +++ b/code/cogs/shuffle.py @@ -0,0 +1,59 @@ +import discord +import datetime +from discord import app_commands +from discord.ext import commands +from cogs.music import Music + +from global_variables import BOT_COLOR + + +class Shuffle(commands.GroupCog, name="shuffle"): + def __init__(self, bot): + self.bot = bot + + + @app_commands.command(name="on") + @app_commands.check(Music.create_player) + async def shuffle_on(self, interaction: discord.Interaction): + "Play songs from the queue in a randomized order" + player = self.bot.lavalink.player_manager.get(interaction.guild.id) + + player.shuffle = True + + embed = discord.Embed( + title=f"Shuffle Enabled 🔀", + description=f"All music will now be shuffled.", + color=BOT_COLOR, + ) + embed.set_footer( + text=datetime.datetime.now(datetime.timezone.utc).strftime( + "%Y-%m-%d %H:%M:%S" + ) + + " UTC" + ) + await interaction.response.send_message(embed=embed) + + @app_commands.command(name="off") + @app_commands.check(Music.create_player) + async def shuffle_off(self, interaction: discord.Interaction): + "Stop playing songs from queue in a randomized order" + player = self.bot.lavalink.player_manager.get(interaction.guild.id) + + player.shuffle = False + + embed = discord.Embed( + title=f"Disabled 🔀", + description=f"Music will no longer be shuffled.", + color=BOT_COLOR, + ) + embed.set_footer( + text=datetime.datetime.now(datetime.timezone.utc).strftime( + "%Y-%m-%d %H:%M:%S" + ) + + " UTC" + ) + await interaction.response.send_message(embed=embed) + + +async def setup(bot): + await bot.add_cog(Shuffle(bot))