Added support for password protected rooms

master
Ciaran Gultnieks 2010-11-09 11:36:25 +00:00
parent b2d26a1377
commit 1004b17c65
2 changed files with 7 additions and 3 deletions

View File

@ -13,11 +13,12 @@ NS_XHTML_W3C = 'http://www.w3.org/1999/xhtml'
class CommitBot(XMPPHandler):
def __init__(self, room, nick):
def __init__(self, room, nick, password=None):
XMPPHandler.__init__(self)
self.room = room
self.nick = nick
self.password = password
def connectionMade(self):
self.send(AvailablePresence())
@ -27,7 +28,9 @@ class CommitBot(XMPPHandler):
# join room
pres = Presence()
pres['to'] = self.room + '/' + self.nick
pres.addElement((NS_MUC, 'x'))
x = pres.addElement((NS_MUC, 'x'))
if not self.password is None:
x.addElement('password', content = self.password)
self.send(pres)
def notify(self, data):

View File

@ -13,7 +13,8 @@ application = service.Application('commitbot')
client = XMPPClient(jid.internJID('user@example.com'), 'password')
client.logTraffic = True
bot = CommitBot('room@chat.example.com', 'gitbot')
#In the next line, replace None with the password, for a protected room
bot = CommitBot('room@chat.example.com', 'gitbot', None)
bot.setHandlerParent(client)
client.setServiceParent(application)