diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index 6c8c593..8faa2ff 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -80,6 +80,11 @@ class StateHandler(object): def contains(self, key: Text) -> bool: return key in self.state_ +class BotIdentity(object): + def __init__(self, name: str, email: str) -> None: + self.name = name + self.email = email + self.mention = '@**' + name + '**' class ExternalBotHandler(object): def __init__( @@ -129,6 +134,9 @@ class ExternalBotHandler(object): def storage(self) -> StateHandler: return self._storage + def identity(self) -> BotIdentity: + return BotIdentity(self.full_name, self.email) + def send_message(self, message: (Dict[str, Any])) -> Dict[str, Any]: if not self._rate_limit.is_legal(): self._rate_limit.show_error_and_exit() diff --git a/zulip_bots/zulip_bots/simple_lib.py b/zulip_bots/zulip_bots/simple_lib.py index ca63293..3ee68b1 100644 --- a/zulip_bots/zulip_bots/simple_lib.py +++ b/zulip_bots/zulip_bots/simple_lib.py @@ -1,6 +1,8 @@ import configparser import sys +from zulip_bots.lib import BotIdentity + class SimpleStorage: def __init__(self): self.data = dict() @@ -36,6 +38,9 @@ class TerminalBotHandler: self.storage = SimpleStorage() self.message_server = SimpleMessageServer() + def identity(self): + return BotIdentity("bot name", "bot-email@domain") + def send_message(self, message): if message['type'] == 'stream': print(''' diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index cd32ca2..1cedea4 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -21,6 +21,7 @@ from zulip_bots.test_file_utils import ( read_bot_fixture_data, ) +from zulip_bots.lib import BotIdentity class StubBotHandler: def __init__(self) -> None: @@ -33,6 +34,9 @@ class StubBotHandler: def reset_transcript(self) -> None: self.transcript = [] # type: List[Tuple[str, Dict[str, Any]]] + def identity(self) -> BotIdentity: + return BotIdentity(self.full_name, self.email) + def send_message(self, message: Dict[str, Any]) -> Dict[str, Any]: self.transcript.append(('send_message', message)) return self.message_server.send(message)