Source code for errbot.backends.null

import logging
from time import sleep

from errbot.backends.base import ONLINE
from errbot.backends.test import TestPerson
from errbot.core import ErrBot

log = logging.getLogger(__name__)


[docs]class ConnectionMock:
[docs] def send(self, msg): pass
[docs] def send_message(self, msg): pass
[docs]class NullBackend(ErrBot): conn = ConnectionMock() running = True
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bot_identifier = self.build_identifier("Err") # whatever
[docs] def serve_forever(self): self.connect() # be sure we are "connected" before the first command self.connect_callback() # notify that the connection occured try: while self.running: sleep(1) except EOFError: pass except KeyboardInterrupt: pass finally: log.debug("Trigger disconnect callback") self.disconnect_callback() log.debug("Trigger shutdown") self.shutdown()
[docs] def connect(self): if not self.conn: self.conn = ConnectionMock() return self.conn
[docs] def build_identifier(self, strrep): return TestPerson(strrep)
[docs] def shutdown(self): if self.running: self.running = False super().shutdown() # only once (hackish)
[docs] def change_presence(self, status: str = ONLINE, message: str = "") -> None: pass
[docs] def build_reply(self, msg, text=None, private=False, threaded=False): pass
[docs] def prefix_groupchat_reply(self, message, identifier): pass
[docs] def query_room(self, room): pass
[docs] def rooms(self): pass
@property def mode(self): return "null"