[Mod] Remove tempban from data after unbanning (#2161)

Resolves #2160.

Also resolves another issue where the bot will error out when getting the guild's invites when it doesn't have the Manage Server permission.
This commit is contained in:
zephyrkul 2018-09-30 22:15:51 -06:00 committed by Toby Harradine
parent 0870403299
commit a9b328ff3c

View File

@ -715,10 +715,13 @@ class Mod(commands.Cog):
to send the newly unbanned user to send the newly unbanned user
:returns: :class:`Invite`""" :returns: :class:`Invite`"""
guild = ctx.guild guild = ctx.guild
if "VANITY_URL" in guild.features and guild.me.permissions.manage_guild: if guild.me.permissions.manage_guild:
# guild has a vanity url so use it as the one to send if "VANITY_URL" in guild.features:
return await guild.vanity_invite() # guild has a vanity url so use it as the one to send
invites = await guild.invites() return await guild.vanity_invite()
invites = await guild.invites()
else:
invites = []
for inv in invites: # Loop through the invites for the guild for inv in invites: # Loop through the invites for the guild
if not (inv.max_uses or inv.max_age or inv.temporary): if not (inv.max_uses or inv.max_age or inv.temporary):
# Invite is for the guild's default channel, # Invite is for the guild's default channel,
@ -1393,23 +1396,24 @@ class Mod(commands.Cog):
member = namedtuple("Member", "id guild") member = namedtuple("Member", "id guild")
while self == self.bot.get_cog("Mod"): while self == self.bot.get_cog("Mod"):
for guild in self.bot.guilds: for guild in self.bot.guilds:
guild_tempbans = await self.settings.guild(guild).current_tempbans() async with self.settings.guild(guild).current_tempbans() as guild_tempbans:
for uid in guild_tempbans: for uid in guild_tempbans:
unban_time = datetime.utcfromtimestamp( unban_time = datetime.utcfromtimestamp(
await self.settings.member(member(uid, guild)).banned_until() await self.settings.member(member(uid, guild)).banned_until()
) )
now = datetime.utcnow() now = datetime.utcnow()
if now > unban_time: # Time to unban the user if now > unban_time: # Time to unban the user
user = await self.bot.get_user_info(uid) user = await self.bot.get_user_info(uid)
queue_entry = (guild.id, user.id) queue_entry = (guild.id, user.id)
self.unban_queue.append(queue_entry) self.unban_queue.append(queue_entry)
try: try:
await guild.unban(user, reason="Tempban finished") await guild.unban(user, reason="Tempban finished")
except discord.Forbidden: guild_tempbans.remove(uid)
self.unban_queue.remove(queue_entry) except discord.Forbidden:
log.info("Failed to unban member due to permissions") self.unban_queue.remove(queue_entry)
except discord.HTTPException: log.info("Failed to unban member due to permissions")
self.unban_queue.remove(queue_entry) except discord.HTTPException:
self.unban_queue.remove(queue_entry)
await asyncio.sleep(60) await asyncio.sleep(60)
async def check_duplicates(self, message): async def check_duplicates(self, message):