mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
[Bank] Allow Bot Owner/Guild Owners to remove invalid users from the bank (#2845)
* 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>
This commit is contained in:
@@ -3,12 +3,13 @@ import logging
|
||||
import random
|
||||
from collections import defaultdict, deque, namedtuple
|
||||
from enum import Enum
|
||||
from typing import cast, Iterable
|
||||
from typing import cast, Iterable, Union
|
||||
|
||||
import discord
|
||||
|
||||
from redbot.cogs.bank import check_global_setting_guildowner, check_global_setting_admin
|
||||
from redbot.core import Config, bank, commands, errors
|
||||
from redbot.cogs.mod.converters import RawUserIds
|
||||
from redbot.core import Config, bank, commands, errors, checks
|
||||
from redbot.core.i18n import Translator, cog_i18n
|
||||
from redbot.core.utils.chat_formatting import box, humanize_number
|
||||
from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
|
||||
@@ -257,6 +258,87 @@ class Economy(commands.Cog):
|
||||
)
|
||||
)
|
||||
|
||||
@_bank.group(name="prune")
|
||||
@check_global_setting_admin()
|
||||
async def _prune(self, ctx):
|
||||
"""Prune bank accounts."""
|
||||
pass
|
||||
|
||||
@_prune.command(name="local")
|
||||
@commands.guild_only()
|
||||
@checks.guildowner()
|
||||
async def _local(self, ctx, confirmation: bool = False):
|
||||
"""Prune bank accounts for users no longer in the server."""
|
||||
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.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."""
|
||||
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.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."""
|
||||
global_bank = await bank.is_global()
|
||||
if global_bank is False and ctx.guild is None:
|
||||
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.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):
|
||||
|
||||
Reference in New Issue
Block a user