[V3] Make bot send typing whilst loading cogs (#1756)

* Show bot is responsive during cog load

* Log download of Lavalink.jar event

* Fix #1709's other bug

* Reformat

* Update core_commands.py from merge
This commit is contained in:
Tobotimus 2018-06-03 08:06:10 +10:00 committed by Will
parent 622382f425
commit 0d193d3e9e
3 changed files with 16 additions and 11 deletions

View File

@ -1,6 +1,7 @@
from pathlib import Path from pathlib import Path
from aiohttp import ClientSession from aiohttp import ClientSession
import shutil import shutil
import logging
from .audio import Audio from .audio import Audio
from .manager import start_lavalink_server from .manager import start_lavalink_server
@ -8,6 +9,8 @@ from discord.ext import commands
from redbot.core.data_manager import cog_data_path from redbot.core.data_manager import cog_data_path
import redbot.core import redbot.core
log = logging.getLogger("red.audio")
LAVALINK_DOWNLOAD_URL = ( LAVALINK_DOWNLOAD_URL = (
"https://github.com/Cog-Creators/Red-DiscordBot/" "releases/download/{}/Lavalink.jar" "https://github.com/Cog-Creators/Red-DiscordBot/" "releases/download/{}/Lavalink.jar"
).format(redbot.core.__version__) ).format(redbot.core.__version__)
@ -33,15 +36,13 @@ async def maybe_download_lavalink(loop, cog):
jar_exists = LAVALINK_JAR_FILE.exists() jar_exists = LAVALINK_JAR_FILE.exists()
current_build = redbot.core.VersionInfo(*await cog.config.current_build()) current_build = redbot.core.VersionInfo(*await cog.config.current_build())
session = ClientSession(loop=loop)
if not jar_exists or current_build < redbot.core.version_info: if not jar_exists or current_build < redbot.core.version_info:
log.info("Downloading Lavalink.jar")
LAVALINK_DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True) LAVALINK_DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
await download_lavalink(session) async with ClientSession(loop=loop) as session:
await download_lavalink(session)
await cog.config.current_build.set(redbot.core.version_info.to_json()) await cog.config.current_build.set(redbot.core.version_info.to_json())
session.close()
shutil.copyfile(str(BUNDLED_APP_YML_FILE), str(APP_YML_FILE)) shutil.copyfile(str(BUNDLED_APP_YML_FILE), str(APP_YML_FILE))

View File

@ -4,6 +4,9 @@ import asyncio
from subprocess import Popen, DEVNULL, PIPE from subprocess import Popen, DEVNULL, PIPE
import os import os
import logging import logging
from typing import Optional, Tuple
_JavaVersion = Tuple[int, int]
log = logging.getLogger("red.audio.manager") log = logging.getLogger("red.audio.manager")
@ -36,16 +39,16 @@ async def monitor_lavalink_server(loop):
) )
async def has_java(loop): async def has_java(loop) -> Tuple[bool, Optional[_JavaVersion]]:
java_available = shutil.which("java") is not None java_available = shutil.which("java") is not None
if not java_available: if not java_available:
return False return False, None
version = await get_java_version(loop) version = await get_java_version(loop)
return version >= (1, 8), version return version >= (1, 8), version
async def get_java_version(loop): async def get_java_version(loop) -> _JavaVersion:
""" """
This assumes we've already checked that java exists. This assumes we've already checked that java exists.
""" """

View File

@ -501,7 +501,8 @@ class Core(CoreLogic):
"""Loads packages""" """Loads packages"""
cog_names = [c.strip() for c in cog_name.split(" ")] cog_names = [c.strip() for c in cog_name.split(" ")]
loaded, failed, not_found = await self._load(cog_names) async with ctx.typing():
loaded, failed, not_found = await self._load(cog_names)
if loaded: if loaded:
fmt = "Loaded {packs}" fmt = "Loaded {packs}"
@ -546,8 +547,8 @@ class Core(CoreLogic):
"""Reloads packages""" """Reloads packages"""
cog_names = [c.strip() for c in cog_name.split(" ")] cog_names = [c.strip() for c in cog_name.split(" ")]
async with ctx.typing():
loaded, failed, not_found = await self._reload(cog_names) loaded, failed, not_found = await self._reload(cog_names)
if loaded: if loaded:
fmt = "Package{plural} {packs} {other} reloaded." fmt = "Package{plural} {packs} {other} reloaded."