Ejemplo n.º 1
0
 def invite(self, room, jids, reason=None):
     """Invites user to muc.
     Works only if user has permission to invite to muc"""
     NS_MUCUSER = 'http://jabber.org/protocol/muc#user'
     mess = Message(to=room)
     for jid in jids:
         invite = simplexml.Node('invite')
         invite.setAttr('to', jid)
         if reason is not None:
             invite.setTagData('reason', reason)
         mess.setTag('x', namespace=NS_MUCUSER).addChild(node=invite)
     self.log.info(mess)
     self.connect().send(mess)
Ejemplo n.º 2
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         node = XML2Node(text)
         # logging.debug('This message is XML : %s' % text)
         text_plain = xhtml2txt(text)
         logging.debug('Plain Text translation from XHTML-IM:\n%s' % text_plain)
         message = Message(body=text_plain)
         message.addChild(node = node)
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Ejemplo n.º 3
0
 def build_message(self, text):
     """Builds an xhtml message without attributes.
     If input is not valid xhtml-im fallback to normal."""
     try:
         text = utf8(text)
         XML2Node(text) # test if is it xml
         # yes, ok epurate it for hipchat
         try:
             hipchat_html = xhtml2hipchat(text)
             node = XML2Node(hipchat_html)
             message = Message(body=xhtml2txt(text))
             message.addChild(node = node)
         except ExpatError as ee:
             logging.error('Error translating to hipchat [%s] Parsing error = [%s]' % (hipchat_html, ee))
     except ExpatError as ee:
         if text.strip(): # avoids keep alive pollution
             logging.debug('Determined that [%s] is not XHTML-IM (%s)' % (text, ee))
         message = Message(body=text)
     return message
Ejemplo n.º 4
0
 def messageReceived(self, cnx, msg):
     '''Message received, addressed to the component. The command execution
        can raise exceptions, but those will be taken care of by the
        caller (messageHandler())'''
     user = UserAccount(msg.getFrom())
     if user.isRegistered():
         try:
             address = Address(msg.getBody())
             msg = Message(to=msg.getFrom(), frm=address.jid,\
                   body=_(ROSTER, 'address_start_chat').format(address=address), typ='chat')
         except InvalidBitcoinAddressError:
             (action, args) = parseCommand(msg.getBody())
             if action is None:
                 return
             msg = msg.buildReply(Command(action, args).execute(user))
             msg.setType('chat')
             if user.checkBalance() is not None:
                 self.sendBitcoinPresence(cnx, user)
     else:
         error = _(REGISTRATION, 'error_not_registered')
         msg = msg.buildReply(_(COMMANDS, 'error_message').format(message=error))
         msg.setType('error')
     cnx.send(msg)
     raise NodeProcessed