Esempio n. 1
0
    def buy(self, params, sender):
        buyer  = self._parseHandle(sender)
        user_sold = self._parseHandle(params[0])

        if userExists(user_sold, self.twitterAPI):
            transaction = self.friendBizAPI.buy(buyer, user_sold)

            if transaction.status == TransactionValues.STATUS_SUCCESS:
                if transaction.seller_id is not None:
                    seller = self.friendBizAPI.getUserByID(transaction.seller_id)
                    self._tweet('@' + sender + ', congrats! You bought @' + user_sold + ' from @' + seller.handle + ' for ' + str(transaction.amount))
                else:
                    self._tweet('@' + sender + ', congrats! You bought @' + user_sold + ' for ' + str(transaction.amount))

            else:
                if transaction.reason == TransactionValues.BUY_FAIL_INSUFFICIENT_CREDIT:
                    b = self.friendBizAPI.getUserByHandle(buyer)
                    self._tweet('@' + sender + ', you don\'t have enough credit to buy @' +
                               user_sold +'. You have ' + str(b.balance) + ', you need ' + str(transaction.amount))

                elif transaction.reason == TransactionValues.BUY_FAIL_ALREADY_OWNER:
                    self._tweet('@' + sender + ', you already own @' + user_sold)

                elif transaction.reason == TransactionValues.BUY_FAIL_CANT_BUY_YOURSELF:
                    self._tweet('@' + sender + ', you can\'t buy yourself ;)')

                else:
                    print("Buy transaction failed: " + transaction.__repr__())
Esempio n. 2
0
    def status(self, params, sender):
        handle = self._parseHandle(params[0])

        if userExists(handle, self.twitterAPI):
            u = self.friendBizAPI.getOrCreateUserByHandle(handle)
            self._tweet('@' + sender + ', ' + prettyStatus(u))