aboutsummaryrefslogtreecommitdiffstats
path: root/warmachine/connections/base.py
blob: 8b81c144236c6f964f5080fbf0f63d242c7c9aa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
INITALIZED = 'Initalized'
CONNECTED = 'Connected'
CONNECTING = 'Connecting'


class Connection(object):
    def __init__(self):
        self.config_dir = None

    def connect(self, *args, **kwargs):
        """
        This is called by the main start method. It should prepare your
        Connection and connect.
        """
        raise NotImplementedError('{} must implement `connect` method'.format(
            self.__class__.__name__))

    def read(self):
        """
        Dictionary of data in the following format:
        {
          'sender': 'username/id',
          'channel': 'channel name' or None,
          'message': 'actual message',
        }

        Returns:
            dict: Data from the connection that the bot should consider.
        """
        raise NotImplementedError('{} must implement `read` method'.format(
            self.__class__.__name__))

    def id(self):
        """
        Unique ID for this connection. Since there can be more than one
        connection it should be unique per actual connection to the server. For
        example `bot nickname` + `server host:port`. This is used to store
        settings and other information.

        Returns:
           str: Unique ID for this connection object
        """
        raise NotImplementedError('{} must implement `id` method'.format(
            self.__class__.__name__))

    def say(self, message, destination):
        """
        Async method that a plugin can use to send a message to a channel or user.
        """
        raise NotImplementedError('{} must implement `say` method'.format(
            self.__class__.__name__))