def leavechat(conversation, room): if room is None: room = conversation.buddy.split('@')[0] if not ChatRoom.exists(room): conversation.say("This isn't a chat room.") return if ChatRoom.exists(room): conversation.say("Ok, I will leave the %s chat room." % room) chat = ChatRoom(room) chat.leave() else: conversation.say("I'm not in the \"%s\" chat room." % room)
def receivedMessage(self, e): # Extract the body of the message try: message = str([c for c in e.children if c.name == 'body'][0]) except: log('discarding invalid message (has no body!): %s' % e.toXml()) return # Discard delayed messages delays = [x for x in e.children if x.name == 'delay'] stamps = [ x for x in e.children \ if x.name == 'x' and \ x.compareAttribute('xmlns','jabber:x:delay') and \ x.hasAttribute('stamp') ] #stampstring = str( stamps[0].getAttribute('stamp') ) #timestamp = time.mktime( time.strptime(stampstring, "%Y%m%dT%H:%M:%S") ) if delays or stamps: log('discarding delayed message: %s' % e.toXml()) return # Route message to the right Conversation or ChatRoom entity if e.getAttribute('type') == 'chat': buddy = str(e['from'].split('/')[0]) if not Conversation.exists(buddy): self.requestAuthorization(buddy) log('received message from %s: %s' % (buddy.split('@')[0], message)) Conversation(buddy).hear(message) elif e.getAttribute('type') == 'groupchat': room = e['from'].split('@')[0] log('received message [chatroom=%s]: %s' % (room, message)) ChatRoom(room).hear(message) else: log('received message of unknown type: %s' % e.toXml(), error=True)
def joinEnvironmentalChatRoom(event): """determine if we should join a chatroom""" chat = ChatRoom(config.ROMEO_ENV_NAME) #make sure the drone can be managed by the room username = config.ROMEO_ENV_NAME jbserver = jconfig.JABBER_CHAT_SERVICE jid = "%(username)s@%(jbserver)s" % locals() Team('support').addMember(jid) #get the conversation context set to some sane defaults conversation = Conversation(jid) #grant the room access to the server if jconfig.JABBER_TRUST_ROOM: conversation.grantAuthorization(notify=False) #be vain assume all conversations revolve around ourself context = { 'server': Server(config.HOSTNAME), 'subject': Server(config.HOSTNAME), } conversation.context.update(context) #finally join the room chat.join()
def joinchat(conversation, room): conversation.say("Ok, I will join the %s chat room." % room) chat = ChatRoom(room) chat.join()