Skip to content

Commit d2466f3

Browse files
committed
bots: Enable zulip_bot_output.py to understand default commands.
1 parent 9b9009b commit d2466f3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

zulip_bots/zulip_bots/zulip_bot_output.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mock import MagicMock, patch
1313
from zulip_bots.lib import StateHandler
1414
from zulip_bots.lib import ExternalBotHandler
15+
from zulip_bots.lib import get_bot_details, setup_default_commands, updated_default_commands
1516
from zulip_bots.provision import provision_bot
1617
from zulip_bots.run import import_module_from_source
1718

@@ -66,18 +67,32 @@ def main():
6667
message = {'content': args.message, 'sender_email': '[email protected]'}
6768
message_handler = lib_module.handler_class()
6869

70+
bot_details = get_bot_details(message_handler, args.bot)
71+
72+
default_commands = setup_default_commands(bot_details, message_handler)
73+
updated_defaults = updated_default_commands(default_commands, bot_details)
74+
6975
with patch('zulip.Client') as mock_client:
7076
mock_bot_handler = ExternalBotHandler(mock_client, bot_dir)
7177
mock_bot_handler.send_reply = MagicMock()
7278
mock_bot_handler.send_message = MagicMock()
7379
mock_bot_handler.update_message = MagicMock()
7480
if hasattr(message_handler, 'initialize') and callable(message_handler.initialize):
7581
message_handler.initialize(mock_bot_handler)
76-
message_handler.handle_message(
77-
message=message,
78-
bot_handler=mock_bot_handler,
79-
state_handler=StateHandler()
80-
)
82+
83+
# Check if command handled in library first; if not, then delegate to bot
84+
handled = False
85+
for command in updated_defaults:
86+
if command == message['content']:
87+
mock_bot_handler.send_reply(message,
88+
updated_defaults[command]['action']())
89+
handled = True
90+
if not handled:
91+
message_handler.handle_message(
92+
message=message,
93+
bot_handler=mock_bot_handler,
94+
state_handler=StateHandler()
95+
)
8196
print("On sending {} bot the message \"{}\"".format(bot_name, args.message))
8297
# send_reply and send_message have slightly arguments; the
8398
# following takes that into account.

0 commit comments

Comments
 (0)