Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Audio] No response whilst downloading Lavalink.jar
When loading Audio and Lavalink.jar needs to be downloaded, the bot takes a very long time to respond, which will leave users wondering if the bot is even loading audio.

Just a simple message saying "Downloading Lavalink.jar" or making the bot type whilst downloading makes sure the user knows something is happening.

Also just a quick side-issue which should be an easy fix, this error occurs if the user does not have Java installed:
```
[24/05/2018 06:25] ERROR core_commands load 363: Package loading failed
Traceback (most recent call last):
  File "/home/tobyh/.pyenv/versions/3.6.5/envs/red/lib/python3.6/site-packages/redbot/core/core_commands.py", line 361, in load
    await ctx.bot.load_extension(spec)
  File "/home/tobyh/.pyenv/versions/3.6.5/envs/red/lib/python3.6/site-packages/redbot/core/bot.py", line 227, in load_extension
    await lib.setup(self)
  File "/home/tobyh/.pyenv/versions/3.6.5/envs/red/lib/python3.6/site-packages/redbot/cogs/audio/__init__.py", line 53, in setup
    await start_lavalink_server(bot.loop)
  File "/home/tobyh/.pyenv/versions/3.6.5/envs/red/lib/python3.6/site-packages/redbot/cogs/audio/manager.py", line 66, in start_lavalink_server
    java_available, java_version = await has_java(loop)
TypeError: 'bool' object is not iterable
```


Discussion:

Resolving patch:
diff --git a/redbot/cogs/audio/__init__.py b/redbot/cogs/audio/__init__.py
--- a/redbot/cogs/audio/__init__.py
+++ b/redbot/cogs/audio/__init__.py
@@ -1,6 +1,7 @@
 from pathlib import Path
 from aiohttp import ClientSession
 import shutil
+import logging
 
 from .audio import Audio
 from .manager import start_lavalink_server
@@ -8,6 +9,8 @@
 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__)
@@ -33,15 +36,13 @@ async def maybe_download_lavalink(loop, cog):
     jar_exists = LAVALINK_JAR_FILE.exists()
     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:
+        log.info("Downloading Lavalink.jar")
         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())
 
-    session.close()
-
     shutil.copyfile(str(BUNDLED_APP_YML_FILE), str(APP_YML_FILE))
 
 
diff --git a/redbot/cogs/audio/manager.py b/redbot/cogs/audio/manager.py
--- a/redbot/cogs/audio/manager.py
+++ b/redbot/cogs/audio/manager.py
@@ -4,6 +4,9 @@
 from subprocess import Popen, DEVNULL, PIPE
 import os
 import logging
+from typing import Optional, Tuple
+
+_JavaVersion = Tuple[int, int]
 
 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
     if not java_available:
-        return False
+        return False, None
 
     version = await get_java_version(loop)
     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.
     """
diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py
--- a/redbot/core/core_commands.py
+++ b/redbot/core/core_commands.py
@@ -501,7 +501,8 @@ async def load(self, ctx, *, cog_name: str):
         """Loads packages"""
 
         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:
             fmt = "Loaded {packs}"
@@ -546,8 +547,8 @@ async def reload_(self, ctx, *, cog_name: str):
         """Reloads packages"""
 
         cog_names = [c.strip() for c in cog_name.split(" ")]
-
-        loaded, failed, not_found = await self._reload(cog_names)
+        async with ctx.typing():
+            loaded, failed, not_found = await self._reload(cog_names)
 
         if loaded:
             fmt = "Package{plural} {packs} {other} reloaded."


Test patch: