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:
parent
fb77f4bad4
commit
0b35ed0a93
|
@ -40,10 +40,10 @@ class SimpleMessageServer:
|
||||||
return dict(result='success', msg='', uri='https://server/user_uploads/{}'.format(uuid4()))
|
return dict(result='success', msg='', uri='https://server/user_uploads/{}'.format(uuid4()))
|
||||||
|
|
||||||
class TerminalBotHandler:
|
class TerminalBotHandler:
|
||||||
def __init__(self, bot_config_file):
|
def __init__(self, bot_config_file, message_server):
|
||||||
self.bot_config_file = bot_config_file
|
self.bot_config_file = bot_config_file
|
||||||
self._storage = SimpleStorage()
|
self._storage = SimpleStorage()
|
||||||
self.message_server = SimpleMessageServer()
|
self.message_server = message_server
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def storage(self):
|
def storage(self):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from zulip_bots.finder import import_module_from_source, resolve_bot_path
|
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__))
|
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.")
|
print("This module does not appear to have a bot handler_class specified.")
|
||||||
sys.exit(1)
|
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):
|
if hasattr(message_handler, 'initialize') and callable(message_handler.initialize):
|
||||||
message_handler.initialize(bot_handler)
|
message_handler.initialize(bot_handler)
|
||||||
|
|
||||||
|
@ -59,11 +60,12 @@ def main():
|
||||||
while True:
|
while True:
|
||||||
content = input('Enter your message: ')
|
content = input('Enter your message: ')
|
||||||
|
|
||||||
message = dict(
|
message = message_server.send(dict(
|
||||||
content=content,
|
content=content,
|
||||||
sender_email=sender_email,
|
sender_email=sender_email,
|
||||||
display_recipient=sender_email,
|
display_recipient=sender_email,
|
||||||
)
|
))
|
||||||
|
|
||||||
message_handler.handle_message(
|
message_handler.handle_message(
|
||||||
message=message,
|
message=message,
|
||||||
bot_handler=bot_handler,
|
bot_handler=bot_handler,
|
||||||
|
|
Loading…
Reference in a new issue