fix clean and clean-bans commands

This commit is contained in:
brandons209 2020-07-28 13:18:33 -04:00
parent 79fda9d5f3
commit 9329e2a8de
3 changed files with 17 additions and 19 deletions

View file

@ -191,7 +191,8 @@ class Isolate(commands.Cog):
data = await self.config.guild(guild).ISOLATED()
for mid, mdata in data.copy().items():
if not mid.isdigit() or guild.get_member(mid):
intid = int(mid)
if guild.get_member(intid):
continue
elif clean_pending or ((mdata["until"] or 0) < now):
@ -204,6 +205,7 @@ class Isolate(commands.Cog):
@isolate.command(name="clean-bans")
@commands.guild_only()
@checks.mod()
@checks.bot_has_permissions(ban_members=True)
async def isolate_clean_bans(self, ctx):
"""
Removes banned members from the isolated list.
@ -213,18 +215,15 @@ class Isolate(commands.Cog):
guild = ctx.guild
data = await self.config.guild(guild).ISOLATED()
try:
bans = await guild.bans()
ban_ids = {u.id for u in bans}
except discord.errors.Forbidden:
await ctx.send(warning("I need ban permissions to see the list of banned users."))
return
bans = await guild.bans()
ban_ids = {ban.user.id for ban in bans}
for mid, mdata in data.copy().items():
if not mid.isdigit() or guild.get_member(mid):
intid = int(mid)
if guild.get_member(intid):
continue
elif mid in ban_ids:
elif intid in ban_ids:
del data[mid]
count += 1

View file

@ -152,7 +152,7 @@ class Markov(commands.Cog):
content = content.split(" ")
try:
model[str(message.channel.id)]
except:
except KeyError:
model[str(message.channel.id)] = {}
for i in range(len(content) - 1):

View file

@ -190,7 +190,8 @@ class Punish(commands.Cog):
data = await self.config.guild(guild).PUNISHED()
for mid, mdata in data.copy().items():
if not mid.isdigit() or guild.get_member(mid):
intid = int(mid)
if guild.get_member(intid):
continue
elif clean_pending or ((mdata["until"] or 0) < now):
@ -203,6 +204,7 @@ class Punish(commands.Cog):
@punish.command(name="clean-bans")
@commands.guild_only()
@checks.mod()
@checks.bot_has_permissions(ban_members=True)
async def punish_clean_bans(self, ctx):
"""
Removes banned members from the punished list.
@ -212,18 +214,15 @@ class Punish(commands.Cog):
guild = ctx.guild
data = await self.config.guild(guild).PUNISHED()
try:
bans = await guild.bans()
ban_ids = {u.id for u in bans}
except discord.errors.Forbidden:
await ctx.send(warning("I need ban permissions to see the list of banned users."))
return
bans = await guild.bans()
ban_ids = {ban.user.id for ban in bans}
for mid, mdata in data.copy().items():
if not mid.isdigit() or guild.get_member(mid):
intid = int(mid)
if guild.get_member(intid):
continue
elif mid in ban_ids:
elif intid in ban_ids:
del data[mid]
count += 1