SpiceBot/sopel_SpiceBot_Core_Prerun/rule_match.py
deathbybandaid e8fe785228 test
2022-02-23 10:02:05 -05:00

49 lines
1.9 KiB
Python

import functools
from sopel_SpiceBot_Core_1 import sb
def rule_match():
"""This Detects --arguments to commands."""
def actual_decorator(function):
@functools.wraps(function)
def internal_rule_match(bot, trigger, comrun, *args, **kwargs):
returnfunc = True
# Applies to non-command rule matching
if comrun.rulematch:
first_full_trigger_str = trigger.args[1]
if comrun.trigger_dict["trigger_type"] == "command":
commands_list = sb.commands.valid_sopel_commands
first_trigger_noprefix = first_full_trigger_str[1:]
first_trigger_command = first_trigger_noprefix.split(" ")[0]
elif comrun.trigger_dict["trigger_type"] == "nickname_command":
commands_list = sb.commands.valid_sopel_nickname_commands
first_trigger_noprefix = " ".join(first_full_trigger_str.split(" ")[1:])
first_trigger_command = first_trigger_noprefix.split(" ")[0]
elif comrun.trigger_dict["trigger_type"] == "action_command":
commands_list = sb.commands.valid_sopel_action_commands
first_trigger_noprefix = first_full_trigger_str
first_trigger_command = first_trigger_noprefix.split(" ")[0]
# Ignore if the command was caught
# handle if the command was triggered with && or | too close to the command
if comrun.trigger_dict["trigger_command"] in commands_list:
if first_trigger_command != comrun.trigger_dict["trigger_command"]:
sb.commands.dispatch(comrun.trigger_dict)
else:
returnfunc = False
if returnfunc:
function(bot, trigger, comrun, *args, **kwargs)
return internal_rule_match
return actual_decorator