[Core] Make core_commands.py comply with #4048 (#4138)

Co-authored-by: Draper <27962761+Drapersniper@users.noreply.github.com>
This commit is contained in:
Dav 2020-08-16 10:37:29 +00:00 committed by GitHub
parent 341fd254fb
commit 581bdaa496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2505,18 +2505,18 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
) )
await ctx.send(box(info)) await ctx.send(box(info))
@commands.group() @commands.group(aliases=["whitelist"])
@checks.is_owner() @checks.is_owner()
async def whitelist(self, ctx: commands.Context): async def allowlist(self, ctx: commands.Context):
""" """
Whitelist management commands. Allowlist management commands.
""" """
pass pass
@whitelist.command(name="add", usage="<user>...") @allowlist.command(name="add", usage="<user>...")
async def whitelist_add(self, ctx: commands.Context, *users: Union[discord.Member, int]): async def allowlist_add(self, ctx: commands.Context, *users: Union[discord.Member, int]):
""" """
Adds a user to the whitelist. Adds a user to the allowlist.
""" """
if not users: if not users:
await ctx.send_help() await ctx.send_help()
@ -2525,30 +2525,30 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
uids = {getattr(user, "id", user) for user in users} uids = {getattr(user, "id", user) for user in users}
await self.bot._whiteblacklist_cache.add_to_whitelist(None, uids) await self.bot._whiteblacklist_cache.add_to_whitelist(None, uids)
await ctx.send(_("Users added to whitelist.")) await ctx.send(_("Users added to allowlist."))
@whitelist.command(name="list") @allowlist.command(name="list")
async def whitelist_list(self, ctx: commands.Context): async def allowlist_list(self, ctx: commands.Context):
""" """
Lists whitelisted users. Lists users on the allowlist.
""" """
curr_list = await ctx.bot._config.whitelist() curr_list = await ctx.bot._config.whitelist()
if not curr_list: if not curr_list:
await ctx.send("Whitelist is empty.") await ctx.send("Allowlist is empty.")
return return
msg = _("Whitelisted Users:") msg = _("Users on allowlist:")
for user in curr_list: for user in curr_list:
msg += "\n\t- {}".format(user) msg += "\n\t- {}".format(user)
for page in pagify(msg): for page in pagify(msg):
await ctx.send(box(page)) await ctx.send(box(page))
@whitelist.command(name="remove", usage="<user>...") @allowlist.command(name="remove", usage="<user>...")
async def whitelist_remove(self, ctx: commands.Context, *users: Union[discord.Member, int]): async def allowlist_remove(self, ctx: commands.Context, *users: Union[discord.Member, int]):
""" """
Removes user from whitelist. Removes user from the allowlist.
""" """
if not users: if not users:
await ctx.send_help() await ctx.send_help()
@ -2557,28 +2557,28 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
uids = {getattr(user, "id", user) for user in users} uids = {getattr(user, "id", user) for user in users}
await self.bot._whiteblacklist_cache.remove_from_whitelist(None, uids) await self.bot._whiteblacklist_cache.remove_from_whitelist(None, uids)
await ctx.send(_("Users have been removed from whitelist.")) await ctx.send(_("Users have been removed from the allowlist."))
@whitelist.command(name="clear") @allowlist.command(name="clear")
async def whitelist_clear(self, ctx: commands.Context): async def allowlist_clear(self, ctx: commands.Context):
""" """
Clears the whitelist. Clears the allowlist.
""" """
await self.bot._whiteblacklist_cache.clear_whitelist() await self.bot._whiteblacklist_cache.clear_whitelist()
await ctx.send(_("Whitelist has been cleared.")) await ctx.send(_("Allowlist has been cleared."))
@commands.group() @commands.group(aliases=["blacklist", "denylist"])
@checks.is_owner() @checks.is_owner()
async def blacklist(self, ctx: commands.Context): async def blocklist(self, ctx: commands.Context):
""" """
Blacklist management commands. Blocklist management commands.
""" """
pass pass
@blacklist.command(name="add", usage="<user>...") @blocklist.command(name="add", usage="<user>...")
async def blacklist_add(self, ctx: commands.Context, *users: Union[discord.Member, int]): async def blocklist_add(self, ctx: commands.Context, *users: Union[discord.Member, int]):
""" """
Adds a user to the blacklist. Adds a user to the blocklist.
""" """
if not users: if not users:
await ctx.send_help() await ctx.send_help()
@ -2590,36 +2590,36 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
else: else:
user_obj = user user_obj = user
if await ctx.bot.is_owner(user_obj): if await ctx.bot.is_owner(user_obj):
await ctx.send(_("You cannot blacklist an owner!")) await ctx.send(_("You cannot add an owner to the blocklist!"))
return return
uids = {getattr(user, "id", user) for user in users} uids = {getattr(user, "id", user) for user in users}
await self.bot._whiteblacklist_cache.add_to_blacklist(None, uids) await self.bot._whiteblacklist_cache.add_to_blacklist(None, uids)
await ctx.send(_("User added to blacklist.")) await ctx.send(_("User added to blocklist."))
@blacklist.command(name="list") @blocklist.command(name="list")
async def blacklist_list(self, ctx: commands.Context): async def blocklist_list(self, ctx: commands.Context):
""" """
Lists blacklisted users. Lists users on the blocklist.
""" """
curr_list = await self.bot._whiteblacklist_cache.get_blacklist(None) curr_list = await self.bot._whiteblacklist_cache.get_blacklist(None)
if not curr_list: if not curr_list:
await ctx.send("Blacklist is empty.") await ctx.send("Blocklist is empty.")
return return
msg = _("Blacklisted Users:") msg = _("Users on blocklist:")
for user in curr_list: for user in curr_list:
msg += "\n\t- {}".format(user) msg += "\n\t- {}".format(user)
for page in pagify(msg): for page in pagify(msg):
await ctx.send(box(page)) await ctx.send(box(page))
@blacklist.command(name="remove", usage="<user>...") @blocklist.command(name="remove", usage="<user>...")
async def blacklist_remove(self, ctx: commands.Context, *users: Union[discord.Member, int]): async def blocklist_remove(self, ctx: commands.Context, *users: Union[discord.Member, int]):
""" """
Removes user from blacklist. Removes user from the blocklist.
""" """
if not users: if not users:
await ctx.send_help() await ctx.send_help()
@ -2628,31 +2628,31 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
uids = {getattr(user, "id", user) for user in users} uids = {getattr(user, "id", user) for user in users}
await self.bot._whiteblacklist_cache.remove_from_blacklist(None, uids) await self.bot._whiteblacklist_cache.remove_from_blacklist(None, uids)
await ctx.send(_("Users have been removed from blacklist.")) await ctx.send(_("Users have been removed from blocklist."))
@blacklist.command(name="clear") @blocklist.command(name="clear")
async def blacklist_clear(self, ctx: commands.Context): async def blocklist_clear(self, ctx: commands.Context):
""" """
Clears the blacklist. Clears the blocklist.
""" """
await self.bot._whiteblacklist_cache.clear_blacklist() await self.bot._whiteblacklist_cache.clear_blacklist()
await ctx.send(_("Blacklist has been cleared.")) await ctx.send(_("Blocklist has been cleared."))
@commands.group() @commands.group(aliases=["localwhitelist"])
@commands.guild_only() @commands.guild_only()
@checks.admin_or_permissions(administrator=True) @checks.admin_or_permissions(administrator=True)
async def localwhitelist(self, ctx: commands.Context): async def localallowlist(self, ctx: commands.Context):
""" """
Whitelist management commands. Server specific allowlist management commands.
""" """
pass pass
@localwhitelist.command(name="add", usage="<user_or_role>...") @localallowlist.command(name="add", usage="<user_or_role>...")
async def localwhitelist_add( async def localallowlist_add(
self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int] self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int]
): ):
""" """
Adds a user or role to the whitelist. Adds a user or role to the server allowlist.
""" """
if not users_or_roles: if not users_or_roles:
await ctx.send_help() await ctx.send_help()
@ -2669,22 +2669,22 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
_( _(
"I cannot allow you to do this, as it would " "I cannot allow you to do this, as it would "
"remove your ability to run commands, " "remove your ability to run commands, "
"please ensure to add yourself to the whitelist first." "please ensure to add yourself to the allowlist first."
) )
) )
await self.bot._whiteblacklist_cache.add_to_whitelist(ctx.guild, uids) await self.bot._whiteblacklist_cache.add_to_whitelist(ctx.guild, uids)
await ctx.send(_("{names} added to whitelist.").format(names=humanize_list(names))) await ctx.send(_("{names} added to allowlist.").format(names=humanize_list(names)))
@localwhitelist.command(name="list") @localallowlist.command(name="list")
async def localwhitelist_list(self, ctx: commands.Context): async def localallowlist_list(self, ctx: commands.Context):
""" """
Lists whitelisted users and roles. Lists users and roles on the server allowlist.
""" """
curr_list = await self.bot._whiteblacklist_cache.get_whitelist(ctx.guild) curr_list = await self.bot._whiteblacklist_cache.get_whitelist(ctx.guild)
if not curr_list: if not curr_list:
await ctx.send("Local whitelist is empty.") await ctx.send("Server allowlist is empty.")
return return
msg = _("Whitelisted Users and roles:") msg = _("Whitelisted Users and roles:")
@ -2694,12 +2694,12 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
for page in pagify(msg): for page in pagify(msg):
await ctx.send(box(page)) await ctx.send(box(page))
@localwhitelist.command(name="remove", usage="<user_or_role>...") @localallowlist.command(name="remove", usage="<user_or_role>...")
async def localwhitelist_remove( async def localallowlist_remove(
self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int] self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int]
): ):
""" """
Removes user or role from whitelist. Removes user or role from the allowlist.
""" """
if not users_or_roles: if not users_or_roles:
await ctx.send_help() await ctx.send_help()
@ -2721,32 +2721,32 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
await self.bot._whiteblacklist_cache.remove_from_whitelist(ctx.guild, uids) await self.bot._whiteblacklist_cache.remove_from_whitelist(ctx.guild, uids)
await ctx.send( await ctx.send(
_("{names} removed from the local whitelist.").format(names=humanize_list(names)) _("{names} removed from the server allowlist.").format(names=humanize_list(names))
) )
@localwhitelist.command(name="clear") @localallowlist.command(name="clear")
async def localwhitelist_clear(self, ctx: commands.Context): async def localallowlist_clear(self, ctx: commands.Context):
""" """
Clears the whitelist. Clears the allowlist.
""" """
await self.bot._whiteblacklist_cache.clear_whitelist(ctx.guild) await self.bot._whiteblacklist_cache.clear_whitelist(ctx.guild)
await ctx.send(_("Local whitelist has been cleared.")) await ctx.send(_("Server allowlist has been cleared."))
@commands.group() @commands.group(aliases=["localblacklist"])
@commands.guild_only() @commands.guild_only()
@checks.admin_or_permissions(administrator=True) @checks.admin_or_permissions(administrator=True)
async def localblacklist(self, ctx: commands.Context): async def localblocklist(self, ctx: commands.Context):
""" """
Blacklist management commands. Server specific blocklist management commands.
""" """
pass pass
@localblacklist.command(name="add", usage="<user_or_role>...") @localblocklist.command(name="add", usage="<user_or_role>...")
async def localblacklist_add( async def localblocklist_add(
self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int] self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int]
): ):
""" """
Adds a user or role to the blacklist. Adds a user or role to the blocklist.
""" """
if not users_or_roles: if not users_or_roles:
await ctx.send_help() await ctx.send_help()
@ -2755,31 +2755,31 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
for user_or_role in users_or_roles: for user_or_role in users_or_roles:
uid = discord.Object(id=getattr(user_or_role, "id", user_or_role)) uid = discord.Object(id=getattr(user_or_role, "id", user_or_role))
if uid.id == ctx.author.id: if uid.id == ctx.author.id:
await ctx.send(_("You cannot blacklist yourself!")) await ctx.send(_("You cannot add yourself to the blocklist!"))
return return
if uid.id == ctx.guild.owner_id and not await ctx.bot.is_owner(ctx.author): if uid.id == ctx.guild.owner_id and not await ctx.bot.is_owner(ctx.author):
await ctx.send(_("You cannot blacklist the guild owner!")) await ctx.send(_("You cannot add the guild owner to the blocklist!"))
return return
if await ctx.bot.is_owner(uid): if await ctx.bot.is_owner(uid):
await ctx.send(_("You cannot blacklist a bot owner!")) await ctx.send(_("You cannot add a bot owner to the blocklist!"))
return return
names = [getattr(u_or_r, "name", u_or_r) for u_or_r in users_or_roles] names = [getattr(u_or_r, "name", u_or_r) for u_or_r in users_or_roles]
uids = {getattr(u_or_r, "id", u_or_r) for u_or_r in users_or_roles} uids = {getattr(u_or_r, "id", u_or_r) for u_or_r in users_or_roles}
await self.bot._whiteblacklist_cache.add_to_blacklist(ctx.guild, uids) await self.bot._whiteblacklist_cache.add_to_blacklist(ctx.guild, uids)
await ctx.send( await ctx.send(
_("{names} added to the local blacklist.").format(names=humanize_list(names)) _("{names} added to the server blocklist.").format(names=humanize_list(names))
) )
@localblacklist.command(name="list") @localblocklist.command(name="list")
async def localblacklist_list(self, ctx: commands.Context): async def localblocklist_list(self, ctx: commands.Context):
""" """
Lists blacklisted users and roles. Lists users and roles on the blocklist.
""" """
curr_list = await self.bot._whiteblacklist_cache.get_blacklist(ctx.guild) curr_list = await self.bot._whiteblacklist_cache.get_blacklist(ctx.guild)
if not curr_list: if not curr_list:
await ctx.send("Local blacklist is empty.") await ctx.send("Server blocklist is empty.")
return return
msg = _("Blacklisted Users and Roles:") msg = _("Blacklisted Users and Roles:")
@ -2789,12 +2789,12 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
for page in pagify(msg): for page in pagify(msg):
await ctx.send(box(page)) await ctx.send(box(page))
@localblacklist.command(name="remove", usage="<user_or_role>...") @localblocklist.command(name="remove", usage="<user_or_role>...")
async def localblacklist_remove( async def localblocklist_remove(
self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int] self, ctx: commands.Context, *users_or_roles: Union[discord.Member, discord.Role, int]
): ):
""" """
Removes user or role from blacklist. Removes user or role from blocklist.
""" """
if not users_or_roles: if not users_or_roles:
await ctx.send_help() await ctx.send_help()
@ -2805,16 +2805,16 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
await self.bot._whiteblacklist_cache.remove_from_blacklist(ctx.guild, uids) await self.bot._whiteblacklist_cache.remove_from_blacklist(ctx.guild, uids)
await ctx.send( await ctx.send(
_("{names} removed from the local blacklist.").format(names=humanize_list(names)) _("{names} removed from the server blocklist.").format(names=humanize_list(names))
) )
@localblacklist.command(name="clear") @localblocklist.command(name="clear")
async def localblacklist_clear(self, ctx: commands.Context): async def localblocklist_clear(self, ctx: commands.Context):
""" """
Clears the blacklist. Clears the server blocklist.
""" """
await self.bot._whiteblacklist_cache.clear_blacklist(ctx.guild) await self.bot._whiteblacklist_cache.clear_blacklist(ctx.guild)
await ctx.send(_("Local blacklist has been cleared.")) await ctx.send(_("Server blocklist has been cleared."))
@checks.guildowner_or_permissions(administrator=True) @checks.guildowner_or_permissions(administrator=True)
@commands.group(name="command") @commands.group(name="command")