mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 21:27:48 +00:00
using @property for existing context functions
This commit is contained in:
+15
-19
@@ -241,15 +241,16 @@ class Music(BaseCog):
|
||||
async def play(self, ctx: CustomContext):
|
||||
"""Start the radio"""
|
||||
# Get the player for this guild from cache.
|
||||
player = ctx.get_player()
|
||||
if player.is_connected:
|
||||
if ctx.player.is_connected:
|
||||
await ctx.send("Already connected")
|
||||
return
|
||||
|
||||
await self.fill_player_queue(player, self.bot.config["queue_buffer_size"] + 1)
|
||||
await self.fill_player_queue(
|
||||
ctx.player, self.bot.config["queue_buffer_size"] + 1
|
||||
)
|
||||
|
||||
if not player.is_playing:
|
||||
await player.play()
|
||||
if not ctx.player.is_playing:
|
||||
await ctx.player.play()
|
||||
|
||||
await EmbedGenerator.Title(ctx, "*⃣ | Connected.")
|
||||
return
|
||||
@@ -257,21 +258,19 @@ class Music(BaseCog):
|
||||
@commands.command(name="skip", aliases=["next"])
|
||||
async def skip(self, ctx: CustomContext):
|
||||
"""Skip the current song"""
|
||||
player = ctx.get_player()
|
||||
await player.skip()
|
||||
await ctx.player.skip()
|
||||
await ctx.send("Skipped current song")
|
||||
|
||||
@commands.command(name="queue")
|
||||
async def queue(self, ctx: CustomContext):
|
||||
"""Display the current radio queue"""
|
||||
player = ctx.get_player()
|
||||
embed_color = self.bot.colors["embed"]
|
||||
embed = Embed(title="Coming Up...", colour=embed_color)
|
||||
|
||||
if len(player.queue) > 0:
|
||||
if len(ctx.player.queue) > 0:
|
||||
embed.description = "\n".join(
|
||||
f"{index}. [{track.title}]({track.uri})"
|
||||
for index, track in enumerate(player.queue, 1)
|
||||
for index, track in enumerate(ctx.player.queue, 1)
|
||||
)
|
||||
else:
|
||||
embed.description = "We are still determining a playlist"
|
||||
@@ -281,11 +280,9 @@ class Music(BaseCog):
|
||||
@commands.command(name="disconnect", aliases=["dc", "stop"])
|
||||
async def disconnect(self, ctx: CustomContext):
|
||||
"""Disconnects the radio from the channel"""
|
||||
player = ctx.get_player()
|
||||
|
||||
if not ctx.author.voice or (
|
||||
player.is_connected
|
||||
and ctx.author.voice.channel.id != int(player.channel_id)
|
||||
ctx.player.is_connected
|
||||
and ctx.author.voice.channel.id != int(ctx.player.channel_id)
|
||||
):
|
||||
# Abuse prevention. Users not in voice channels, or not in the same voice channel as the bot
|
||||
# may not disconnect the bot.
|
||||
@@ -294,18 +291,17 @@ class Music(BaseCog):
|
||||
|
||||
# Clear the queue to ensure old tracks don't start playing
|
||||
# when someone else queues something.
|
||||
player.queue.clear()
|
||||
ctx.player.queue.clear()
|
||||
# Stop the current track so Lavalink consumes less resources.
|
||||
await player.stop()
|
||||
await ctx.player.stop()
|
||||
# Disconnect from the voice channel.
|
||||
await ctx.voice_client.disconnect(force=True)
|
||||
await EmbedGenerator.Title(ctx, "*⃣ | Disconnected.")
|
||||
|
||||
@commands.command(name="now")
|
||||
async def now_playing(self, ctx: CustomContext):
|
||||
player: DefaultPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id)
|
||||
track = player.current
|
||||
embed = await self.create_track_embed(track)
|
||||
"""Displays information about the currently played track"""
|
||||
embed = await self.create_track_embed(ctx.player.current)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user