mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -05:00
Merge branch 'V3/release/3.0.0' into V3/develop
# Conflicts: # redbot/cogs/customcom/customcom.py # redbot/core/errors.py
This commit is contained in:
@@ -148,5 +148,5 @@ class VersionInfo:
|
||||
)
|
||||
|
||||
|
||||
__version__ = "3.0.0rc1.post1"
|
||||
__version__ = "3.0.0rc2"
|
||||
version_info = VersionInfo.from_str(__version__)
|
||||
|
||||
@@ -4,9 +4,10 @@ from typing import Union, List, Optional
|
||||
|
||||
import discord
|
||||
|
||||
from redbot.core import Config
|
||||
from . import Config, errors
|
||||
|
||||
__all__ = [
|
||||
"MAX_BALANCE",
|
||||
"Account",
|
||||
"get_balance",
|
||||
"set_balance",
|
||||
@@ -26,6 +27,8 @@ __all__ = [
|
||||
"set_default_balance",
|
||||
]
|
||||
|
||||
MAX_BALANCE = 2 ** 63 - 1
|
||||
|
||||
_DEFAULT_GLOBAL = {
|
||||
"is_global": False,
|
||||
"bank_name": "Twentysix bank",
|
||||
@@ -170,10 +173,22 @@ async def set_balance(member: discord.Member, amount: int) -> int:
|
||||
------
|
||||
ValueError
|
||||
If attempting to set the balance to a negative number.
|
||||
BalanceTooHigh
|
||||
If attempting to set the balance to a value greater than
|
||||
``bank.MAX_BALANCE``
|
||||
|
||||
"""
|
||||
if amount < 0:
|
||||
raise ValueError("Not allowed to have negative balance.")
|
||||
if amount > MAX_BALANCE:
|
||||
currency = (
|
||||
await get_currency_name()
|
||||
if await is_global()
|
||||
else await get_currency_name(member.guild)
|
||||
)
|
||||
raise errors.BalanceTooHigh(
|
||||
user=member.display_name, max_balance=MAX_BALANCE, currency_name=currency
|
||||
)
|
||||
if await is_global():
|
||||
group = _conf.user(member)
|
||||
else:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import inspect
|
||||
import os
|
||||
import logging
|
||||
from collections import Counter
|
||||
@@ -236,20 +237,13 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
|
||||
if cog is None:
|
||||
return
|
||||
|
||||
for when in ("before", "after"):
|
||||
for cls in inspect.getmro(cog.__class__):
|
||||
try:
|
||||
hook = getattr(cog, f"_{cog.__class__.__name__}__red_permissions_{when}")
|
||||
hook = getattr(cog, f"_{cls.__name__}__permissions_hook")
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
self.remove_permissions_hook(hook, when)
|
||||
|
||||
try:
|
||||
hook = getattr(cog, f"_{cog.__class__.__name__}__red_permissions_before")
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
self.remove_permissions_hook(hook)
|
||||
self.remove_permissions_hook(hook)
|
||||
|
||||
super().remove_cog(cogname)
|
||||
|
||||
@@ -390,10 +384,17 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
|
||||
)
|
||||
if not hasattr(cog, "requires"):
|
||||
commands.Cog.__init__(cog)
|
||||
|
||||
for cls in inspect.getmro(cog.__class__):
|
||||
try:
|
||||
hook = getattr(cog, f"_{cls.__name__}__permissions_hook")
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
self.add_permissions_hook(hook)
|
||||
|
||||
for attr in dir(cog):
|
||||
_attr = getattr(cog, attr)
|
||||
if attr == f"_{cog.__class__.__name__}__permissions_hook":
|
||||
self.add_permissions_hook(_attr)
|
||||
if isinstance(_attr, discord.ext.commands.Command) and not isinstance(
|
||||
_attr, commands.Command
|
||||
):
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import importlib.machinery
|
||||
from typing import Optional
|
||||
|
||||
import discord
|
||||
|
||||
from .i18n import Translator
|
||||
|
||||
_ = Translator(__name__, __file__)
|
||||
|
||||
|
||||
class RedError(Exception):
|
||||
@@ -21,3 +28,24 @@ class CogLoadError(RedError):
|
||||
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=self.max_balance, currency=self.currency_name
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user