[Warnings] Fix actions not being taken (#2218)

When multiple warning actions were registered, and the user didn't exceed the points for the highest action on the list, no action was taken.

Resolves #2106.

Also commented out the casetype registration for warnings, since it's not actually using modlog yet.

Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
Toby Harradine 2018-10-11 11:54:11 +11:00 committed by GitHub
parent f7b1f9f0dc
commit 094735566d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -19,9 +19,11 @@ async def warning_points_add_check(
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:
# Actions are sorted in decreasing order of points.
# The first action we find where the user is above the threshold will be the
# highest action we can take.
if points >= a["points"]: if points >= a["points"]:
act = a act = a
else:
break break
if act and act["exceed_command"] is not None: # some action needs to be taken if act and act["exceed_command"] is not None: # some action needs to be taken
await create_and_invoke_context(ctx, act["exceed_command"], user) await create_and_invoke_context(ctx, act["exceed_command"], user)

View File

@ -9,7 +9,7 @@ from redbot.cogs.warnings.helpers import (
get_command_for_dropping_points, get_command_for_dropping_points,
warning_points_remove_check, warning_points_remove_check,
) )
from redbot.core import Config, modlog, checks, commands from redbot.core import Config, checks, commands
from redbot.core.bot import Red from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils.mod import is_admin_or_superior from redbot.core.utils.mod import is_admin_or_superior
@ -34,15 +34,14 @@ class Warnings(commands.Cog):
self.config.register_guild(**self.default_guild) self.config.register_guild(**self.default_guild)
self.config.register_member(**self.default_member) self.config.register_member(**self.default_member)
self.bot = bot self.bot = bot
loop = asyncio.get_event_loop()
loop.create_task(self.register_warningtype())
@staticmethod # We're not utilising modlog yet - no need to register a casetype
async def register_warningtype(): # @staticmethod
try: # async def register_warningtype():
await modlog.register_casetype("warning", True, "\N{WARNING SIGN}", "Warning", None) # try:
except RuntimeError: # await modlog.register_casetype("warning", True, "\N{WARNING SIGN}", "Warning", None)
pass # except RuntimeError:
# pass
@commands.group() @commands.group()
@commands.guild_only() @commands.guild_only()