test
This commit is contained in:
parent
01847c9d81
commit
5425fb5c4f
@ -40,7 +40,7 @@ class SpiceBotCore_OBJ():
|
||||
self.logger.info("SpiceBot Comms Interface Setup Complete.")
|
||||
|
||||
# SpiceBots access to Sopel Command listing
|
||||
self.commands = Commands()
|
||||
self.commands = Commands(self.config)
|
||||
self.logger.info("SpiceBot Commands Interface Setup Complete.")
|
||||
|
||||
def setup(self, bot):
|
||||
|
||||
@ -5,8 +5,9 @@ from sopel.trigger import PreTrigger
|
||||
|
||||
class Commands():
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, config):
|
||||
self.bot = None
|
||||
self.config = config
|
||||
|
||||
@property
|
||||
def valid_sopel_commands(self):
|
||||
@ -99,3 +100,102 @@ class Commands():
|
||||
"\x01", "ACTION", trigger_dict["trigger_str"], "\x01")
|
||||
)
|
||||
bot.dispatch(pretrigger)
|
||||
|
||||
def get_commands_split(self, trigger, splitkey):
|
||||
commands = []
|
||||
|
||||
# Get split for multiple commands
|
||||
if splitkey in trigger.args[1]:
|
||||
triggers = [x.strip() for x in trigger.args[1].split(splitkey)]
|
||||
else:
|
||||
triggers = [trigger.args[1]]
|
||||
|
||||
first_trigger = triggers[0]
|
||||
del triggers[0]
|
||||
|
||||
if first_trigger.startswith(tuple(self.config.prefix_list)):
|
||||
first_trigger_type = "command"
|
||||
first_trigger_prefix = first_trigger[0]
|
||||
first_trigger = first_trigger[1:]
|
||||
elif first_trigger.startswith(self.bot.nick):
|
||||
first_trigger_type = "nickname_command"
|
||||
first_trigger_prefix = str(first_trigger.split(" ")[0])
|
||||
first_trigger = " ".join(first_trigger.split(" ")[1:])
|
||||
elif "intent" in trigger.tags:
|
||||
if trigger.tags["intent"] == "ACTION":
|
||||
first_trigger_type = "action_command"
|
||||
first_trigger_prefix = "ACTION"
|
||||
else:
|
||||
first_trigger_type = "rule"
|
||||
first_trigger_prefix = None
|
||||
|
||||
first_command = first_trigger.split(" ")[0]
|
||||
|
||||
commands.append({
|
||||
"trigger_type": first_trigger_type,
|
||||
"trigger_prefix": first_trigger_prefix,
|
||||
"trigger_str": first_trigger,
|
||||
"trigger_command": first_command
|
||||
})
|
||||
|
||||
for trigger_str in triggers:
|
||||
|
||||
if trigger_str.startswith(tuple(self.config.prefix_list)):
|
||||
trigger_type = "command"
|
||||
trigger_prefix = trigger_str[0]
|
||||
trigger_str = trigger_str[1:]
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
elif trigger_str.startswith(self.bot.nick):
|
||||
trigger_type = "nickname_command"
|
||||
trigger_prefix = str(trigger_str.split(" ")[0])
|
||||
trigger_str = " ".join(trigger_str.split(" ")[1:])
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
elif trigger_str.startswith(tuple(["ACTION", "/me"])):
|
||||
trigger_type = "action_command"
|
||||
trigger_prefix = "ACTION"
|
||||
trigger_str = " ".join(trigger_str.split(" ")[1:])
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
else:
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
command_types = ["command", "nickname_command", "action_command"]
|
||||
# Assume same command type until proven otherwise
|
||||
assumed_trigger_type = first_trigger_type
|
||||
assumed_trigger_prefix = first_trigger_prefix
|
||||
|
||||
# Still under the assumption that the command is most likely the same type as first command
|
||||
command_types.remove(assumed_trigger_type)
|
||||
command_types.insert(0, assumed_trigger_type)
|
||||
|
||||
found = []
|
||||
for command_type in command_types:
|
||||
|
||||
if command_type == "command":
|
||||
commands_list = self.valid_sopel_commands
|
||||
elif command_type == "nickname_command":
|
||||
commands_list = self.valid_sopel_nickname_commands
|
||||
elif command_type == "action_command":
|
||||
commands_list = self.valid_sopel_action_commands
|
||||
|
||||
if trigger_command in commands_list:
|
||||
found.append(command_type)
|
||||
|
||||
if len(found):
|
||||
trigger_type = found[0]
|
||||
if trigger_type == "command":
|
||||
trigger_prefix = self.config.prefix_list[0]
|
||||
elif trigger_type == "nickname_command":
|
||||
trigger_prefix = "%s," % self.bot.nick
|
||||
elif trigger_type == "action_command":
|
||||
trigger_prefix = "ACTION"
|
||||
else:
|
||||
trigger_type = assumed_trigger_type
|
||||
trigger_prefix = assumed_trigger_prefix
|
||||
|
||||
commands.append({
|
||||
"trigger_type": trigger_type,
|
||||
"trigger_prefix": trigger_prefix,
|
||||
"trigger_str": trigger_str,
|
||||
"trigger_command": trigger_command
|
||||
})
|
||||
|
||||
return commands
|
||||
|
||||
@ -16,7 +16,7 @@ def dispatch_multi():
|
||||
bot.say("dispatch_multi")
|
||||
|
||||
# Get list of trigger command(s)
|
||||
commands = get_commands(bot, trigger)
|
||||
commands = sb.commands.get_commands_split(bot, trigger, "&&")
|
||||
|
||||
# If more than 1 trigger command, dispatch
|
||||
if len(commands) > 1:
|
||||
@ -28,104 +28,3 @@ def dispatch_multi():
|
||||
|
||||
return internal_dispatch_multi
|
||||
return actual_decorator
|
||||
|
||||
|
||||
def get_commands(bot, trigger):
|
||||
commands = []
|
||||
|
||||
# Get && split for multiple commands
|
||||
if "&&" in trigger.args[1]:
|
||||
triggers = [x.strip() for x in trigger.args[1].split("&&")]
|
||||
else:
|
||||
triggers = [trigger.args[1]]
|
||||
|
||||
first_trigger = triggers[0]
|
||||
del triggers[0]
|
||||
|
||||
if first_trigger.startswith(tuple(sb.config.prefix_list)):
|
||||
first_trigger_type = "command"
|
||||
first_trigger_prefix = first_trigger[0]
|
||||
first_trigger = first_trigger[1:]
|
||||
elif first_trigger.startswith(bot.nick):
|
||||
first_trigger_type = "nickname_command"
|
||||
first_trigger_prefix = str(first_trigger.split(" ")[0])
|
||||
first_trigger = " ".join(first_trigger.split(" ")[1:])
|
||||
elif "intent" in trigger.tags:
|
||||
if trigger.tags["intent"] == "ACTION":
|
||||
first_trigger_type = "action_command"
|
||||
first_trigger_prefix = "ACTION"
|
||||
else:
|
||||
bot.say("what kind of rule command is this")
|
||||
first_trigger_type = "rule"
|
||||
first_trigger_prefix = None
|
||||
|
||||
first_command = first_trigger.split(" ")[0]
|
||||
|
||||
commands.append({
|
||||
"trigger_type": first_trigger_type,
|
||||
"trigger_prefix": first_trigger_prefix,
|
||||
"trigger_str": first_trigger,
|
||||
"trigger_command": first_command
|
||||
})
|
||||
|
||||
for trigger_str in triggers:
|
||||
|
||||
if trigger_str.startswith(tuple(sb.config.prefix_list)):
|
||||
trigger_type = "command"
|
||||
trigger_prefix = trigger_str[0]
|
||||
trigger_str = trigger_str[1:]
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
elif trigger_str.startswith(bot.nick):
|
||||
trigger_type = "nickname_command"
|
||||
trigger_prefix = str(trigger_str.split(" ")[0])
|
||||
trigger_str = " ".join(trigger_str.split(" ")[1:])
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
elif trigger_str.startswith(tuple(["ACTION", "/me"])):
|
||||
trigger_type = "action_command"
|
||||
trigger_prefix = "ACTION"
|
||||
trigger_str = " ".join(trigger_str.split(" ")[1:])
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
else:
|
||||
trigger_command = trigger_str.split(" ")[0]
|
||||
command_types = ["command", "nickname_command", "action_command"]
|
||||
# Assume same command type until proven otherwise
|
||||
assumed_trigger_type = first_trigger_type
|
||||
assumed_trigger_prefix = first_trigger_prefix
|
||||
|
||||
# Still under the assumption that the command is most likely the same type as first command
|
||||
command_types.remove(assumed_trigger_type)
|
||||
command_types.insert(0, assumed_trigger_type)
|
||||
|
||||
found = []
|
||||
for command_type in command_types:
|
||||
|
||||
if command_type == "command":
|
||||
commands_list = sb.commands.valid_sopel_commands
|
||||
elif command_type == "nickname_command":
|
||||
commands_list = sb.commands.valid_sopel_nickname_commands
|
||||
elif command_type == "action_command":
|
||||
commands_list = sb.commands.valid_sopel_action_commands
|
||||
|
||||
if trigger_command in commands_list:
|
||||
found.append(command_type)
|
||||
|
||||
if len(found):
|
||||
trigger_type = found[0]
|
||||
if trigger_type == "command":
|
||||
trigger_prefix = sb.config.prefix_list[0]
|
||||
elif trigger_type == "nickname_command":
|
||||
trigger_prefix = "%s," % bot.nick
|
||||
elif trigger_type == "action_command":
|
||||
trigger_prefix = "ACTION"
|
||||
else:
|
||||
trigger_type = assumed_trigger_type
|
||||
trigger_prefix = assumed_trigger_prefix
|
||||
|
||||
commands.append({
|
||||
"trigger_type": trigger_type,
|
||||
"trigger_prefix": trigger_prefix,
|
||||
"trigger_str": trigger_str,
|
||||
"trigger_command": trigger_command
|
||||
})
|
||||
|
||||
return commands
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import functools
|
||||
|
||||
from sopel_SpiceBot_Core_1 import sb
|
||||
|
||||
|
||||
def pipe_split():
|
||||
"""
|
||||
@ -15,7 +17,7 @@ def pipe_split():
|
||||
bot.say("pipe_split")
|
||||
|
||||
# Get list of trigger command(s)
|
||||
pipes = get_pipes(bot, trigger)
|
||||
pipes = sb.commands.get_commands_split(bot, trigger, "|")
|
||||
bot.say(str(pipes))
|
||||
|
||||
function(bot, trigger, comrun, *args, **kwargs)
|
||||
@ -24,14 +26,3 @@ def pipe_split():
|
||||
|
||||
return internal_pipe_split
|
||||
return actual_decorator
|
||||
|
||||
|
||||
def get_pipes(bot, trigger):
|
||||
|
||||
# Get && split for multiple commands
|
||||
if "|" in trigger.args[1]:
|
||||
pipes = [x.strip() for x in trigger.args[1].split("|")]
|
||||
else:
|
||||
pipes = [trigger.args[1]]
|
||||
|
||||
return pipes
|
||||
|
||||
Loading…
Reference in New Issue
Block a user