-
Notifications
You must be signed in to change notification settings - Fork 4
/
base_bot.py
48 lines (37 loc) · 1.5 KB
/
base_bot.py
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
# Georges Toth (c) 2012
from twisted.application import service
from twisted.python import log
from twisted.words.protocols.jabber.jid import JID
from wokkel.client import XMPPClient
from wokkel.muc import MUCClient
class BaseMUCBot(MUCClient):
def __init__(self, roomJID, nick, roomPassword):
MUCClient.__init__(self)
self.roomJID = roomJID
self.nick = nick
self.roomPassword = roomPassword
def connectionInitialized(self):
"""
Once authorized, join the room.
If the join action causes a new room to be created, the room will be
locked until configured. Here we will just accept the default
configuration by submitting an empty form using L{configure}, which
usually results in a public non-persistent room.
Alternatively, you would use L{getConfiguration} to retrieve the
configuration form, and then submit the filled in form with the
required settings using L{configure}, possibly after presenting it to
an end-user.
"""
def joinedRoom(room):
if room.locked:
# Just accept the default configuration.
return self.configure(room.roomJID, {})
MUCClient.connectionInitialized(self)
d = self.join(self.roomJID, self.nick, password=self.roomPassword)
d.addCallback(joinedRoom)
d.addCallback(lambda _: log.msg("Joined room"))
d.addErrback(log.err, "Join failed")
def receivedGroupChat(self, room, user, message):
self.handleGroupChat(room, user, message)
def handleGroupChat(self, room, user, message):
pass