Commit ba71855e authored by Jeremiah Lowin's avatar Jeremiah Lowin Committed by Nick Groenen

Add support for multiple subcommands

parent 2f58bcff
......@@ -271,21 +271,18 @@ class ErrBot(Backend, StoreMixin):
command = None
args = ''
if not only_check_re_command:
if len(text_split) > 1:
command = (text_split[0] + '_' + text_split[1]).lower()
with self._gbl:
if command in self.commands:
cmd = command
args = ' '.join(text_split[2:])
i = len(text_split)
while cmd is None:
command = '_'.join(text_split[:i])
if not cmd:
command = text_split[0].lower()
args = ' '.join(text_split[1:])
with self._gbl:
if command in self.commands:
cmd = command
if len(text_split) > 1:
args = ' '.join(text_split[1:])
args = ' '.join(text_split[i:])
else:
i -= 1
if i == 0:
break
if command == self.bot_config.BOT_PREFIX: # we did "!!" so recall the last command
if len(user_cmd_history):
......
......@@ -335,3 +335,18 @@ def test_callback_no_command(testbot):
testbot.bot.plugin_manager.update_plugin_places([], extra_plugin_dir)
testbot.exec_command('!plugin activate TestCommandNotFoundFilter')
assert expected_str == testbot.exec_command(cmd)
def test_subcommands(testbot):
# test single subcommand (method is run_subcommands())
cmd = '!run subcommands with these args'
cmd_underscore = '!run_subcommands with these args'
expected_args = 'with these args'
assert expected_args == testbot.exec_command(cmd)
assert expected_args == testbot.exec_command(cmd_underscore)
# test multiple subcmomands (method is run_lots_of_subcommands())
cmd = '!run lots of subcommands with these args'
cmd_underscore = '!run_lots_of_subcommands with these args'
assert expected_args == testbot.exec_command(cmd)
assert expected_args == testbot.exec_command(cmd_underscore)
......@@ -19,3 +19,13 @@ class DummyTest(BotPlugin):
def re_bar(self, msg, match):
"""This runs re_foo."""
return 'bar'
@botcmd
def run_subcommands(self, msg, args):
"""Tests a simple subcommand"""
return args
@botcmd
def run_lots_of_subcommands(self, msg, args):
"""Tests multiple subcommands"""
return args
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment