[Core] Utilize consume rest, Union (#2407)

This commit is contained in:
zephyrkul 2019-02-12 20:11:22 -07:00 committed by Toby Harradine
parent 9869f95bd6
commit 820be2a0ae

View File

@ -1125,7 +1125,7 @@ class Core(commands.Cog, CoreLogic):
@commands.command() @commands.command()
@checks.is_owner() @checks.is_owner()
async def backup(self, ctx: commands.Context, backup_path: str = None): async def backup(self, ctx: commands.Context, *, backup_path: str = None):
"""Creates a backup of all data for the instance.""" """Creates a backup of all data for the instance."""
from redbot.core.data_manager import basic_config, instance_name from redbot.core.data_manager import basic_config, instance_name
from redbot.core.drivers.red_json import JSON from redbot.core.drivers.red_json import JSON
@ -1368,7 +1368,7 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(box(page)) await ctx.send(box(page))
@whitelist.command(name="remove") @whitelist.command(name="remove")
async def whitelist_remove(self, ctx: commands.Context, user: discord.User): async def whitelist_remove(self, ctx: commands.Context, *, user: discord.User):
""" """
Removes user from whitelist. Removes user from whitelist.
""" """
@ -1401,7 +1401,7 @@ class Core(commands.Cog, CoreLogic):
pass pass
@blacklist.command(name="add") @blacklist.command(name="add")
async def blacklist_add(self, ctx: commands.Context, user: discord.User): async def blacklist_add(self, ctx: commands.Context, *, user: discord.User):
""" """
Adds a user to the blacklist. Adds a user to the blacklist.
""" """
@ -1430,7 +1430,7 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(box(page)) await ctx.send(box(page))
@blacklist.command(name="remove") @blacklist.command(name="remove")
async def blacklist_remove(self, ctx: commands.Context, user: discord.User): async def blacklist_remove(self, ctx: commands.Context, *, user: discord.User):
""" """
Removes user from blacklist. Removes user from blacklist.
""" """
@ -1464,17 +1464,13 @@ class Core(commands.Cog, CoreLogic):
pass pass
@localwhitelist.command(name="add") @localwhitelist.command(name="add")
async def localwhitelist_add(self, ctx: commands.Context, *, user_or_role: str): async def localwhitelist_add(
self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
):
""" """
Adds a user or role to the whitelist. Adds a user or role to the whitelist.
""" """
try: user = isinstance(user_or_role, discord.Member)
obj = await commands.MemberConverter().convert(ctx, user_or_role)
except commands.BadArgument:
obj = await commands.RoleConverter().convert(ctx, user_or_role)
user = False
else:
user = True
async with ctx.bot.db.guild(ctx.guild).whitelist() as curr_list: async with ctx.bot.db.guild(ctx.guild).whitelist() as curr_list:
if obj.id not in curr_list: if obj.id not in curr_list:
curr_list.append(obj.id) curr_list.append(obj.id)
@ -1499,17 +1495,13 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(box(page)) await ctx.send(box(page))
@localwhitelist.command(name="remove") @localwhitelist.command(name="remove")
async def localwhitelist_remove(self, ctx: commands.Context, *, user_or_role: str): async def localwhitelist_remove(
self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
):
""" """
Removes user or role from whitelist. Removes user or role from whitelist.
""" """
try: user = isinstance(user_or_role, discord.Member)
obj = await commands.MemberConverter().convert(ctx, user_or_role)
except commands.BadArgument:
obj = await commands.RoleConverter().convert(ctx, user_or_role)
user = False
else:
user = True
removed = False removed = False
async with ctx.bot.db.guild(ctx.guild).whitelist() as curr_list: async with ctx.bot.db.guild(ctx.guild).whitelist() as curr_list:
@ -1546,17 +1538,13 @@ class Core(commands.Cog, CoreLogic):
pass pass
@localblacklist.command(name="add") @localblacklist.command(name="add")
async def localblacklist_add(self, ctx: commands.Context, *, user_or_role: str): async def localblacklist_add(
self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
):
""" """
Adds a user or role to the blacklist. Adds a user or role to the blacklist.
""" """
try: user = isinstance(user_or_role, discord.Member)
obj = await commands.MemberConverter().convert(ctx, user_or_role)
except commands.BadArgument:
obj = await commands.RoleConverter().convert(ctx, user_or_role)
user = False
else:
user = True
if user and await ctx.bot.is_owner(obj): if user and await ctx.bot.is_owner(obj):
await ctx.send(_("You cannot blacklist an owner!")) await ctx.send(_("You cannot blacklist an owner!"))
@ -1586,18 +1574,14 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(box(page)) await ctx.send(box(page))
@localblacklist.command(name="remove") @localblacklist.command(name="remove")
async def localblacklist_remove(self, ctx: commands.Context, *, user_or_role: str): async def localblacklist_remove(
self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
):
""" """
Removes user or role from blacklist. Removes user or role from blacklist.
""" """
removed = False removed = False
try: user = isinstance(user_or_role, discord.Member)
obj = await commands.MemberConverter().convert(ctx, user_or_role)
except commands.BadArgument:
obj = await commands.RoleConverter().convert(ctx, user_or_role)
user = False
else:
user = True
async with ctx.bot.db.guild(ctx.guild).blacklist() as curr_list: async with ctx.bot.db.guild(ctx.guild).blacklist() as curr_list:
if obj.id in curr_list: if obj.id in curr_list:
@ -1794,7 +1778,7 @@ class Core(commands.Cog, CoreLogic):
@autoimmune_group.command(name="add") @autoimmune_group.command(name="add")
async def autoimmune_add( async def autoimmune_add(
self, ctx: commands.Context, user_or_role: Union[discord.Member, discord.Role] self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
): ):
""" """
Makes a user or roles immune from automated moderation actions Makes a user or roles immune from automated moderation actions
@ -1807,7 +1791,7 @@ class Core(commands.Cog, CoreLogic):
@autoimmune_group.command(name="remove") @autoimmune_group.command(name="remove")
async def autoimmune_remove( async def autoimmune_remove(
self, ctx: commands.Context, user_or_role: Union[discord.Member, discord.Role] self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
): ):
""" """
Makes a user or roles immune from automated moderation actions Makes a user or roles immune from automated moderation actions
@ -1820,7 +1804,7 @@ class Core(commands.Cog, CoreLogic):
@autoimmune_group.command(name="isimmune") @autoimmune_group.command(name="isimmune")
async def autoimmune_checkimmune( async def autoimmune_checkimmune(
self, ctx: commands.Context, user_or_role: Union[discord.Member, discord.Role] self, ctx: commands.Context, *, user_or_role: Union[discord.Member, discord.Role]
): ):
""" """
Checks if a user or role would be considered immune from automated actions Checks if a user or role would be considered immune from automated actions