mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
[Audio] Refactor internal Lavalink server management (#2495)
* Refactor internal Lavalink server management Killing many birds with one stone here. - Made server manager into class-based API with two public methods: `start()` and `shutdown()`. Must be re-instantiated each time it is restarted. - Using V3 universal Lavalink.jar hosted on Cog-Creators/Lavalink-Jars repository. - Uses output of `java -jar Lavalink.jar --version` to check if a new jar needs to be downloaded. - `ServerManager.start()` won't return until server is ready, i.e. when "Started Launcher in X seconds" message is printed to STDOUT. - `shlex.quote()` is used so spaces in path to Lavalink.jar don't cause issues. - Enabling external Lavalink will cause internal server to be terminated. - Disabling internal Lavalink will no longer reset settings in config - instead, hard-coded values will be used when connecting to an internal server. - Internal server will now run both WS and REST servers on port 2333, meaning one less port will need to be taken up. - Now using `asyncio.subprocess` module so waiting on and reading from subprocesses can be done asynchronously. Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Don't use shlex.quote on Windows Signed-off-by: Toby <tobyharradine@gmail.com> * Don't use shlex.quote at all I misread a note in the python docs and assumed it was best to use it. Turns out the note only applies to `asyncio.create_subprocess_shell`. Signed-off-by: Toby <tobyharradine@gmail.com> * Missed the port on the rebase * Ignore invalid architectures and inform users when commands are used. * Style fix
This commit is contained in:
@@ -1,31 +1,9 @@
|
||||
from pathlib import Path
|
||||
import logging
|
||||
from redbot.core import commands
|
||||
|
||||
from .audio import Audio
|
||||
from .manager import start_lavalink_server, maybe_download_lavalink
|
||||
from redbot.core import commands
|
||||
from redbot.core.data_manager import cog_data_path
|
||||
import redbot.core
|
||||
|
||||
log = logging.getLogger("red.audio")
|
||||
|
||||
LAVALINK_DOWNLOAD_URL = (
|
||||
"https://github.com/Cog-Creators/Red-DiscordBot/releases/download/{}/Lavalink.jar"
|
||||
).format(redbot.core.__version__)
|
||||
|
||||
LAVALINK_DOWNLOAD_DIR = cog_data_path(raw_name="Audio")
|
||||
LAVALINK_JAR_FILE = LAVALINK_DOWNLOAD_DIR / "Lavalink.jar"
|
||||
|
||||
APP_YML_FILE = LAVALINK_DOWNLOAD_DIR / "application.yml"
|
||||
BUNDLED_APP_YML_FILE = Path(__file__).parent / "data/application.yml"
|
||||
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
cog = Audio(bot)
|
||||
if not await cog.config.use_external_lavalink():
|
||||
await maybe_download_lavalink(bot.loop, cog)
|
||||
await start_lavalink_server(bot.loop)
|
||||
|
||||
await cog.initialize()
|
||||
|
||||
bot.add_cog(cog)
|
||||
|
||||
Reference in New Issue
Block a user