mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-07 09:52:30 -05:00
Move modlogset/bankset commands to core (#4486)
* Move bankset and modlogset to core commands * Move prune over too * Finish moving prune * Move [p]economyset registeramount to [p]bankset registeramount * style fix * Fix circular import issue with another breaking change * Apparently I missed a conflict and git still let me commit... * Really git? * Rename RawUserIds -> RawUserIdConverter, improve documentation * Improve documentation of `is_owner_if_bank_global()` * MENTION_REGEX -> USER_MENTION_REGEX * Add 'bank.' prefix * Fix command examples in docstrings * Missing docstring change from `bankset prune` * Missing changes for commands in modlogset * Update docs * Remove duplicated info in `economyset showsettings` * Fix toctree in index.rst * Add command group prefixes to names of functions for bankset/modlogset * Remaining string updates due to command name changes * Ensure that the bank folder is actually gone Co-authored-by: palmtree5 <palmtree5+3577255@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -8,8 +8,6 @@ from typing import cast, Iterable, Union, Literal
|
||||
|
||||
import discord
|
||||
|
||||
from redbot.cogs.bank import is_owner_if_bank_global
|
||||
from redbot.cogs.mod.converters import RawUserIds
|
||||
from redbot.core import Config, bank, commands, errors, checks
|
||||
from redbot.core.commands.converter import TimedeltaConverter
|
||||
from redbot.core.bot import Red
|
||||
@@ -240,7 +238,7 @@ class Economy(commands.Cog):
|
||||
)
|
||||
)
|
||||
|
||||
@is_owner_if_bank_global()
|
||||
@bank.is_owner_if_bank_global()
|
||||
@checks.admin_or_permissions(manage_guild=True)
|
||||
@_bank.command(name="set")
|
||||
async def _set(self, ctx: commands.Context, to: discord.Member, creds: SetParser):
|
||||
@@ -291,151 +289,6 @@ class Economy(commands.Cog):
|
||||
else:
|
||||
await ctx.send(msg)
|
||||
|
||||
@is_owner_if_bank_global()
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
@_bank.command()
|
||||
async def reset(self, ctx, confirmation: bool = False):
|
||||
"""Delete all bank accounts.
|
||||
|
||||
Examples:
|
||||
- `[p]bank reset` - Did not confirm. Shows the help message.
|
||||
- `[p]bank reset yes`
|
||||
|
||||
**Arguments**
|
||||
|
||||
- `<confirmation>` This will default to false unless specified.
|
||||
"""
|
||||
if confirmation is False:
|
||||
await ctx.send(
|
||||
_(
|
||||
"This will delete all bank accounts for {scope}.\nIf you're sure, type "
|
||||
"`{prefix}bank reset yes`"
|
||||
).format(
|
||||
scope=self.bot.user.name if await bank.is_global() else _("this server"),
|
||||
prefix=ctx.clean_prefix,
|
||||
)
|
||||
)
|
||||
else:
|
||||
await bank.wipe_bank(guild=ctx.guild)
|
||||
await ctx.send(
|
||||
_("All bank accounts for {scope} have been deleted.").format(
|
||||
scope=self.bot.user.name if await bank.is_global() else _("this server")
|
||||
)
|
||||
)
|
||||
|
||||
@is_owner_if_bank_global()
|
||||
@checks.admin_or_permissions(manage_guild=True)
|
||||
@_bank.group(name="prune")
|
||||
async def _prune(self, ctx):
|
||||
"""Base command for pruning bank accounts."""
|
||||
pass
|
||||
|
||||
@_prune.command(name="server", aliases=["guild", "local"])
|
||||
@commands.guild_only()
|
||||
@checks.guildowner()
|
||||
async def _local(self, ctx, confirmation: bool = False):
|
||||
"""Prune bank accounts for users no longer in the server.
|
||||
|
||||
Cannot be used with a global bank. See `[p]bank prune global`.
|
||||
|
||||
Examples:
|
||||
- `[p]bank prune server` - Did not confirm. Shows the help message.
|
||||
- `[p]bank prune server yes`
|
||||
|
||||
**Arguments**
|
||||
|
||||
- `<confirmation>` This will default to false unless specified.
|
||||
"""
|
||||
global_bank = await bank.is_global()
|
||||
if global_bank is True:
|
||||
return await ctx.send(_("This command cannot be used with a global bank."))
|
||||
|
||||
if confirmation is False:
|
||||
await ctx.send(
|
||||
_(
|
||||
"This will delete all bank accounts for users no longer in this server."
|
||||
"\nIf you're sure, type "
|
||||
"`{prefix}bank prune local yes`"
|
||||
).format(prefix=ctx.clean_prefix)
|
||||
)
|
||||
else:
|
||||
await bank.bank_prune(self.bot, guild=ctx.guild)
|
||||
await ctx.send(
|
||||
_("Bank accounts for users no longer in this server have been deleted.")
|
||||
)
|
||||
|
||||
@_prune.command(name="global")
|
||||
@checks.is_owner()
|
||||
async def _global(self, ctx, confirmation: bool = False):
|
||||
"""Prune bank accounts for users who no longer share a server with the bot.
|
||||
|
||||
Cannot be used without a global bank. See `[p]bank prune server`.
|
||||
|
||||
Examples:
|
||||
- `[p]bank prune global` - Did not confirm. Shows the help message.
|
||||
- `[p]bank prune global yes`
|
||||
|
||||
**Arguments**
|
||||
|
||||
- `<confirmation>` This will default to false unless specified.
|
||||
"""
|
||||
global_bank = await bank.is_global()
|
||||
if global_bank is False:
|
||||
return await ctx.send(_("This command cannot be used with a local bank."))
|
||||
|
||||
if confirmation is False:
|
||||
await ctx.send(
|
||||
_(
|
||||
"This will delete all bank accounts for users "
|
||||
"who no longer share a server with the bot."
|
||||
"\nIf you're sure, type `{prefix}bank prune global yes`"
|
||||
).format(prefix=ctx.clean_prefix)
|
||||
)
|
||||
else:
|
||||
await bank.bank_prune(self.bot)
|
||||
await ctx.send(
|
||||
_(
|
||||
"Bank accounts for users who "
|
||||
"no longer share a server with the bot have been pruned."
|
||||
)
|
||||
)
|
||||
|
||||
@_prune.command(usage="<user> [confirmation=False]")
|
||||
async def user(
|
||||
self, ctx, member_or_id: Union[discord.Member, RawUserIds], confirmation: bool = False
|
||||
):
|
||||
"""Delete the bank account of a specified user.
|
||||
|
||||
Examples:
|
||||
- `[p]bank prune user @TwentySix` - Did not confirm. Shows the help message.
|
||||
- `[p]bank prune user @TwentySix yes`
|
||||
|
||||
**Arguments**
|
||||
|
||||
- `<user>` The user to delete the bank of. Takes mentions, names, and user ids.
|
||||
- `<confirmation>` This will default to false unless specified.
|
||||
"""
|
||||
if ctx.guild is None and not await bank.is_global():
|
||||
return await ctx.send(_("This command cannot be used in DMs with a local bank."))
|
||||
try:
|
||||
name = member_or_id.display_name
|
||||
uid = member_or_id.id
|
||||
except AttributeError:
|
||||
name = member_or_id
|
||||
uid = member_or_id
|
||||
|
||||
if confirmation is False:
|
||||
await ctx.send(
|
||||
_(
|
||||
"This will delete {name}'s bank account."
|
||||
"\nIf you're sure, type "
|
||||
"`{prefix}bank prune user {id} yes`"
|
||||
).format(prefix=ctx.clean_prefix, id=uid, name=name)
|
||||
)
|
||||
else:
|
||||
await bank.bank_prune(self.bot, guild=ctx.guild, user_id=uid)
|
||||
await ctx.send(_("The bank account for {name} has been pruned.").format(name=name))
|
||||
|
||||
@guild_only_check()
|
||||
@commands.command()
|
||||
async def payday(self, ctx: commands.Context):
|
||||
@@ -805,7 +658,7 @@ class Economy(commands.Cog):
|
||||
)
|
||||
|
||||
@guild_only_check()
|
||||
@is_owner_if_bank_global()
|
||||
@bank.is_owner_if_bank_global()
|
||||
@checks.admin_or_permissions(manage_guild=True)
|
||||
@commands.group()
|
||||
async def economyset(self, ctx: commands.Context):
|
||||
@@ -830,16 +683,12 @@ class Economy(commands.Cog):
|
||||
"Slot cooldown: {slot_time}\n"
|
||||
"Payday amount: {payday_amount}\n"
|
||||
"Payday cooldown: {payday_time}\n"
|
||||
"Amount given at account registration: {register_amount}\n"
|
||||
"Maximum allowed balance: {maximum_bal}"
|
||||
).format(
|
||||
slot_min=humanize_number(await conf.SLOT_MIN()),
|
||||
slot_max=humanize_number(await conf.SLOT_MAX()),
|
||||
slot_time=humanize_number(await conf.SLOT_TIME()),
|
||||
payday_time=humanize_number(await conf.PAYDAY_TIME()),
|
||||
payday_amount=humanize_number(await conf.PAYDAY_CREDITS()),
|
||||
register_amount=humanize_number(await bank.get_default_balance(guild)),
|
||||
maximum_bal=humanize_number(await bank.get_max_balance(guild)),
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -1043,34 +892,6 @@ class Economy(commands.Cog):
|
||||
)
|
||||
)
|
||||
|
||||
@economyset.command()
|
||||
async def registeramount(self, ctx: commands.Context, creds: int):
|
||||
"""Set the initial balance for new bank accounts.
|
||||
|
||||
Example:
|
||||
- `[p]economyset registeramount 5000`
|
||||
|
||||
**Arguments**
|
||||
|
||||
- `<creds>` The new initial balance amount. Default is 0.
|
||||
"""
|
||||
guild = ctx.guild
|
||||
max_balance = await bank.get_max_balance(ctx.guild)
|
||||
credits_name = await bank.get_currency_name(guild)
|
||||
try:
|
||||
await bank.set_default_balance(creds, guild)
|
||||
except ValueError:
|
||||
return await ctx.send(
|
||||
_("Amount must be greater than or equal to zero and less than {maxbal}.").format(
|
||||
maxbal=humanize_number(max_balance)
|
||||
)
|
||||
)
|
||||
await ctx.send(
|
||||
_("Registering an account will now give {num} {currency}.").format(
|
||||
num=humanize_number(creds), currency=credits_name
|
||||
)
|
||||
)
|
||||
|
||||
# What would I ever do without stackoverflow?
|
||||
@staticmethod
|
||||
def display_time(seconds, granularity=2):
|
||||
|
||||
Reference in New Issue
Block a user