test
This commit is contained in:
parent
8c728d28bc
commit
21a48907f5
@ -159,7 +159,48 @@ class Commands():
|
|||||||
rulematch = True
|
rulematch = True
|
||||||
return rulematch
|
return rulematch
|
||||||
|
|
||||||
def get_commands_split(self, trigger, splitkey):
|
def get_commands_nosplit(self, trigger):
|
||||||
|
commands = []
|
||||||
|
first_full_trigger_str = trigger.args[1]
|
||||||
|
|
||||||
|
if first_full_trigger_str.startswith(tuple(self.config.prefix_list)):
|
||||||
|
first_trigger_type = "command"
|
||||||
|
first_trigger_prefix = first_full_trigger_str[0]
|
||||||
|
first_trigger_noprefix = first_full_trigger_str[1:]
|
||||||
|
first_trigger_command = first_trigger_noprefix.split(" ")[0]
|
||||||
|
first_trigger_str = " ".join([x.strip() for x in first_trigger_noprefix.split(" ")[1:]])
|
||||||
|
elif first_full_trigger_str.startswith(self.bot.nick):
|
||||||
|
first_trigger_type = "nickname_command"
|
||||||
|
first_trigger_prefix = str(first_full_trigger_str.split(" ")[0])
|
||||||
|
first_trigger_noprefix = " ".join(first_full_trigger_str.split(" ")[1:])
|
||||||
|
first_trigger_command = first_trigger_noprefix.split(" ")[0]
|
||||||
|
first_trigger_str = " ".join([x.strip() for x in first_trigger_noprefix.split(" ")[1:]])
|
||||||
|
elif "intent" in trigger.tags and trigger.tags["intent"] == "ACTION":
|
||||||
|
first_trigger_type = "action_command"
|
||||||
|
first_trigger_prefix = "ACTION"
|
||||||
|
first_trigger_noprefix = first_full_trigger_str
|
||||||
|
first_trigger_command = first_trigger_noprefix.split(" ")[0]
|
||||||
|
first_trigger_str = " ".join([x.strip() for x in first_trigger_noprefix.split(" ")[1:]])
|
||||||
|
else:
|
||||||
|
first_trigger_type = "rule"
|
||||||
|
first_trigger_prefix = None
|
||||||
|
first_trigger_noprefix = first_full_trigger_str
|
||||||
|
first_trigger_command = first_trigger_noprefix.split(" ")[0]
|
||||||
|
first_trigger_str = " ".join([x.strip() for x in first_trigger_noprefix.split(" ")[1:]])
|
||||||
|
|
||||||
|
commands.append({
|
||||||
|
"trigger_type": first_trigger_type,
|
||||||
|
"trigger_prefix": first_trigger_prefix,
|
||||||
|
"trigger_str": first_trigger_str,
|
||||||
|
"trigger_command": first_trigger_command,
|
||||||
|
"trigger_hostmask": trigger.hostmask,
|
||||||
|
"trigger_sender": trigger.sender,
|
||||||
|
"trigger_time": str(trigger.time)
|
||||||
|
})
|
||||||
|
|
||||||
|
return commands
|
||||||
|
|
||||||
|
def get_commands_split(self, trigger, splitkey=None):
|
||||||
commands = []
|
commands = []
|
||||||
|
|
||||||
# Get split for multiple commands
|
# Get split for multiple commands
|
||||||
|
|||||||
@ -13,14 +13,11 @@ def prerun():
|
|||||||
|
|
||||||
comrun = ComRun(function, trigger)
|
comrun = ComRun(function, trigger)
|
||||||
|
|
||||||
# Get list of trigger command(s) by && split
|
|
||||||
commands = sb.commands.get_commands_split(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(comrun.commands) > 1:
|
||||||
for trigger_dict in commands:
|
for trigger_dict in comrun.commands:
|
||||||
if comrun.is_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)
|
||||||
@ -28,37 +25,19 @@ def prerun():
|
|||||||
sb.commands.dispatch(trigger_dict)
|
sb.commands.dispatch(trigger_dict)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If the original trigger is not the same after && split
|
# If the original trigger is not the same after && or | split
|
||||||
# so we will now redispatch to help get the correct function passed
|
# so we will now redispatch to help get the correct function passed
|
||||||
trigger_command = sb.commands.get_command_from_trigger(trigger)
|
if comrun.has_command_been_sanitized:
|
||||||
if trigger_command != commands[0]["trigger_command"]:
|
if comrun.is_pipe_command:
|
||||||
sb.commands.dispatch(commands[0])
|
trigger_dict = rebuild_pipes(comrun.commands)
|
||||||
return
|
else:
|
||||||
|
trigger_dict = comrun.command
|
||||||
# Get list of trigger command(s) by | split
|
|
||||||
commands = sb.commands.get_commands_split(trigger, "|")
|
|
||||||
|
|
||||||
# Validate | split
|
|
||||||
trigger_command = sb.commands.get_command_from_trigger(trigger)
|
|
||||||
if trigger_command != commands[0]["trigger_command"]:
|
|
||||||
trigger_dict = rebuild_pipes(commands)
|
|
||||||
sb.commands.dispatch(trigger_dict)
|
sb.commands.dispatch(trigger_dict)
|
||||||
return
|
return
|
||||||
|
|
||||||
if comrun.is_rulematch and sb.commands.is_real_command(commands[0]):
|
if comrun.is_rulematch and comrun.is_real_command():
|
||||||
return
|
return
|
||||||
|
|
||||||
# This is where we rebuild trigger
|
|
||||||
# we validate a few things here
|
|
||||||
# trigger = clean_trigger(bot, trigger, commands[0])
|
|
||||||
|
|
||||||
# Now we have a single valid command
|
|
||||||
# we are going to validate the command
|
|
||||||
# as a && or | attached to a command
|
|
||||||
# could trigger an unmatched command
|
|
||||||
# if validate_command(rulematch):
|
|
||||||
# return
|
|
||||||
|
|
||||||
# Run function
|
# Run function
|
||||||
function(bot, trigger, comrun, *args, **kwargs)
|
function(bot, trigger, comrun, *args, **kwargs)
|
||||||
|
|
||||||
@ -90,6 +69,10 @@ class ComRun():
|
|||||||
self.function = function
|
self.function = function
|
||||||
self.trigger = trigger
|
self.trigger = trigger
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_real_command(self):
|
||||||
|
return sb.commands.is_real_command(self.command)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def command_type(self):
|
def command_type(self):
|
||||||
return sb.commands.what_command_type(self.trigger)
|
return sb.commands.what_command_type(self.trigger)
|
||||||
@ -97,3 +80,60 @@ class ComRun():
|
|||||||
@property
|
@property
|
||||||
def is_rulematch(self):
|
def is_rulematch(self):
|
||||||
return sb.commands.is_rulematch(self.function, self.command_type)
|
return sb.commands.is_rulematch(self.function, self.command_type)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_multi_command(self):
|
||||||
|
if "&&" in self.trigger.args[1]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_pipe_command(self):
|
||||||
|
if "|" in self.trigger.args[1]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def multi_split_count(self):
|
||||||
|
if "&&" in self.trigger.args[1]:
|
||||||
|
return len([x.strip() for x in self.trigger.args[1].split("&&")])
|
||||||
|
return "N/A"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pipe_split_count(self):
|
||||||
|
if "|" in self.trigger.args[1]:
|
||||||
|
return len([x.strip() for x in self.trigger.args[1].split("|")])
|
||||||
|
return "N/A"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def commands(self):
|
||||||
|
if "&&" in self.trigger.args[1]:
|
||||||
|
return sb.commands.get_commands_split(self.trigger, "&&")
|
||||||
|
elif "|" in self.trigger.args[1]:
|
||||||
|
return sb.commands.get_commands_split(self.trigger, "|")
|
||||||
|
else:
|
||||||
|
return sb.commands.get_commands_nosplit(self.trigger)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def command(self):
|
||||||
|
return self.commands[0]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_command_been_sanitized(self):
|
||||||
|
|
||||||
|
trigger_command = sb.commands.get_command_from_trigger(self.trigger)
|
||||||
|
multi_split_count = self.multi_split_count
|
||||||
|
pipe_split_count = self.pipe_split_count
|
||||||
|
|
||||||
|
if trigger_command != self.command["trigger_command"]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
elif multi_split_count != "N/A":
|
||||||
|
if multi_split_count != len(self.commands):
|
||||||
|
return True
|
||||||
|
|
||||||
|
elif pipe_split_count != "N/A":
|
||||||
|
if pipe_split_count != len(self.commands):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user