mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
* Add command to remove dead members from bank
* Add a global check
* Added a FIXME so `bank_local_clean` is updated once bulk-update is implemented
Added a brief warning to warn devs not to use the `_get_base_group` as it can mess up their config files
Removed a redundant existence check
* Updated commit to reflect changes requested in review
* Updated commit to reflect changes requested in review
* 🤦
* Return command to run with user id so we don't worry about safeguarding the command agaisn't invalid formats
* Braaaainnn
Removed aliases that used old naming scheme
* TL:DR Added global bank support, and rework permissions
Renamed `bank_local_clean` to `bank_prune`
Added support for global banks to `bank_prune`
`bank_prune` will now raise `BankPruneError` if trying to prune a local bank and `guild` is not supplied
Renamed `cleanup` subgroup to `prune`
`prune` subgroup will have 3 commands:
`user` : Deletes the bank account for the specified member : Accepts `Union[discord.Member, discord.User, int]`
`global` : Prune global bank accounts for all users who no longer share a server with the bot
`local` : Prune local bank accounts for all users who are no longer in the guild
Changed check for `prune` subgroup to be `@check_global_setting_admin()`
[p]bank prune local : Can be run by Guild owners only
[p]bank prune global : Can be run by Bot Owner only
[p]bank prune user : Can be run by Admins, Guild owners and Bot Owner
* Yikes ... Updated kwarg name
* Fixed unexpected unindent: docstring of redbot.core.bank.bank_prune:14:Field list ends without a blank line
* ...
* 3rd time lucky?
* 4th time lucky?
* Fix Docstring
* Initial commit to address review by Flame
* Updated code to reflect Flame's comments
* Skip pruning of unavailable guilds
* Fixed typo in string
* *sigh* black is the bane of my existence
* addressed Flames commends
Fixed [p]bank prune user, When run via DM it will now return an error message to the user (Thanks jack1142)
* Time to get some sleep
* 'DM' > 'DMs' in string
* Add towncrier entries
Signed-off-by: Draper <guyreis96@gmail.com>
* Update to reflect Flame's review
Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>
90 lines
2.5 KiB
Python
90 lines
2.5 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 BankPruneError(BankError):
|
|
"""Raised when trying to prune a local bank and no server is specified."""
|
|
|
|
|
|
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())
|
|
|
|
"""
|