terminal: Extract message server from the handler.

This makes the user and the bot to share the message server when
sending messages. As a result, the message id can be shared. And history
messages sent by the user will be stored as well.
This commit is contained in:
PIG208 2021-05-13 19:36:45 +08:00 committed by Tim Abbott
parent fb77f4bad4
commit 0b35ed0a93
2 changed files with 8 additions and 6 deletions

View file

@ -40,10 +40,10 @@ class SimpleMessageServer:
return dict(result='success', msg='', uri='https://server/user_uploads/{}'.format(uuid4()))
class TerminalBotHandler:
def __init__(self, bot_config_file):
def __init__(self, bot_config_file, message_server):
self.bot_config_file = bot_config_file
self._storage = SimpleStorage()
self.message_server = SimpleMessageServer()
self.message_server = message_server
@property
def storage(self):

View file

@ -4,7 +4,7 @@ import sys
import argparse
from zulip_bots.finder import import_module_from_source, resolve_bot_path
from zulip_bots.simple_lib import TerminalBotHandler
from zulip_bots.simple_lib import SimpleMessageServer, TerminalBotHandler
current_dir = os.path.dirname(os.path.abspath(__file__))
@ -49,7 +49,8 @@ def main():
print("This module does not appear to have a bot handler_class specified.")
sys.exit(1)
bot_handler = TerminalBotHandler(args.bot_config_file)
message_server = SimpleMessageServer()
bot_handler = TerminalBotHandler(args.bot_config_file, message_server)
if hasattr(message_handler, 'initialize') and callable(message_handler.initialize):
message_handler.initialize(bot_handler)
@ -59,11 +60,12 @@ def main():
while True:
content = input('Enter your message: ')
message = dict(
message = message_server.send(dict(
content=content,
sender_email=sender_email,
display_recipient=sender_email,
)
))
message_handler.handle_message(
message=message,
bot_handler=bot_handler,