This commit is contained in:
Drapersniper
2020-10-06 10:11:48 +01:00
parent b59e3a835c
commit 449da2c463
5 changed files with 103 additions and 19 deletions

View File

@@ -94,6 +94,7 @@ class Audio(
localpath=str(cog_data_path(raw_name="Audio")),
url_keyword_blacklist=[],
url_keyword_whitelist=[],
java_exc_path="java",
**self._default_lavalink_settings,
)

View File

@@ -1111,12 +1111,14 @@ class AudioSetCommands(MixinMeta, metaclass=CompositeMetaClass):
"Release date: [{build_time}]\n"
"Lavaplayer version: [{lavaplayer}]\n"
"Java version: [{jvm}]\n"
"Java Executable: [{jv_exec}]\n"
).format(
build_time=self.player_manager.build_time,
llbuild=self.player_manager.ll_build,
llbranch=self.player_manager.ll_branch,
lavaplayer=self.player_manager.lavaplayer,
jvm=self.player_manager.jvm,
jv_exec=self.player_manager.path,
)
if is_owner:
msg += _("Localtracks path: [{localpath}]\n").format(**global_data)

View File

@@ -1,4 +1,5 @@
import logging
from pathlib import Path
import discord
@@ -18,6 +19,73 @@ class LavalinkSetupCommands(MixinMeta, metaclass=CompositeMetaClass):
async def command_llsetup(self, ctx: commands.Context):
"""Lavalink server configuration options."""
@command_llsetup.command(name="java")
async def command_llsetup_java(self, ctx: commands.Context, *, java_path: str = None):
"""Change your Java executable path
Enter nothing to reset to default.
"""
external = await self.config.use_external_lavalink()
if external:
return await self.send_embed_msg(
ctx,
title=_("Invalid Environment"),
description=_(
"You cannot changed the Java executable path of "
"external Lavalink instances from the Audio Cog."
),
)
if java_path is None:
await self.config.java_exc_path.clear()
await self.send_embed_msg(
ctx,
title=_("Java Executable Reset"),
description=_("Audio will now use `java` to run your Lavalink.jar"),
)
else:
exc = Path(java_path)
exc_absolute = exc.absolute()
if not exc.exists() or not exc.is_file():
return await self.send_embed_msg(
ctx,
title=_("Invalid Environment"),
description=_("`{java_path}` is not a valid executable").format(
java_path=exc_absolute
),
)
await self.config.java_exc_path.set(exc_absolute)
await self.send_embed_msg(
ctx,
title=_("Java Executable Changed"),
description=_("Audio will now use `{exc}` to run your Lavalink.jar").format(
exc=exc_absolute
),
)
try:
if self.player_manager is not None:
await self.player_manager.shutdown()
except ProcessLookupError:
await self.send_embed_msg(
ctx,
title=_("Failed To Shutdown Lavalink"),
description=_(
"For it to take effect please reload " "Audio (`{prefix}reload audio`)."
).format(
prefix=ctx.prefix,
),
)
else:
try:
self.lavalink_restart_connect()
except ProcessLookupError:
await self.send_embed_msg(
ctx,
title=_("Failed To Shutdown Lavalink"),
description=_("Please reload Audio (`{prefix}reload audio`).").format(
prefix=ctx.prefix
),
)
@command_llsetup.command(name="external")
async def command_llsetup_external(self, ctx: commands.Context):
"""Toggle using external Lavalink servers."""

View File

@@ -23,7 +23,9 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
max_retries = 5
retry_count = 0
while retry_count < max_retries:
external = await self.config.use_external_lavalink()
configs = await self.config.all()
external = configs["use_external_lavalink"]
java_exec = configs["java_exc_path"]
if external is False:
settings = self._default_lavalink_settings
host = settings["host"]
@@ -34,7 +36,7 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
await self.player_manager.shutdown()
self.player_manager = ServerManager()
try:
await self.player_manager.start()
await self.player_manager.start(java_exec)
except LavalinkDownloadFailed as exc:
await asyncio.sleep(1)
if exc.should_retry:
@@ -66,11 +68,10 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
else:
break
else:
config_data = await self.config.all()
host = config_data["host"]
password = config_data["password"]
rest_port = config_data["rest_port"]
ws_port = config_data["ws_port"]
host = configs["host"]
password = configs["password"]
rest_port = configs["rest_port"]
ws_port = configs["ws_port"]
break
else:
log.critical(