added room events for specific rooms, added buildForm to xep_0004 plugin

This commit is contained in:
Nathan Fritz 2010-09-23 00:51:23 +00:00
parent d576e32f7a
commit c258d2f19d
2 changed files with 28 additions and 3 deletions

View file

@ -54,7 +54,7 @@ class Form(ElementBase):
field['options'] = options field['options'] = options
return field return field
def getXML(self): def getXML(self, type='submit'):
logging.warning("Form.getXML() is deprecated API compatibility with plugins/old_0004.py") logging.warning("Form.getXML() is deprecated API compatibility with plugins/old_0004.py")
return self.xml return self.xml
@ -387,3 +387,6 @@ class xep_0004(base.base_plugin):
def handle_form(self, message): def handle_form(self, message):
self.xmpp.event("message_xform", message) self.xmpp.event("message_xform", message)
def buildForm(self, xml):
return Form(xml=xml)

View file

@ -120,20 +120,34 @@ class xep_0045(base.base_plugin):
def handle_groupchat_presence(self, pr): def handle_groupchat_presence(self, pr):
""" Handle a presence in a muc. """ Handle a presence in a muc.
""" """
got_offline = False
got_online = False
if pr['muc']['room'] not in self.rooms.keys(): if pr['muc']['room'] not in self.rooms.keys():
return return
entry = pr['muc'].getStanzaValues() entry = pr['muc'].getStanzaValues()
entry['show'] = pr['show']
entry['status'] = pr['status']
if pr['type'] == 'unavailable': if pr['type'] == 'unavailable':
del self.rooms[entry['room']][entry['nick']] if entry['nick'] in self.rooms[entry['room']]:
del self.rooms[entry['room']][entry['nick']]
got_offline = True
else: else:
if entry['nick'] not in self.rooms[entry['room']]:
got_online = True
self.rooms[entry['room']][entry['nick']] = entry self.rooms[entry['room']][entry['nick']] = entry
logging.debug("MUC presence from %s/%s : %s" % (entry['room'],entry['nick'], entry)) logging.debug("MUC presence from %s/%s : %s" % (entry['room'],entry['nick'], entry))
self.xmpp.event("groupchat_presence", pr) self.xmpp.event("groupchat_presence", pr)
self.xmpp.event("muc::%s::presence" % entry['room'], pr)
if got_offline:
self.xmpp.event("muc::%s::got_offline" % entry['room'], pr)
if got_online:
self.xmpp.event("muc::%s::got_online" % entry['room'], pr)
def handle_groupchat_message(self, msg): def handle_groupchat_message(self, msg):
""" Handle a message event in a muc. """ Handle a message event in a muc.
""" """
self.xmpp.event('groupchat_message', msg) self.xmpp.event('groupchat_message', msg)
self.xmpp.event("muc::%s::message" % msg['from'].bare, msg)
def jidInRoom(self, room, jid): def jidInRoom(self, room, jid):
for nick in self.rooms[room]: for nick in self.rooms[room]:
@ -141,6 +155,12 @@ class xep_0045(base.base_plugin):
if entry is not None and entry['jid'].full == jid: if entry is not None and entry['jid'].full == jid:
return True return True
return False return False
def getNick(self, room, jid):
for nick in self.rooms[room]:
entry = self.rooms[room][nick]
if entry is not None and entry['jid'].full == jid:
return nick
def getRoomForm(self, room, ifrom=None): def getRoomForm(self, room, ifrom=None):
iq = self.xmpp.makeIqGet() iq = self.xmpp.makeIqGet()
@ -256,13 +276,14 @@ class xep_0045(base.base_plugin):
def getRoomConfig(self, room): def getRoomConfig(self, room):
iq = self.xmpp.makeIqGet('http://jabber.org/protocol/muc#owner') iq = self.xmpp.makeIqGet('http://jabber.org/protocol/muc#owner')
iq['to'] = room iq['to'] = room
iq['from'] = self.xmpp.jid
result = iq.send() result = iq.send()
if result is None or result['type'] != 'result': if result is None or result['type'] != 'result':
raise ValueError raise ValueError
form = result.xml.find('{http://jabber.org/protocol/muc#owner}query/{jabber:x:data}x') form = result.xml.find('{http://jabber.org/protocol/muc#owner}query/{jabber:x:data}x')
if form is None: if form is None:
raise ValueError raise ValueError
return self.xmpp.plugin['old_0004'].buildForm(form) return self.xmpp.plugin['xep_0004'].buildForm(form)
def cancelConfig(self, room): def cancelConfig(self, room):
query = ET.Element('{http://jabber.org/protocol/muc#owner}query') query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
@ -277,6 +298,7 @@ class xep_0045(base.base_plugin):
query.append(x) query.append(x)
iq = self.xmpp.makeIqSet(query) iq = self.xmpp.makeIqSet(query)
iq['to'] = room iq['to'] = room
iq['from'] = self.xmpp.jid
iq.send() iq.send()
def getJoinedRooms(self): def getJoinedRooms(self):