mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:57:48 +00:00
Merge branch 'dev' into database-rewrite
This commit is contained in:
@@ -111,6 +111,12 @@ class TuneBot(commands.Bot):
|
|||||||
print(f"Version: {discord.__version__}")
|
print(f"Version: {discord.__version__}")
|
||||||
print(f"Invite: {self.invite_link}")
|
print(f"Invite: {self.invite_link}")
|
||||||
|
|
||||||
|
ll = self.config["lavalink"]
|
||||||
|
self.lavalink = lavalink.Client(self.user.id)
|
||||||
|
self.lavalink.add_node(
|
||||||
|
ll["host"], ll["port"], ll["password"], ll["region"], ll["name"]
|
||||||
|
)
|
||||||
|
|
||||||
def process_colours(self, colors: Dict[str, str]) -> Dict[str, Color]:
|
def process_colours(self, colors: Dict[str, str]) -> Dict[str, Color]:
|
||||||
colour_dict: Dict[str, Color] = {}
|
colour_dict: Dict[str, Color] = {}
|
||||||
for name, color in colors.items():
|
for name, color in colors.items():
|
||||||
|
|||||||
+4
-18
@@ -74,25 +74,11 @@ class LavalinkVoiceClient(discord.VoiceClient):
|
|||||||
class Music(BaseCog):
|
class Music(BaseCog):
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
if not hasattr(
|
while not self.is_lavalink_ready():
|
||||||
self.bot, "lavalink"
|
|
||||||
): # This ensures the client isn't overwritten during cog reloads.
|
|
||||||
self.bot.lavalink = lavalink.Client(self.bot.user.id)
|
|
||||||
|
|
||||||
ll = self.bot.config["lavalink"]
|
|
||||||
self.bot.lavalink.add_node(
|
|
||||||
ll["host"], ll["port"], ll["password"], ll["region"], ll["name"]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.bot.lavalink.add_event_hook(self.track_hook)
|
|
||||||
await self.async_init()
|
|
||||||
|
|
||||||
async def async_init(self):
|
|
||||||
redis_result = await self.bot.global_autojoin.fetch_channels()
|
|
||||||
|
|
||||||
while len(self.bot.lavalink.node_manager.available_nodes) == 0:
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
self.bot.lavalink.add_event_hook(self.track_hook)
|
||||||
|
redis_result = await self.bot.global_autojoin.fetch_channels()
|
||||||
for guild_id, (voicechannel_id, textchannel_id) in redis_result.items():
|
for guild_id, (voicechannel_id, textchannel_id) in redis_result.items():
|
||||||
player = self.bot.lavalink.player_manager.create(guild_id)
|
player = self.bot.lavalink.player_manager.create(guild_id)
|
||||||
player.store("channel", textchannel_id)
|
player.store("channel", textchannel_id)
|
||||||
@@ -151,7 +137,7 @@ class Music(BaseCog):
|
|||||||
# This is essentially the same as `@commands.guild_only()`
|
# This is essentially the same as `@commands.guild_only()`
|
||||||
# except it saves us repeating ourselves (and also a few lines).
|
# except it saves us repeating ourselves (and also a few lines).
|
||||||
|
|
||||||
if not hasattr(self.bot, "lavalink"):
|
if not self.is_lavalink_ready():
|
||||||
await ctx.send("Still starting please wait a moment.")
|
await ctx.send("Still starting please wait a moment.")
|
||||||
|
|
||||||
if guild_check:
|
if guild_check:
|
||||||
|
|||||||
+3
-1
@@ -13,10 +13,12 @@ if TYPE_CHECKING:
|
|||||||
from bot import TuneBot
|
from bot import TuneBot
|
||||||
from tunebot import PlaylistSource
|
from tunebot import PlaylistSource
|
||||||
from tunebot import AutoJoin
|
from tunebot import AutoJoin
|
||||||
|
from utils.classes import BaseCog
|
||||||
|
|
||||||
|
|
||||||
class CustomContext(commands.Context):
|
class CustomContext(commands.Context):
|
||||||
bot: "TuneBot"
|
bot: "TuneBot"
|
||||||
|
cog: "BaseCog"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def redis(self) -> Redis:
|
def redis(self) -> Redis:
|
||||||
@@ -24,7 +26,7 @@ class CustomContext(commands.Context):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def player(self) -> DefaultPlayer:
|
def player(self) -> DefaultPlayer:
|
||||||
if hasattr(self.bot, "lavalink"):
|
if self.cog.is_lavalink_ready():
|
||||||
return self.bot.lavalink.player_manager.get(self.guild.id)
|
return self.bot.lavalink.player_manager.get(self.guild.id)
|
||||||
|
|
||||||
raise CommandInvokeError("Lavalink is still starting up.")
|
raise CommandInvokeError("Lavalink is still starting up.")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from discord.ext.commands import Cog
|
from discord.ext.commands import Cog
|
||||||
@@ -13,3 +14,9 @@ class BaseCog(Cog):
|
|||||||
for command in self.walk_commands():
|
for command in self.walk_commands():
|
||||||
if brief := slash_descriptions.get(command.qualified_name):
|
if brief := slash_descriptions.get(command.qualified_name):
|
||||||
command.brief = brief
|
command.brief = brief
|
||||||
|
|
||||||
|
def is_lavalink_ready(self) -> bool:
|
||||||
|
return (
|
||||||
|
hasattr(self.bot, "lavalink")
|
||||||
|
and len(self.bot.lavalink.node_manager.available_nodes) > 0
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user