1import logging
2from time import sleep
3
4from errbot.backends.base import ONLINE
5from errbot.backends.test import TestPerson
6from errbot.core import ErrBot
7
8log = logging.getLogger(__name__)
9
10
11class ConnectionMock:
12    def send(self, msg):
13        pass
14
15    def send_message(self, msg):
16        pass
17
18
19class NullBackend(ErrBot):
20    conn = ConnectionMock()
21    running = True
22
23    def __init__(self, *args, **kwargs):
24        super().__init__(*args, **kwargs)
25        self.bot_identifier = self.build_identifier("Err")  # whatever
26
27    def serve_forever(self):
28        self.connect()  # be sure we are "connected" before the first command
29        self.connect_callback()  # notify that the connection occured
30        try:
31            while self.running:
32                sleep(1)
33
34        except EOFError:
35            pass
36        except KeyboardInterrupt:
37            pass
38        finally:
39            log.debug("Trigger disconnect callback")
40            self.disconnect_callback()
41            log.debug("Trigger shutdown")
42            self.shutdown()
43
44    def connect(self):
45        if not self.conn:
46            self.conn = ConnectionMock()
47        return self.conn
48
49    def build_identifier(self, strrep):
50        return TestPerson(strrep)
51
52    def shutdown(self):
53        if self.running:
54            self.running = False
55            super().shutdown()  # only once (hackish)
56
57    def change_presence(self, status: str = ONLINE, message: str = "") -> None:
58        pass
59
60    def build_reply(self, msg, text=None, private=False, threaded=False):
61        pass
62
63    def prefix_groupchat_reply(self, message, identifier):
64        pass
65
66    def query_room(self, room):
67        pass
68
69    def rooms(self):
70        pass
71
72    @property
73    def mode(self):
74        return "null"
75