xmpp.py 697 Bytes
Newer Older
ale's avatar
ale committed
1
2
3
4
5
6
7
8
9

from sleekxmpp import ClientXMPP


class SendMsgBot(ClientXMPP):
    """XMPP bot that gets online and optionally sends a message."""

    def __init__(self, jid, password, recipient=None, msg=None):
        super(SendMsgBot, self).__init__(jid, password)
ale's avatar
ale committed
10
        self.auto_reconnect = False
ale's avatar
ale committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
        self.reconnect_max_attempts = 0
        self.session_timeout = 5

        self.recipient = recipient
        self.msg = msg

        self.add_event_handler('session_start', self.start)

    def start(self, event):
        self.send_presence()
        self.get_roster()

        if self.recipient:
            self.send_message(mto=self.recipient, mbody=self.msg)

        self.disconnect()