test
This commit is contained in:
parent
6148bf9f0d
commit
2183620070
@ -71,35 +71,38 @@ class Commands():
|
|||||||
|
|
||||||
def dispatch(self, trigger_dict):
|
def dispatch(self, trigger_dict):
|
||||||
if trigger_dict["trigger_type"] == "command":
|
if trigger_dict["trigger_type"] == "command":
|
||||||
return self.dispatch_command(trigger_dict)
|
pretrigger = self.generate_pretrigger_command(trigger_dict)
|
||||||
elif trigger_dict["trigger_type"] == "nickname_command":
|
elif trigger_dict["trigger_type"] == "nickname_command":
|
||||||
return self.dispatch_nickname_command(trigger_dict)
|
pretrigger = self.generate_pretrigger_nickname_command(trigger_dict)
|
||||||
elif trigger_dict["trigger_type"] == "action_command":
|
elif trigger_dict["trigger_type"] == "action_command":
|
||||||
return self.dispatch_action_command(trigger_dict)
|
pretrigger = self.generate_pretrigger_action_command(trigger_dict)
|
||||||
|
self.bot.dispatch(pretrigger)
|
||||||
|
|
||||||
def dispatch_command(self, trigger_dict):
|
def generate_pretrigger_command(self, trigger_dict):
|
||||||
|
# @time=2022-02-23T15:04:01.447Z :
|
||||||
|
pretrigger = PreTrigger(
|
||||||
|
self.bot.nick,
|
||||||
|
"%s :%s %s %s :%s%s %s" % ("",
|
||||||
|
trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"],
|
||||||
|
trigger_dict["trigger_prefix"], trigger_dict["trigger_command"], trigger_dict["trigger_str"])
|
||||||
|
)
|
||||||
|
return pretrigger
|
||||||
|
|
||||||
|
def generate_pretrigger_nickname_command(self, trigger_dict):
|
||||||
pretrigger = PreTrigger(
|
pretrigger = PreTrigger(
|
||||||
self.bot.nick,
|
self.bot.nick,
|
||||||
":%s %s %s :%s %s %s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"],
|
":%s %s %s :%s %s %s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"],
|
||||||
trigger_dict["trigger_prefix"], trigger_dict["trigger_command"], trigger_dict["trigger_str"])
|
trigger_dict["trigger_prefix"], trigger_dict["trigger_command"], trigger_dict["trigger_str"])
|
||||||
)
|
)
|
||||||
self.bot.dispatch(pretrigger)
|
return pretrigger
|
||||||
|
|
||||||
def dispatch_nickname_command(self, trigger_dict):
|
def generate_pretrigger_action_command(self, trigger_dict):
|
||||||
pretrigger = PreTrigger(
|
|
||||||
self.bot.nick,
|
|
||||||
":%s %s %s :%s %s %s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"],
|
|
||||||
trigger_dict["trigger_prefix"], trigger_dict["trigger_command"], trigger_dict["trigger_str"])
|
|
||||||
)
|
|
||||||
self.bot.dispatch(pretrigger)
|
|
||||||
|
|
||||||
def dispatch_action_command(self, trigger_dict):
|
|
||||||
pretrigger = PreTrigger(
|
pretrigger = PreTrigger(
|
||||||
self.bot.nick,
|
self.bot.nick,
|
||||||
":%s %s %s :%s%s %s%s %s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"],
|
":%s %s %s :%s%s %s%s %s" % (trigger_dict["trigger_hostmask"], "PRIVMSG", trigger_dict["trigger_sender"],
|
||||||
"\x01", "ACTION", trigger_dict["trigger_command"], trigger_dict["trigger_str"], "\x01")
|
"\x01", "ACTION", trigger_dict["trigger_command"], trigger_dict["trigger_str"], "\x01")
|
||||||
)
|
)
|
||||||
self.bot.dispatch(pretrigger)
|
return pretrigger
|
||||||
|
|
||||||
def get_commands_split(self, trigger, splitkey):
|
def get_commands_split(self, trigger, splitkey):
|
||||||
commands = []
|
commands = []
|
||||||
@ -144,7 +147,8 @@ class Commands():
|
|||||||
"trigger_str": first_trigger_str,
|
"trigger_str": first_trigger_str,
|
||||||
"trigger_command": first_trigger_command,
|
"trigger_command": first_trigger_command,
|
||||||
"trigger_hostmask": trigger.hostmask,
|
"trigger_hostmask": trigger.hostmask,
|
||||||
"trigger_sender": trigger.sender
|
"trigger_sender": trigger.sender,
|
||||||
|
"trigger_time": trigger.time
|
||||||
})
|
})
|
||||||
|
|
||||||
for full_trigger_str in triggers:
|
for full_trigger_str in triggers:
|
||||||
@ -213,7 +217,8 @@ class Commands():
|
|||||||
"trigger_str": trigger_str,
|
"trigger_str": trigger_str,
|
||||||
"trigger_command": trigger_command,
|
"trigger_command": trigger_command,
|
||||||
"trigger_hostmask": trigger.hostmask,
|
"trigger_hostmask": trigger.hostmask,
|
||||||
"trigger_sender": trigger.sender
|
"trigger_sender": trigger.sender,
|
||||||
|
"trigger_time": trigger.time
|
||||||
})
|
})
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|||||||
@ -2,7 +2,9 @@ import functools
|
|||||||
|
|
||||||
from sopel_SpiceBot_Core_1 import sb
|
from sopel_SpiceBot_Core_1 import sb
|
||||||
|
|
||||||
# from .comrun import comrun_create
|
from .comrun import ComRun
|
||||||
|
from .validate_trigger import validate_trigger
|
||||||
|
# from .validate_command import validate_command
|
||||||
# from .dispatch_multi import dispatch_multi
|
# from .dispatch_multi import dispatch_multi
|
||||||
# from .pipe_split import pipe_split
|
# from .pipe_split import pipe_split
|
||||||
# from .command_args import command_args
|
# from .command_args import command_args
|
||||||
@ -14,22 +16,34 @@ def prerun(rulematch=False):
|
|||||||
|
|
||||||
def actual_decorator(function):
|
def actual_decorator(function):
|
||||||
|
|
||||||
# @comrun_create(rulematch)
|
|
||||||
# @dispatch_multi()
|
|
||||||
# @pipe_split()
|
|
||||||
# @command_args()
|
|
||||||
# @rule_match()
|
|
||||||
@functools.wraps(function)
|
@functools.wraps(function)
|
||||||
def internal_prerun(bot, trigger, comrun, *args, **kwargs):
|
def internal_prerun(bot, trigger, comrun, *args, **kwargs):
|
||||||
|
|
||||||
# Get list of trigger command(s)
|
# 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,
|
||||||
|
# we are going to redispatch commands
|
||||||
|
# This will give sopel the appearance of recieving individual commands
|
||||||
if len(commands) > 1:
|
if len(commands) > 1:
|
||||||
for trigger_dict in commands[1:]:
|
for trigger_dict in commands:
|
||||||
sb.commands.dispatch(trigger_dict)
|
sb.commands.dispatch(trigger_dict)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# This is where we rebuild trigger
|
||||||
|
# we validate a few things here
|
||||||
|
trigger, redispatch = validate_trigger(trigger)
|
||||||
|
|
||||||
|
# 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
|
||||||
function(bot, trigger, comrun, *args, **kwargs)
|
function(bot, trigger, comrun, *args, **kwargs)
|
||||||
|
|
||||||
# if not comrun.piped:
|
# if not comrun.piped:
|
||||||
|
|||||||
@ -1,33 +1,7 @@
|
|||||||
import functools
|
|
||||||
|
|
||||||
|
|
||||||
class ComRun():
|
class ComRun():
|
||||||
|
|
||||||
def __init__(self, rulematch):
|
def __init__(self, rulematch, trigger):
|
||||||
self.piped = False
|
|
||||||
self.rulematch = rulematch
|
self.rulematch = rulematch
|
||||||
self.say = ""
|
self.original_trigger = trigger
|
||||||
self.trigger_dict = {
|
|
||||||
"trigger_type": None,
|
|
||||||
"trigger_prefix": None,
|
|
||||||
"trigger_str": None,
|
|
||||||
"trigger_command": None,
|
|
||||||
"trigger_hostmask": None,
|
|
||||||
"trigger_sender": None
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def comrun_create(rulematch):
|
|
||||||
"""This Detects --arguments to commands."""
|
|
||||||
|
|
||||||
def actual_decorator(function):
|
|
||||||
|
|
||||||
@functools.wraps(function)
|
|
||||||
def internal_comrun_create(bot, trigger, *args, **kwargs):
|
|
||||||
|
|
||||||
comrun = ComRun(rulematch)
|
|
||||||
|
|
||||||
function(bot, trigger, comrun, *args, **kwargs)
|
|
||||||
|
|
||||||
return internal_comrun_create
|
|
||||||
return actual_decorator
|
|
||||||
|
|||||||
20
sopel_SpiceBot_Core_Prerun/validate_trigger.py
Normal file
20
sopel_SpiceBot_Core_Prerun/validate_trigger.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
from sopel_SpiceBot_Core_1 import sb
|
||||||
|
|
||||||
|
|
||||||
|
def validate_trigger(trigger, trigger_dict):
|
||||||
|
redispatch = False
|
||||||
|
|
||||||
|
trigger_time = trigger.time
|
||||||
|
|
||||||
|
if trigger_dict["trigger_type"] == "command":
|
||||||
|
trigger._pretrigger = sb.commands.generate_pretrigger_command(trigger_dict)
|
||||||
|
elif trigger_dict["trigger_type"] == "nickname_command":
|
||||||
|
trigger._pretrigger = sb.commands.generate_pretrigger_nickname_command(trigger_dict)
|
||||||
|
elif trigger_dict["trigger_type"] == "action_command":
|
||||||
|
trigger._pretrigger = sb.commands.generate_pretrigger_action_command(trigger_dict)
|
||||||
|
|
||||||
|
trigger._pretrigger.time = trigger_time
|
||||||
|
|
||||||
|
return trigger, redispatch
|
||||||
@ -15,6 +15,7 @@ def commands_test(bot, trigger, comrun):
|
|||||||
@plugin.command('testa')
|
@plugin.command('testa')
|
||||||
def commands_test_a(bot, trigger, comrun):
|
def commands_test_a(bot, trigger, comrun):
|
||||||
bot.say("test a")
|
bot.say("test a")
|
||||||
|
bot.say(str(trigger.tags))
|
||||||
|
|
||||||
bot.say("%s" % trigger.hostmask)
|
bot.say("%s" % trigger.hostmask)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user