Single-source supported Java versions in Audio code (#6500)

This commit is contained in:
Jakub Kuczys
2025-01-26 23:03:20 +01:00
committed by GitHub
parent 22888f8014
commit 6bf2a88995
5 changed files with 62 additions and 21 deletions

View File

@@ -10,10 +10,11 @@ from red_commons.logging import getLogger
from redbot.core import commands
from redbot.core.data_manager import cog_data_path
from redbot.core.i18n import Translator
from redbot.core.utils.chat_formatting import box, inline
from redbot.core.utils.chat_formatting import box, humanize_list, inline
from ..abc import MixinMeta
from ..cog_utils import CompositeMetaClass
from ...managed_node import version_pins
from ...utils import (
MAX_JAVA_RAM,
DEFAULT_LAVALINK_YAML,
@@ -29,6 +30,16 @@ log = getLogger("red.cogs.Audio.cog.Commands.lavalink_setup")
_ = Translator("Audio", Path(__file__))
class LavalinkSetupJavaCommand(commands.Command):
def format_text_for_context(self, ctx: commands.Context, text: str) -> str:
text = super().format_text_for_context(ctx, text)
return text.format(
supported_java_versions=humanize_list(
list(map(str, version_pins.SUPPORTED_JAVA_VERSIONS))
),
)
class LavalinkSetupCommands(MixinMeta, metaclass=CompositeMetaClass):
@commands.group(name="llset")
@commands.is_owner()
@@ -43,7 +54,7 @@ class LavalinkSetupCommands(MixinMeta, metaclass=CompositeMetaClass):
All the commands in here have the potential to break the Audio cog.
"""
@command_llset.command(name="java")
@command_llset.command(name="java", cls=LavalinkSetupJavaCommand)
@has_managed_server()
async def command_llset_java(self, ctx: commands.Context, *, java_path: str = "java"):
"""Change your Java executable path.
@@ -51,7 +62,7 @@ class LavalinkSetupCommands(MixinMeta, metaclass=CompositeMetaClass):
This command shouldn't need to be used most of the time, and is only useful if the host machine has conflicting Java versions.
If changing this make sure that the Java executable you set is supported by Audio.
The current supported versions are Java 17 and 11.
The current supported versions are Java {supported_java_versions}.
Enter nothing or "java" to reset it back to default.
"""

View File

@@ -23,6 +23,7 @@ from redbot.core.utils.antispam import AntiSpam
from redbot.core.utils.chat_formatting import box, humanize_list, underline, bold
from ...errors import TrackEnqueueError, AudioError
from ...managed_node import version_pins
from ..abc import MixinMeta
from ..cog_utils import CompositeMetaClass
@@ -87,7 +88,7 @@ DANGEROUS_COMMANDS = {
"This command will change the executable path of Java, "
"this is useful if you have multiple installations of Java and the default one is causing issues. "
"Please don't change this unless you are certain that the Java version you are specifying is supported by Red. "
"The default and supported versions are currently Java 17 and 11."
"The supported versions are currently Java {supported_java_versions}."
),
"command_llset_heapsize": _(
"This command will change the maximum RAM allocation for the managed Lavalink node, "
@@ -279,7 +280,11 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
"If you wish to continue, enter this case sensitive token without spaces as your next message."
"\n\n{confirm_token}"
).format(
template=_(DANGEROUS_COMMANDS[ctx.command.callback.__name__]),
template=_(DANGEROUS_COMMANDS[ctx.command.callback.__name__]).format(
supported_java_versions=humanize_list(
list(map(str, version_pins.SUPPORTED_JAVA_VERSIONS))
),
),
confirm_token=box(confirm_token, lang="py"),
)
sent = await ctx.send(message)