Added support for password protected rooms
This commit is contained in:
parent
b2d26a1377
commit
1004b17c65
@ -13,11 +13,12 @@ NS_XHTML_W3C = 'http://www.w3.org/1999/xhtml'
|
|||||||
|
|
||||||
class CommitBot(XMPPHandler):
|
class CommitBot(XMPPHandler):
|
||||||
|
|
||||||
def __init__(self, room, nick):
|
def __init__(self, room, nick, password=None):
|
||||||
XMPPHandler.__init__(self)
|
XMPPHandler.__init__(self)
|
||||||
|
|
||||||
self.room = room
|
self.room = room
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
|
self.password = password
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
self.send(AvailablePresence())
|
self.send(AvailablePresence())
|
||||||
@ -27,7 +28,9 @@ class CommitBot(XMPPHandler):
|
|||||||
# join room
|
# join room
|
||||||
pres = Presence()
|
pres = Presence()
|
||||||
pres['to'] = self.room + '/' + self.nick
|
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)
|
self.send(pres)
|
||||||
|
|
||||||
def notify(self, data):
|
def notify(self, data):
|
||||||
|
@ -13,7 +13,8 @@ application = service.Application('commitbot')
|
|||||||
client = XMPPClient(jid.internJID('user@example.com'), 'password')
|
client = XMPPClient(jid.internJID('user@example.com'), 'password')
|
||||||
client.logTraffic = True
|
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)
|
bot.setHandlerParent(client)
|
||||||
|
|
||||||
client.setServiceParent(application)
|
client.setServiceParent(application)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user