Merge pull request #14 from strNophix/player-context

Player now available on context
This commit is contained in:
2021-11-06 15:30:52 +01:00
committed by GitHub
3 changed files with 20 additions and 12 deletions
+2 -1
View File
@@ -10,6 +10,7 @@ from discord.ext import tasks
from discord.ext.commands import Context
from bot import ChristmasBot
from context import CustomContext
from utils.database import AutoJoin
from utils.EmbedGenerator import EmbedGenerator
from utils.classes import BaseCog
@@ -49,7 +50,7 @@ class InformationCog(BaseCog, name="Information"):
@commands.command(name="wlinfo")
@commands.cooldown(rate=1, per=5, type=commands.BucketType.user)
async def wlinfo(self, ctx: Context):
async def wlinfo(self, ctx: CustomContext):
"""Retrieve various node/server/player information"""
player = self.bot.lavalink.player_manager.get(ctx.guild.id)
node = player.node
+9 -10
View File
@@ -241,12 +241,12 @@ class Music(BaseCog):
async def play(self, ctx: CustomContext):
"""Start the radio"""
# Get the player for this guild from cache.
player: DefaultPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id)
player = ctx.get_player()
if player.is_connected:
await ctx.send("Already connected")
return
await self.fill_player_queue(player, self.bot.config["queue_buffer_size"]
await self.fill_player_queue(player, self.bot.config["queue_buffer_size"]+1)
if not player.is_playing:
await player.play()
@@ -255,17 +255,16 @@ class Music(BaseCog):
return
@commands.command(name="skip", aliases=["next"])
async def skip(self, ctx: Context):
async def skip(self, ctx: CustomContext):
"""Skip the current song"""
player: DefaultPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id)
player = ctx.get_player()
await player.skip()
await ctx.send("Skipped current song")
@commands.command(name="queue", aliases=["q"])
async def queue(self, ctx: Context):
@commands.command(name="queue")
async def queue(self, ctx: CustomContext):
"""Display the current radio queue"""
player: DefaultPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id)
player = ctx.get_player()
embed_color = self.bot.colors["embed"]
embed = Embed(title="Coming Up...", colour=embed_color)
@@ -280,9 +279,9 @@ class Music(BaseCog):
await ctx.send(embed=embed)
@commands.command(name="disconnect", aliases=["dc", "stop"])
async def disconnect(self, ctx: Context):
async def disconnect(self, ctx: CustomContext):
"""Disconnects the radio from the channel"""
player: DefaultPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id)
player = ctx.get_player()
if not ctx.author.voice or (
player.is_connected
+8
View File
@@ -1,7 +1,15 @@
from aioredis.client import Redis
from discord.ext import commands
from discord.ext.commands.errors import CommandInvokeError
from lavalink.models import DefaultPlayer
class CustomContext(commands.Context):
def get_redis(self) -> Redis:
return self.bot._redis_client
def get_player(self) -> DefaultPlayer:
if hasattr(self.bot, "lavalink"):
return self.bot.lavalink.player_manager.get(self.guild.id)
raise CommandInvokeError("Lavalink is still starting up.")