Remove a large amount of fetch_user calls (#3075)

* Non-audio changes

* address Flame's feedback
This commit is contained in:
Michael H
2019-12-21 01:15:34 -05:00
committed by GitHub
parent b457f8d1c1
commit a36e95c286
6 changed files with 65 additions and 50 deletions

View File

@@ -1687,13 +1687,14 @@ class Core(commands.Cog, CoreLogic):
pass
@whitelist.command(name="add")
async def whitelist_add(self, ctx, user: discord.User):
async def whitelist_add(self, ctx, *, user: Union[discord.Member, int]):
"""
Adds a user to the whitelist.
"""
uid = getattr(user, "id", user)
async with ctx.bot._config.whitelist() as curr_list:
if user.id not in curr_list:
curr_list.append(user.id)
if uid not in curr_list:
curr_list.append(uid)
await ctx.send(_("User added to whitelist."))
@@ -1712,16 +1713,16 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(box(page))
@whitelist.command(name="remove")
async def whitelist_remove(self, ctx: commands.Context, *, user: discord.User):
async def whitelist_remove(self, ctx: commands.Context, *, user: Union[discord.Member, int]):
"""
Removes user from whitelist.
"""
removed = False
uid = getattr(user, "id", user)
async with ctx.bot._config.whitelist() as curr_list:
if user.id in curr_list:
if uid in curr_list:
removed = True
curr_list.remove(user.id)
curr_list.remove(uid)
if removed:
await ctx.send(_("User has been removed from whitelist."))
@@ -1745,7 +1746,7 @@ class Core(commands.Cog, CoreLogic):
pass
@blacklist.command(name="add")
async def blacklist_add(self, ctx: commands.Context, *, user: discord.User):
async def blacklist_add(self, ctx: commands.Context, *, user: Union[discord.Member, int]):
"""
Adds a user to the blacklist.
"""
@@ -1753,9 +1754,10 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(_("You cannot blacklist an owner!"))
return
uid = getattr(user, "id", user)
async with ctx.bot._config.blacklist() as curr_list:
if user.id not in curr_list:
curr_list.append(user.id)
if uid not in curr_list:
curr_list.append(uid)
await ctx.send(_("User added to blacklist."))
@@ -1774,16 +1776,17 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(box(page))
@blacklist.command(name="remove")
async def blacklist_remove(self, ctx: commands.Context, *, user: discord.User):
async def blacklist_remove(self, ctx: commands.Context, *, user: Union[discord.Member, int]):
"""
Removes user from blacklist.
"""
removed = False
uid = getattr(user, "id", user)
async with ctx.bot._config.blacklist() as curr_list:
if user.id in curr_list:
if uid in curr_list:
removed = True
curr_list.remove(user.id)
curr_list.remove(uid)
if removed:
await ctx.send(_("User has been removed from blacklist."))
@@ -1809,12 +1812,16 @@ class Core(commands.Cog, CoreLogic):
@localwhitelist.command(name="add")
async def localwhitelist_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, int]
):
"""
Adds a user or role to the whitelist.
"""
user = isinstance(user_or_role, discord.Member)
if isinstance(user_or_role, int):
user_or_role = discord.Object(id=user_or_role)
user = True
async with ctx.bot._config.guild(ctx.guild).whitelist() as curr_list:
if user_or_role.id not in curr_list:
curr_list.append(user_or_role.id)
@@ -1840,12 +1847,15 @@ class Core(commands.Cog, CoreLogic):
@localwhitelist.command(name="remove")
async def localwhitelist_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, int]
):
"""
Removes user or role from whitelist.
"""
user = isinstance(user_or_role, discord.Member)
if isinstance(user_or_role, int):
user_or_role = discord.Object(id=user_or_role)
user = True
removed = False
async with ctx.bot._config.guild(ctx.guild).whitelist() as curr_list:
@@ -1883,12 +1893,15 @@ class Core(commands.Cog, CoreLogic):
@localblacklist.command(name="add")
async def localblacklist_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, int]
):
"""
Adds a user or role to the blacklist.
"""
user = isinstance(user_or_role, discord.Member)
if isinstance(user_or_role, int):
user_or_role = discord.Object(id=user_or_role)
user = True
if user and await ctx.bot.is_owner(user_or_role):
await ctx.send(_("You cannot blacklist an owner!"))
@@ -1919,13 +1932,16 @@ class Core(commands.Cog, CoreLogic):
@localblacklist.command(name="remove")
async def localblacklist_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, int]
):
"""
Removes user or role from blacklist.
"""
removed = False
user = isinstance(user_or_role, discord.Member)
if isinstance(user_or_role, int):
user_or_role = discord.Object(id=user_or_role)
user = True
async with ctx.bot._config.guild(ctx.guild).blacklist() as curr_list:
if user_or_role.id in curr_list: