update advanced.py cog

This commit is contained in:
cloudwithax 2022-11-19 14:28:15 -05:00
parent 70815d45ff
commit 9fde02c2e0
1 changed files with 14 additions and 12 deletions

View File

@ -21,7 +21,7 @@ class Player(pomice.Player):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.queue = asyncio.Queue() self.queue = pomice.Queue()
self.controller: discord.Message = None self.controller: discord.Message = None
# Set context here so we can send a now playing embed # Set context here so we can send a now playing embed
self.context: commands.Context = None self.context: commands.Context = None
@ -49,8 +49,8 @@ class Player(pomice.Player):
# Queue up the next track, else teardown the player # Queue up the next track, else teardown the player
try: try:
track: pomice.Track = self.queue.get_nowait() track: pomice.Track = self.queue.get()
except asyncio.queues.QueueEmpty: except pomice.QueueEmpty:
return await self.teardown() return await self.teardown()
await self.play(track) await self.play(track)
@ -143,7 +143,7 @@ class Music(commands.Cog):
async def on_pomice_track_exception(self, player: Player, track, _): async def on_pomice_track_exception(self, player: Player, track, _):
await player.do_next() await player.do_next()
@commands.command(aliases=['join', 'joi', 'j', 'summon', 'su', 'con']) @commands.command(aliases=['joi', 'j', 'summon', 'su', 'con', 'connect'])
async def join(self, ctx: commands.Context, *, channel: discord.VoiceChannel = None) -> None: async def join(self, ctx: commands.Context, *, channel: discord.VoiceChannel = None) -> None:
if not channel: if not channel:
channel = getattr(ctx.author.voice, "channel", None) channel = getattr(ctx.author.voice, "channel", None)
@ -157,7 +157,7 @@ class Music(commands.Cog):
player: Player = ctx.voice_client player: Player = ctx.voice_client
# Set the player context so we can use it so send messages # Set the player context so we can use it so send messages
player.set_context(ctx=ctx) await player.set_context(ctx=ctx)
await ctx.send(f"Joined the voice channel `{channel.name}`") await ctx.send(f"Joined the voice channel `{channel.name}`")
@commands.command(aliases=['disconnect', 'dc', 'disc', 'lv', 'fuckoff']) @commands.command(aliases=['disconnect', 'dc', 'disc', 'lv', 'fuckoff'])
@ -172,7 +172,9 @@ class Music(commands.Cog):
async def play(self, ctx: commands.Context, *, search: str) -> None: async def play(self, ctx: commands.Context, *, search: str) -> None:
# Checks if the player is in the channel before we play anything # Checks if the player is in the channel before we play anything
if not (player := ctx.voice_client): if not (player := ctx.voice_client):
await ctx.invoke(self.join) await ctx.author.voice.channel.connect(cls=Player)
player: Player = ctx.voice_client
await player.set_context(ctx=ctx)
# If you search a keyword, Pomice will automagically search the result using YouTube # If you search a keyword, Pomice will automagically search the result using YouTube
# You can pass in "search_type=" as an argument to change the search type # You can pass in "search_type=" as an argument to change the search type
@ -187,10 +189,10 @@ class Music(commands.Cog):
if isinstance(results, pomice.Playlist): if isinstance(results, pomice.Playlist):
for track in results.tracks: for track in results.tracks:
await player.queue.put(track) player.queue.put(track)
else: else:
track = results[0] track = results[0]
await player.queue.put(track) player.queue.put(track)
if not player.is_playing: if not player.is_playing:
await player.do_next() await player.do_next()
@ -315,7 +317,7 @@ class Music(commands.Cog):
if self.is_privileged(ctx): if self.is_privileged(ctx):
await ctx.send('An admin or DJ has shuffled the queue.', delete_after=10) await ctx.send('An admin or DJ has shuffled the queue.', delete_after=10)
player.shuffle_votes.clear() player.shuffle_votes.clear()
return random.shuffle(player.queue._queue) return player.queue.shuffle()
required = self.required(ctx) required = self.required(ctx)
player.shuffle_votes.add(ctx.author) player.shuffle_votes.add(ctx.author)
@ -323,7 +325,7 @@ class Music(commands.Cog):
if len(player.shuffle_votes) >= required: if len(player.shuffle_votes) >= required:
await ctx.send('Vote to shuffle passed. Shuffling the queue.', delete_after=10) await ctx.send('Vote to shuffle passed. Shuffling the queue.', delete_after=10)
player.shuffle_votes.clear() player.shuffle_votes.clear()
random.shuffle(player.queue._queue) player.queue.shuffle()
else: else:
await ctx.send(f'{ctx.author.mention} has voted to shuffle the queue. Votes: {len(player.shuffle_votes)}/{required}', delete_after=15) await ctx.send(f'{ctx.author.mention} has voted to shuffle the queue. Votes: {len(player.shuffle_votes)}/{required}', delete_after=15)
@ -348,7 +350,7 @@ class Music(commands.Cog):
def setup(bot: commands.Bot): async def setup(bot: commands.Bot):
bot.add_cog(Music(bot)) await bot.add_cog(Music(bot))