mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
* 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> * 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> * 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> * Rename method 🤦 Signed-off-by: Guy <guyreis96@gmail.com> * Updated this to be aware of #2925 Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Addressed Flames review + Fixed 1 bug in errors.py + `[p]leaderboard` and `[p]bank balance` will set the users balance to max balance if the bank maxbal is lower than the previous user balance Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Missed this clarification Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * address Flames review Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>
86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
import importlib.machinery
|
|
|
|
import discord
|
|
|
|
from redbot.core.utils.chat_formatting import humanize_number
|
|
from .i18n import Translator
|
|
|
|
_ = Translator(__name__, __file__)
|
|
|
|
|
|
class RedError(Exception):
|
|
"""Base error class for Red-related errors."""
|
|
|
|
|
|
class PackageAlreadyLoaded(RedError):
|
|
"""Raised when trying to load an already-loaded package."""
|
|
|
|
def __init__(self, spec: importlib.machinery.ModuleSpec, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.spec: importlib.machinery.ModuleSpec = spec
|
|
|
|
def __str__(self) -> str:
|
|
return f"There is already a package named {self.spec.name.split('.')[-1]} loaded"
|
|
|
|
|
|
class CogLoadError(RedError):
|
|
"""Raised by a cog when it cannot load itself.
|
|
The message will be send to the user."""
|
|
|
|
pass
|
|
|
|
|
|
class BankError(RedError):
|
|
"""Base error class for bank-related errors."""
|
|
|
|
|
|
class BalanceTooHigh(BankError, OverflowError):
|
|
"""Raised when trying to set a user's balance to higher than the maximum."""
|
|
|
|
def __init__(
|
|
self, user: discord.abc.User, max_balance: int, currency_name: str, *args, **kwargs
|
|
):
|
|
super().__init__(*args, **kwargs)
|
|
self.user = user
|
|
self.max_balance = max_balance
|
|
self.currency_name = currency_name
|
|
|
|
def __str__(self) -> str:
|
|
return _("{user}'s balance cannot rise above {max} {currency}.").format(
|
|
user=self.user, max=humanize_number(self.max_balance), currency=self.currency_name
|
|
)
|
|
|
|
|
|
class MissingExtraRequirements(RedError):
|
|
"""Raised when an extra requirement is missing but required."""
|
|
|
|
|
|
class ConfigError(RedError):
|
|
"""Error in a Config operation."""
|
|
|
|
|
|
class StoredTypeError(ConfigError, TypeError):
|
|
"""A TypeError pertaining to stored Config data.
|
|
|
|
This error may arise when, for example, trying to increment a value
|
|
which is not a number, or trying to toggle a value which is not a
|
|
boolean.
|
|
"""
|
|
|
|
|
|
class CannotSetSubfield(StoredTypeError):
|
|
"""Tried to set sub-field of an invalid data structure.
|
|
|
|
This would occur in the following example::
|
|
|
|
>>> import asyncio
|
|
>>> from redbot.core import Config
|
|
>>> config = Config.get_conf(None, 1234, cog_name="Example")
|
|
>>> async def example():
|
|
... await config.foo.set(True)
|
|
... await config.set_raw("foo", "bar", False) # Should raise here
|
|
...
|
|
>>> asyncio.run(example())
|
|
|
|
"""
|