test
This commit is contained in:
parent
aec1422769
commit
a1bed3d02e
@ -8,6 +8,27 @@ class Commands():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.bot = None
|
self.bot = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def valid_sopel_commands(self):
|
||||||
|
found = []
|
||||||
|
for command_dict in self.sopel_commands:
|
||||||
|
found.append(command_dict["name"]).extend(command_dict["aliases"])
|
||||||
|
return found
|
||||||
|
|
||||||
|
@property
|
||||||
|
def valid_sopel_nickname_commands(self):
|
||||||
|
found = []
|
||||||
|
for command_dict in self.sopel_nickname_commands:
|
||||||
|
found.append(command_dict["name"]).extend(command_dict["aliases"])
|
||||||
|
return found
|
||||||
|
|
||||||
|
@property
|
||||||
|
def valid_sopel_action_commands(self):
|
||||||
|
found = []
|
||||||
|
for command_dict in self.sopel_action_commands:
|
||||||
|
found.append(command_dict["name"]).extend(command_dict["aliases"])
|
||||||
|
return found
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sopel_commands(self):
|
def sopel_commands(self):
|
||||||
commands_list = []
|
commands_list = []
|
||||||
@ -16,6 +37,7 @@ class Commands():
|
|||||||
commands_list.append({
|
commands_list.append({
|
||||||
"name": command.name,
|
"name": command.name,
|
||||||
"aliases": command.aliases,
|
"aliases": command.aliases,
|
||||||
|
"type": "command"
|
||||||
})
|
})
|
||||||
return commands_list
|
return commands_list
|
||||||
|
|
||||||
@ -27,6 +49,7 @@ class Commands():
|
|||||||
commands_list.append({
|
commands_list.append({
|
||||||
"name": command.name,
|
"name": command.name,
|
||||||
"aliases": command.aliases,
|
"aliases": command.aliases,
|
||||||
|
"type": "nickname_command"
|
||||||
})
|
})
|
||||||
return commands_list
|
return commands_list
|
||||||
|
|
||||||
@ -38,15 +61,19 @@ class Commands():
|
|||||||
commands_list.append({
|
commands_list.append({
|
||||||
"name": command.name,
|
"name": command.name,
|
||||||
"aliases": command.aliases,
|
"aliases": command.aliases,
|
||||||
|
"type": "action_command"
|
||||||
})
|
})
|
||||||
return commands_list
|
return commands_list
|
||||||
|
|
||||||
def dispatch(self, bot, trigger, trigger_dict):
|
def dispatch(self, bot, trigger, trigger_dict):
|
||||||
if trigger_dict["trigger_type"] == "command":
|
if trigger_dict["trigger_type"] == "command":
|
||||||
|
if trigger_dict["trigger_type"] in self.valid_sopel_commands:
|
||||||
return self.dispatch_command(bot, trigger, trigger_dict)
|
return self.dispatch_command(bot, trigger, trigger_dict)
|
||||||
elif trigger_dict["trigger_type"] == "nickname_command":
|
elif trigger_dict["trigger_type"] == "nickname_command":
|
||||||
|
if trigger_dict["trigger_type"] in self.valid_sopel_nickname_commands:
|
||||||
return self.dispatch_nickname_command(bot, trigger, trigger_dict)
|
return self.dispatch_nickname_command(bot, trigger, trigger_dict)
|
||||||
elif trigger_dict["trigger_type"] == "action_command":
|
elif trigger_dict["trigger_type"] == "action_command":
|
||||||
|
if trigger_dict["trigger_type"] in self.valid_sopel_action_commands:
|
||||||
return self.dispatch_action_command(bot, trigger, trigger_dict)
|
return self.dispatch_action_command(bot, trigger, trigger_dict)
|
||||||
|
|
||||||
def dispatch_command(self, bot, trigger, trigger_dict):
|
def dispatch_command(self, bot, trigger, trigger_dict):
|
||||||
|
|||||||
@ -27,43 +27,70 @@ def get_commands(bot, trigger):
|
|||||||
if trigger.tags["intent"] == "ACTION":
|
if trigger.tags["intent"] == "ACTION":
|
||||||
first_trigger_type = "action_command"
|
first_trigger_type = "action_command"
|
||||||
first_trigger_prefix = "ACTION"
|
first_trigger_prefix = "ACTION"
|
||||||
first_trigger = first_trigger
|
|
||||||
else:
|
else:
|
||||||
bot.say("what kind of rule command is this")
|
bot.say("what kind of rule command is this")
|
||||||
first_trigger_type = "rule"
|
first_trigger_type = "rule"
|
||||||
first_trigger_prefix = None
|
first_trigger_prefix = None
|
||||||
first_trigger = first_trigger
|
|
||||||
|
first_command = first_trigger.split(" ")[0]
|
||||||
|
|
||||||
commands.append({
|
commands.append({
|
||||||
"trigger_type": first_trigger_type,
|
"trigger_type": first_trigger_type,
|
||||||
"trigger_prefix": first_trigger_prefix,
|
"trigger_prefix": first_trigger_prefix,
|
||||||
"trigger_str": first_trigger
|
"trigger_str": first_trigger,
|
||||||
|
"trigger_command": first_command
|
||||||
})
|
})
|
||||||
|
|
||||||
for trigger_item in triggers:
|
for trigger_str in triggers:
|
||||||
|
|
||||||
if trigger_item.startswith(tuple(sb.config.prefix_list)):
|
if trigger_str.startswith(tuple(sb.config.prefix_list)):
|
||||||
trigger_type = "command"
|
trigger_type = "command"
|
||||||
trigger_prefix = trigger_item[0]
|
trigger_prefix = trigger_str[0]
|
||||||
trigger_str = trigger_item[1:]
|
trigger_str = trigger_str[1:]
|
||||||
elif trigger_item.startswith(bot.nick):
|
trigger_command = trigger_str.split(" ")[0]
|
||||||
|
elif trigger_str.startswith(bot.nick):
|
||||||
trigger_type = "nickname_command"
|
trigger_type = "nickname_command"
|
||||||
trigger_prefix = str(trigger_item.split(" ")[0])
|
trigger_prefix = str(trigger_str.split(" ")[0])
|
||||||
trigger_str = " ".join(trigger_item.split(" ")[1:])
|
trigger_str = " ".join(trigger_str.split(" ")[1:])
|
||||||
elif trigger_item.startswith(tuple(["ACTION", "/me"])):
|
trigger_command = trigger_str.split(" ")[0]
|
||||||
|
elif trigger_str.startswith(tuple(["ACTION", "/me"])):
|
||||||
trigger_type = "action_command"
|
trigger_type = "action_command"
|
||||||
trigger_prefix = "ACTION"
|
trigger_prefix = "ACTION"
|
||||||
trigger_str = " ".join(trigger_item.split(" ")[1:])
|
trigger_str = " ".join(trigger_str.split(" ")[1:])
|
||||||
|
trigger_command = trigger_str.split(" ")[0]
|
||||||
else:
|
else:
|
||||||
|
command_types = ["command", "nickname_command", "action_command"]
|
||||||
# TODO Assume same command type until proven otherwise
|
# TODO Assume same command type until proven otherwise
|
||||||
trigger_type = first_trigger_type
|
trigger_type = first_trigger_type
|
||||||
trigger_prefix = first_trigger_prefix
|
trigger_prefix = first_trigger_prefix
|
||||||
trigger_str = trigger_item
|
trigger_str = trigger_str
|
||||||
|
trigger_command = trigger_str.split(" ")[0]
|
||||||
|
|
||||||
|
# Still under the assumption that the command is most likely the same type as first command
|
||||||
|
command_types.remove(trigger_type)
|
||||||
|
command_types.insert(0, 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]
|
||||||
|
|
||||||
commands.append({
|
commands.append({
|
||||||
"trigger_type": trigger_type,
|
"trigger_type": trigger_type,
|
||||||
"trigger_prefix": trigger_prefix,
|
"trigger_prefix": trigger_prefix,
|
||||||
"trigger_str": trigger_str
|
"trigger_str": trigger_str,
|
||||||
|
"trigger_command": trigger_command
|
||||||
})
|
})
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user