This commit is contained in:
deathbybandaid 2022-02-24 09:37:23 -05:00
parent 6d70ec5e1a
commit c75621eed3
2 changed files with 42 additions and 20 deletions

View File

@ -118,6 +118,17 @@ class Commands():
return command return command
def what_command_type(self, trigger):
full_trigger_str = trigger.args[1]
if full_trigger_str.startswith(tuple(self.config.prefix_list)):
return "command"
elif full_trigger_str.startswith(self.bot.nick):
return "nickname_command"
elif "intent" in trigger.tags and trigger.tags["intent"] == "ACTION":
return "action_command"
else:
return "rule"
def is_real_command(self, trigger_dict): def is_real_command(self, trigger_dict):
if trigger_dict["trigger_type"] == "command": if trigger_dict["trigger_type"] == "command":
@ -132,6 +143,22 @@ class Commands():
else: else:
return False return False
def is_rulematch(function, command_type):
"""Determine if function could be called with a rule match"""
rulematch = False
if command_type == "command":
if hasattr(function, 'commands'):
command_aliases = function.commands
elif command_type == "nickname_command":
if hasattr(function, 'nickname_commands'):
command_aliases = function.nickname_commands
elif command_type == "action_command":
if hasattr(function, 'action_commands'):
command_aliases = function.action_commands
if '(.*)' in command_aliases:
rulematch = True
return rulematch
def get_commands_split(self, trigger, splitkey): def get_commands_split(self, trigger, splitkey):
commands = [] commands = []

View File

@ -3,7 +3,7 @@ import functools
from sopel_SpiceBot_Core_1 import sb from sopel_SpiceBot_Core_1 import sb
def prerun(rulematch=False): def prerun():
"""This decorator is the hub of handling for all SpiceBot Commands""" """This decorator is the hub of handling for all SpiceBot Commands"""
def actual_decorator(function): def actual_decorator(function):
@ -11,28 +11,17 @@ def prerun(rulematch=False):
@functools.wraps(function) @functools.wraps(function)
def internal_prerun(bot, trigger, *args, **kwargs): def internal_prerun(bot, trigger, *args, **kwargs):
# trigger_type = [x for x in dir(function) if not x.startswith("__")][1] comrun = ComRun(function, trigger)
if hasattr(function, 'commands'):
print("commands")
print(function.commands)
if hasattr(function, 'nickname_commands'):
print("nickname_commands")
print(function.nickname_commands)
if hasattr(function, 'action_commands'):
print("action_commands")
print(function.action_commands)
# Get list of trigger command(s) by && split # Get list of trigger command(s) by && split
commands = sb.commands.get_commands_split(trigger, "&&") commands = sb.commands.get_commands_split(trigger, "&&")
comrun = ComRun(rulematch, trigger)
# Since there was more than one command, # Since there was more than one command,
# we are going to redispatch commands # we are going to redispatch commands
# This will give sopel the appearance of recieving individual commands # This will give sopel the appearance of recieving individual commands
if len(commands) > 1: if len(commands) > 1:
for trigger_dict in commands: for trigger_dict in commands:
if rulematch: if comrun.is_rulematch:
if not sb.commands.is_real_command(trigger_dict): if not sb.commands.is_real_command(trigger_dict):
sb.commands.dispatch(trigger_dict) sb.commands.dispatch(trigger_dict)
else: else:
@ -53,11 +42,10 @@ def prerun(rulematch=False):
trigger_command = sb.commands.get_command_from_trigger(trigger) trigger_command = sb.commands.get_command_from_trigger(trigger)
if trigger_command != commands[0]["trigger_command"]: if trigger_command != commands[0]["trigger_command"]:
trigger_dict = rebuild_pipes(commands) trigger_dict = rebuild_pipes(commands)
sb.osd("pipes - dispatching %s %s" % (trigger_dict["trigger_command"], trigger_dict["trigger_str"]), trigger.sender)
sb.commands.dispatch(trigger_dict) sb.commands.dispatch(trigger_dict)
return return
if rulematch and sb.commands.is_real_command(commands[0]): if comrun.is_rulematch and sb.commands.is_real_command(commands[0]):
return return
# This is where we rebuild trigger # This is where we rebuild trigger
@ -98,7 +86,14 @@ def rebuild_pipes(commands):
class ComRun(): class ComRun():
def __init__(self, rulematch, trigger): def __init__(self, function, trigger):
self.rulematch = rulematch self.function = function
self.original_trigger = trigger self.trigger = trigger
self.trigger_dict = {}
@property
def command_type(self):
return sb.commands.what_command_type(self.trigger)
@property
def is_rulematch(self):
return sb.commands.is_rulematch(self.function, self.command_type)