[V3 Warnings] fix several bugs found (#1577)

This commit is contained in:
palmtree5 2018-05-03 19:46:59 -08:00 committed by Kowlin
parent 79676c4f72
commit e4ea3110e3
2 changed files with 27 additions and 14 deletions

View File

@ -17,8 +17,8 @@ async def warning_points_add_check(config: Config, ctx: RedContext, user: discor
act = {} act = {}
async with guild_settings.actions() as registered_actions: async with guild_settings.actions() as registered_actions:
for a in registered_actions: for a in registered_actions:
if points >= registered_actions[a]["point_count"]: if points >= a["points"]:
act = registered_actions[a] act = a
else: else:
break break
if act: # some action needs to be taken if act: # some action needs to be taken
@ -31,8 +31,8 @@ async def warning_points_remove_check(config: Config, ctx: RedContext, user: dis
act = {} act = {}
async with guild_settings.actions() as registered_actions: async with guild_settings.actions() as registered_actions:
for a in registered_actions: for a in registered_actions:
if points >= registered_actions[a]["point_count"]: if points >= a["points"]:
act = registered_actions[a] act = a
else: else:
break break
if act: # some action needs to be taken if act: # some action needs to be taken

View File

@ -120,7 +120,7 @@ class Warnings:
registered_actions.append(to_add) registered_actions.append(to_add)
# Sort in descending order by point count for ease in # Sort in descending order by point count for ease in
# finding the highest possible action to take # finding the highest possible action to take
registered_actions.sort(key=lambda a: a["point_count"], reverse=True) registered_actions.sort(key=lambda a: a["points"], reverse=True)
await ctx.tick() await ctx.tick()
@warnaction.command(name="del") @warnaction.command(name="del")
@ -137,6 +137,11 @@ class Warnings:
break break
if to_remove: if to_remove:
registered_actions.remove(to_remove) registered_actions.remove(to_remove)
await ctx.tick()
else:
await ctx.send(
_("No action named {} exists!").format(action_name)
)
@commands.group() @commands.group()
@commands.guild_only() @commands.guild_only()
@ -178,7 +183,7 @@ class Warnings:
guild_settings = self.config.guild(guild) guild_settings = self.config.guild(guild)
async with guild_settings.reasons() as registered_reasons: async with guild_settings.reasons() as registered_reasons:
if registered_reasons.pop(reason_name.lower(), None): if registered_reasons.pop(reason_name.lower(), None):
await ctx.send(_("Removed reason {}").format(reason_name)) await ctx.tick()
else: else:
await ctx.send(_("That is not a registered reason name")) await ctx.send(_("That is not a registered reason name"))
@ -191,13 +196,16 @@ class Warnings:
guild_settings = self.config.guild(guild) guild_settings = self.config.guild(guild)
msg_list = [] msg_list = []
async with guild_settings.reasons() as registered_reasons: async with guild_settings.reasons() as registered_reasons:
for r in registered_reasons.keys(): for r, v in registered_reasons.items():
msg_list.append( msg_list.append(
"Name: {}\nPoints: {}\nAction: {}".format( "Name: {}\nPoints: {}\nDescription: {}".format(
r, r["points"], r["action"] r, v["points"], v["description"]
) )
) )
await ctx.send_interactive(msg_list) if msg_list:
await ctx.send_interactive(msg_list)
else:
await ctx.send(_("There are no reasons configured!"))
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@ -210,11 +218,16 @@ class Warnings:
async with guild_settings.actions() as registered_actions: async with guild_settings.actions() as registered_actions:
for r in registered_actions: for r in registered_actions:
msg_list.append( msg_list.append(
"Name: {}\nPoints: {}\nDescription: {}".format( "Name: {}\nPoints: {}\nExceed command: {}\n"
r, r["points"], r["description"] "Drop command: {}".format(
r["action_name"], r["points"], r["exceed_command"],
r["drop_command"]
) )
) )
await ctx.send_interactive(msg_list) if msg_list:
await ctx.send_interactive(msg_list)
else:
await ctx.send(_("There are no actions configured!"))
@commands.command() @commands.command()
@commands.guild_only() @commands.guild_only()
@ -271,7 +284,7 @@ class Warnings:
if userid is None: if userid is None:
user = ctx.author user = ctx.author
else: else:
if not is_admin_or_superior(self.bot, ctx.author): if not await is_admin_or_superior(self.bot, ctx.author):
await ctx.send( await ctx.send(
warning( warning(
_("You are not allowed to check " _("You are not allowed to check "