mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
[V3] Update code standards (black code format pass) (#1650)
* ran black: code formatter against `redbot/` with `-l 99` * badge
This commit is contained in:
@@ -9,9 +9,10 @@ from redbot.core.data_manager import cog_data_path
|
||||
import redbot.core
|
||||
|
||||
LAVALINK_DOWNLOAD_URL = (
|
||||
"https://github.com/Cog-Creators/Red-DiscordBot/"
|
||||
"releases/download/{}/Lavalink.jar"
|
||||
).format(redbot.core.__version__)
|
||||
"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"
|
||||
@@ -21,7 +22,7 @@ BUNDLED_APP_YML_FILE = Path(__file__).parent / "application.yml"
|
||||
|
||||
|
||||
async def download_lavalink(session):
|
||||
with LAVALINK_JAR_FILE.open(mode='wb') as f:
|
||||
with LAVALINK_JAR_FILE.open(mode="wb") as f:
|
||||
async with session.get(LAVALINK_DOWNLOAD_URL) as resp:
|
||||
while True:
|
||||
chunk = await resp.content.read(512)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,11 @@
|
||||
import subprocess
|
||||
|
||||
TO_TRANSLATE = [
|
||||
'../audio.py'
|
||||
]
|
||||
TO_TRANSLATE = ["../audio.py"]
|
||||
|
||||
|
||||
def regen_messages():
|
||||
subprocess.run(
|
||||
['pygettext', '-n'] + TO_TRANSLATE
|
||||
)
|
||||
subprocess.run(["pygettext", "-n"] + TO_TRANSLATE)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
regen_messages()
|
||||
regen_messages()
|
||||
|
||||
@@ -5,7 +5,7 @@ from subprocess import Popen, DEVNULL, PIPE
|
||||
import os
|
||||
import logging
|
||||
|
||||
log = logging.getLogger('red.audio.manager')
|
||||
log = logging.getLogger("red.audio.manager")
|
||||
|
||||
proc = None
|
||||
SHUTDOWN = asyncio.Event()
|
||||
@@ -13,7 +13,8 @@ SHUTDOWN = asyncio.Event()
|
||||
|
||||
def has_java_error(pid):
|
||||
from . import LAVALINK_DOWNLOAD_DIR
|
||||
poss_error_file = LAVALINK_DOWNLOAD_DIR / 'hs_err_pid{}.log'.format(pid)
|
||||
|
||||
poss_error_file = LAVALINK_DOWNLOAD_DIR / "hs_err_pid{}.log".format(pid)
|
||||
return poss_error_file.exists()
|
||||
|
||||
|
||||
@@ -29,14 +30,14 @@ async def monitor_lavalink_server(loop):
|
||||
log.info("Restarting Lavalink jar.")
|
||||
await start_lavalink_server(loop)
|
||||
else:
|
||||
log.error("Your Java is borked. Please find the hs_err_pid{}.log file"
|
||||
" in the Audio data folder and report this issue.".format(
|
||||
proc.pid
|
||||
))
|
||||
log.error(
|
||||
"Your Java is borked. Please find the hs_err_pid{}.log file"
|
||||
" in the Audio data folder and report this issue.".format(proc.pid)
|
||||
)
|
||||
|
||||
|
||||
async def has_java(loop):
|
||||
java_available = shutil.which('java') is not None
|
||||
java_available = shutil.which("java") is not None
|
||||
if not java_available:
|
||||
return False
|
||||
|
||||
@@ -48,20 +49,18 @@ async def get_java_version(loop):
|
||||
"""
|
||||
This assumes we've already checked that java exists.
|
||||
"""
|
||||
proc = Popen(
|
||||
shlex.split("java -version", posix=os.name == 'posix'),
|
||||
stdout=PIPE, stderr=PIPE
|
||||
)
|
||||
proc = Popen(shlex.split("java -version", posix=os.name == "posix"), stdout=PIPE, stderr=PIPE)
|
||||
_, err = proc.communicate()
|
||||
|
||||
version_info = str(err, encoding='utf-8')
|
||||
version_info = str(err, encoding="utf-8")
|
||||
|
||||
version_line = version_info.split('\n')[0]
|
||||
version_line = version_info.split("\n")[0]
|
||||
version_start = version_line.find('"')
|
||||
version_string = version_line[version_start + 1:-1]
|
||||
major, minor = version_string.split('.')[:2]
|
||||
major, minor = version_string.split(".")[:2]
|
||||
return int(major), int(minor)
|
||||
|
||||
|
||||
async def start_lavalink_server(loop):
|
||||
java_available, java_version = await has_java(loop)
|
||||
if not java_available:
|
||||
@@ -72,13 +71,15 @@ async def start_lavalink_server(loop):
|
||||
extra_flags = "-Dsun.zip.disableMemoryMapping=true"
|
||||
|
||||
from . import LAVALINK_DOWNLOAD_DIR, LAVALINK_JAR_FILE
|
||||
|
||||
start_cmd = "java {} -jar {}".format(extra_flags, LAVALINK_JAR_FILE.resolve())
|
||||
|
||||
global proc
|
||||
proc = Popen(
|
||||
shlex.split(start_cmd, posix=os.name == 'posix'),
|
||||
shlex.split(start_cmd, posix=os.name == "posix"),
|
||||
cwd=str(LAVALINK_DOWNLOAD_DIR),
|
||||
stdout=DEVNULL, stderr=DEVNULL
|
||||
stdout=DEVNULL,
|
||||
stderr=DEVNULL,
|
||||
)
|
||||
|
||||
log.info("Lavalink jar started. PID: {}".format(proc.pid))
|
||||
|
||||
Reference in New Issue
Block a user