mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[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:
parent
3723b4b1ea
commit
2ba6fb17ca
1
changelog.d/audio/3065.bugfix.rst
Normal file
1
changelog.d/audio/3065.bugfix.rst
Normal file
@ -0,0 +1 @@
|
||||
Correctly reports the import error when an SQL dependency is missing.
|
||||
@ -7,6 +7,7 @@ import logging
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
import traceback
|
||||
from collections import namedtuple
|
||||
from typing import Callable, Dict, List, Mapping, NoReturn, Optional, Tuple, Union
|
||||
|
||||
@ -15,11 +16,14 @@ try:
|
||||
from databases import Database
|
||||
|
||||
HAS_SQL = True
|
||||
except ModuleNotFoundError:
|
||||
_ERROR = None
|
||||
except ImportError as err:
|
||||
_ERROR = "".join(traceback.format_exception_only(type(err), err)).strip()
|
||||
HAS_SQL = False
|
||||
SQLError = ModuleNotFoundError
|
||||
SQLError = err.__class__
|
||||
Database = None
|
||||
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
import lavalink
|
||||
|
||||
@ -35,7 +35,7 @@ from redbot.core.utils.menus import (
|
||||
)
|
||||
from redbot.core.utils.predicates import MessagePredicate, ReactionPredicate
|
||||
from . import dataclasses
|
||||
from .apis import MusicCache, HAS_SQL
|
||||
from .apis import MusicCache, HAS_SQL, _ERROR
|
||||
from .checks import can_have_caching
|
||||
from .converters import ComplexScopeParser, ScopeParser, get_lazy_converter, get_playlist_converter
|
||||
from .equalizer import Equalizer
|
||||
@ -197,16 +197,16 @@ class Audio(commands.Cog):
|
||||
lavalink.register_event_listener(self.event_handler)
|
||||
if not HAS_SQL:
|
||||
error_message = (
|
||||
"Audio version: {version}\nThis version requires SQL to "
|
||||
"Audio version: {version}\nThis version requires some SQL dependencies to "
|
||||
"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 "
|
||||
"`ModuleNotFoundError: No module named '_sqlite3'`\n"
|
||||
"You will need to reinstall "
|
||||
"Python with SQL dependencies installed.\n\n"
|
||||
f"`{_ERROR}`.\n"
|
||||
"You will need to install the missing SQL dependency.\n\n"
|
||||
).format(version=__version__)
|
||||
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)
|
||||
|
||||
async def _migrate_config(self, from_version: int, to_version: int):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user