Exemplo n.º 1
0
 def messageReceived(self, cnx, msg):
     from command import parse as parseCommand, Command
     (action, args) = parseCommand(msg.getBody())
     command = Command(action, args, self)
     msg = msg.buildReply(command.execute(UserAccount(msg.getFrom())))
     msg.setType('chat')
     cnx.send(msg)
     raise NodeProcessed
Exemplo n.º 2
0
    def test_parseCommand(self):
        # test a correct connect
        args = "connect   lash   127.0.0.1"
        pssName, cmd, params = command.parseCommand(args)

        self.assertEqual(pssName, None)
        self.assertEqual(cmd, "connect")
        self.assertEqual(params, ["lash", "127.0.0.1"])

        # test a malformed command
        argList = "me connect   lash   127.0.0.1"
        with self.assertRaises(command.CommandException) as context:
            command.parseCommand(argList)
        self.assertTrue(
            "connect command isn't bound to a pssName" in context.exception)

        # test an unknown command
        argList = "test whatever string"
        with self.assertRaises(command.CommandException) as context:
            command.parseCommand(argList)
        self.assertTrue("command unknown" in context.exception)
Exemplo n.º 3
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