[Audio] Handle Missing SQL deps more gracefully (#3066)

* Removes `MAX_BALANCE` from bank, user `bank.get_max_balance()` now
`[p]bankset maxbal` can be used to set the maximum bank balance

Signed-off-by: Guy <guyreis96@gmail.com>

* Remove duplicated call in `[p]playlist update`

Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>

* Handle both ModuleNotFoundError and ImportError and pull a more complete error message to forward to the user and fix grammar.

Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>

* Since we aren't 100% certain of message length here due to using the error message for the raised error ... lets use pagify so this doesn't bite us in the future.

Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>

* .... Lets not reinvent the wheel

Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>

* Address Jack's review
This commit is contained in:
Draper 2019-10-22 03:36:24 +01:00 committed by Michael H
parent 3723b4b1ea
commit 2ba6fb17ca
3 changed files with 14 additions and 9 deletions

View File

@ -0,0 +1 @@
Correctly reports the import error when an SQL dependency is missing.

View File

@ -7,6 +7,7 @@ import logging
import os import os
import random import random
import time import time
import traceback
from collections import namedtuple from collections import namedtuple
from typing import Callable, Dict, List, Mapping, NoReturn, Optional, Tuple, Union from typing import Callable, Dict, List, Mapping, NoReturn, Optional, Tuple, Union
@ -15,11 +16,14 @@ try:
from databases import Database from databases import Database
HAS_SQL = True HAS_SQL = True
except ModuleNotFoundError: _ERROR = None
except ImportError as err:
_ERROR = "".join(traceback.format_exception_only(type(err), err)).strip()
HAS_SQL = False HAS_SQL = False
SQLError = ModuleNotFoundError SQLError = err.__class__
Database = None Database = None
import aiohttp import aiohttp
import discord import discord
import lavalink import lavalink

View File

@ -35,7 +35,7 @@ from redbot.core.utils.menus import (
) )
from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate
from . import dataclasses from . import dataclasses
from .apis import MusicCache, HAS_SQL from .apis import MusicCache, HAS_SQL, _ERROR
from .checks import can_have_caching from .checks import can_have_caching
from .converters import ComplexScopeParser, ScopeParser, get_lazy_converter, get_playlist_converter from .converters import ComplexScopeParser, ScopeParser, get_lazy_converter, get_playlist_converter
from .equalizer import Equalizer from .equalizer import Equalizer
@ -197,16 +197,16 @@ class Audio(commands.Cog):
lavalink.register_event_listener(self.event_handler) lavalink.register_event_listener(self.event_handler)
if not HAS_SQL: if not HAS_SQL:
error_message = ( error_message = (
"Audio version: {version}\nThis version requires SQL to " "Audio version: {version}\nThis version requires some SQL dependencies to "
"access the caching features, " "access the caching features, "
"your Python install is missing the module sqlite3.\n\n" "your Python install is missing some of them.\n\n"
"For instructions on how to fix it Google " "For instructions on how to fix it Google "
"`ModuleNotFoundError: No module named '_sqlite3'`\n" f"`{_ERROR}`.\n"
"You will need to reinstall " "You will need to install the missing SQL dependency.\n\n"
"Python with SQL dependencies installed.\n\n"
).format(version=__version__) ).format(version=__version__)
with contextlib.suppress(discord.HTTPException): with contextlib.suppress(discord.HTTPException):
await self.bot.send_to_owners(error_message) for page in pagify(error_message):
await self.bot.send_to_owners(page)
log.critical(error_message) log.critical(error_message)
async def _migrate_config(self, from_version: int, to_version: int): async def _migrate_config(self, from_version: int, to_version: int):