Exemple #1
0
    def get_balance_confirmed(self):
        # check if user have pending tips
        pending_tips = self.get_balance_pending_tip()
        bot_logger.logger.debug("pending_tips %s" % (str(pending_tips)))

        return crypto.get_user_confirmed_balance(
            self.address) - int(pending_tips)
Exemple #2
0
def info_user(rpc, msg):
    if user_function.user_exist(msg.author.name):
        address = user_function.get_user_address(msg.author.name)
        balance = crypto.get_user_confirmed_balance(rpc, msg.author.name)
        pending_balance = crypto.get_user_unconfirmed_balance(
            rpc, msg.author.name)
        spendable_balance = crypto.get_user_spendable_balance(
            rpc, msg.author.name) + balance
        balance_value_usd = utils.get_coin_value(balance)
        pending_value_usd = utils.get_coin_value(pending_balance)
        spendable_value_usd = utils.get_coin_value(spendable_balance)
        msg.reply(
            Template(lang.message_account_details +
                     lang.message_footer).render(
                         username=msg.author.name,
                         balance=str(balance),
                         balance_value_usd=str(balance_value_usd),
                         pendingbalance=str(pending_balance),
                         pending_value_usd=str(pending_value_usd),
                         spendablebalance=str(spendable_balance),
                         spendable_value_usd=str(spendable_value_usd),
                         address=address))

    else:
        msg.reply(
            Template(lang.message_need_register +
                     lang.message_footer).render(username=msg.author.name))
Exemple #3
0
def balance_user(rpc, msg):
    if user_function.user_exist(msg.author.name):

        balance = crypto.get_user_confirmed_balance(rpc, msg.author.name)
        pending_balance = crypto.get_user_unconfirmed_balance(
            rpc, msg.author.name)
        spendable_balance = crypto.get_user_spendable_balance(
            rpc, msg.author.name) + balance
        bot_logger.logger.info('user %s balance = %s' %
                               (msg.author.name, balance))

        balance_value_usd = utils.get_coin_value(balance)
        pending_value_usd = utils.get_coin_value(pending_balance)
        spendable_value_usd = utils.get_coin_value(spendable_balance)
        msg.reply(
            Template(lang.message_balance + lang.message_footer).render(
                username=msg.author.name,
                balance=str(balance),
                balance_value_usd=str(balance_value_usd),
                pendingbalance=str(pending_balance),
                pending_value_usd=str(pending_value_usd),
                spendablebalance=str(spendable_balance),
                spendable_value_usd=str(spendable_value_usd)))

        user_function.add_to_history(msg.author.name, "", "", balance,
                                     "balance")
    else:
        bot_logger.logger.info('user %s not registered ' % msg.author.name)
        msg.reply(
            Template(lang.message_need_register +
                     lang.message_footer).render(username=msg.author.name))
Exemple #4
0
def register_user(rpc, msg):
    if not user_function.user_exist(msg.author.name):
        address = rpc.getnewaddress("reddit-%s" % msg.author.name)
        if address:
            msg.reply(
                Template(lang.message_register_success +
                         lang.message_footer).render(username=msg.author.name,
                                                     address=address))
            user_function.add_user(msg.author.name, address)

            user_function.add_to_history(msg.author.name, "", "", "",
                                         "register")

            # create a backup of wallet
            rpc.backupwallet(
                config.backup_wallet_path + "backup_" +
                datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + ".dat")
        else:
            bot_logger.logger.warning('Error during register !')
    else:
        bot_logger.logger.info('%s are already registered ' % msg.author.name)
        balance = crypto.get_user_confirmed_balance(rpc, msg.author.name)
        address = user_function.get_user_address(msg.author.name)
        msg.reply(
            Template(lang.message_already_registered +
                     lang.message_account_details +
                     lang.message_footer).render(username=msg.author.name,
                                                 address=address,
                                                 balance=str(balance)))
Exemple #5
0
def withdraw_user(rpc, msg, failover_time):
    split_message = msg.body.strip().split()

    if user_function.user_exist(msg.author.name):
        sender_address = user_function.get_user_address(msg.author.name)
        amount = float(split_message[1])
        amount = round(amount - 0.5)
        print(amount)
        user_balance = crypto.get_user_confirmed_balance(rpc, msg.author.name)
        user_spendable_balance = crypto.get_user_spendable_balance(
            rpc, msg.author.name)
        if utils.check_amount_valid(
                amount) and split_message[4] != sender_address:
            if amount >= float(user_balance) + float(user_spendable_balance):
                bot_logger.logger.info(
                    'user %s not have enough to withdraw this amount (%s), balance = %s'
                    % (msg.author.name, amount, user_balance))
                msg.reply(
                    Template(lang.message_balance_low_withdraw).render(
                        username=msg.author.name,
                        user_balance=str(user_balance),
                        amount=str(amount)) + lang.message_footer)
            else:
                receiver_address = split_message[4]
                if time.time() > int(failover_time.value) + 86400:
                    send = crypto.send_to(rpc, sender_address,
                                          receiver_address, amount)
                else:
                    send = crypto.send_to_failover(rpc, sender_address,
                                                   receiver_address, amount)

                if send:
                    user_function.add_to_history(msg.author.name,
                                                 sender_address,
                                                 receiver_address, amount,
                                                 "withdraw")
                    value_usd = utils.get_coin_value(amount)
                    msg.reply(
                        Template(lang.message_withdraw +
                                 lang.message_footer).render(
                                     username=msg.author.name,
                                     receiver_address=receiver_address,
                                     amount=str(amount),
                                     value_usd=str(value_usd)))

        elif split_message[4] == sender_address:
            msg.reply(lang.message_withdraw_to_self + lang.message_footer)
        else:
            bot_logger.logger.info(lang.message_invalid_amount)
            msg.reply(lang.message_invalid_amount + lang.message_footer)
    else:
        msg.reply(
            Template(lang.message_need_register +
                     lang.message_footer).render(username=msg.author.name))
Exemple #6
0
def tip_user(rpc, reddit, msg, tx_queue, failover_time):
    bot_logger.logger.info('An user mention detected ')
    bot_logger.logger.debug("failover_time : %s " % (str(failover_time.value)))

    split_message = msg.body.lower().strip().split()
    tip_index = split_message.index(str('+/u/' + config.bot_name))

    if split_message[tip_index] == str(
            '+/u/' + config.bot_name) and split_message[tip_index +
                                                        2] == 'doge':

        amount = float(split_message[tip_index + 1])
        amount = round(amount - 0.5)
        if utils.check_amount_valid(amount):
            parent_comment = msg.parent()
            if user_function.user_exist(msg.author.name) and (
                    msg.author.name != parent_comment.author.name):

                # check we have enough
                user_balance = crypto.get_user_confirmed_balance(
                    rpc, msg.author.name)
                user_pending_balance = crypto.get_user_unconfirmed_balance(
                    rpc, msg.author.name)

                user_spendable_balance = crypto.balance_user(
                    rpc, msg, failover_time)
                bot_logger.logger.debug('user_spendable_balance = %s' %
                                        user_spendable_balance)

                # in failover we need to use only user_balance
                if amount >= float(user_spendable_balance):
                    # not enough for tip
                    if amount < float(user_pending_balance):
                        reddit.redditor(msg.author.name).message(
                            'pending tip',
                            Template(lang.message_balance_pending_tip).render(
                                username=msg.author.name))
                    else:
                        bot_logger.logger.info(
                            'user %s not have enough to tip this amount (%s), balance = %s'
                            %
                            (msg.author.name, str(amount), str(user_balance)))
                        reddit.redditor(msg.author.name).message(
                            'low balance',
                            Template(lang.message_balance_low_tip).render(
                                username=msg.author.name))
                else:

                    value_usd = utils.get_coin_value(amount)

                    # check user have address before tip
                    if user_function.user_exist(parent_comment.author.name):
                        txid = crypto.tip_user(rpc, msg.author.name,
                                               parent_comment.author.name,
                                               amount, tx_queue, failover_time)
                        if txid:
                            user_function.add_to_history(
                                msg.author.name, msg.author.name,
                                parent_comment.author.name, amount, "tip send",
                                txid)
                            user_function.add_to_history(
                                parent_comment.author.name, msg.author.name,
                                parent_comment.author.name, amount,
                                "tip receive", txid)

                            bot_logger.logger.info(
                                '%s tip %s to %s' %
                                (msg.author.name, str(amount),
                                 parent_comment.author.name))
                            # if user have 'verify' in this command he will have confirmation
                            if split_message.count(
                                    'verify') or int(amount) >= 1000:
                                msg.reply(
                                    Template(lang.message_tip).render(
                                        sender=msg.author.name,
                                        receiver=parent_comment.author.name,
                                        amount=str(int(amount)),
                                        value_usd=str(value_usd),
                                        txid=txid))
                    else:
                        user_function.save_unregistered_tip(
                            msg.author.name, parent_comment.author.name,
                            amount, msg.fullname)
                        user_function.add_to_history(
                            msg.author.name, msg.author.name,
                            parent_comment.author.name, amount, "tip send",
                            False)
                        user_function.add_to_history(
                            parent_comment.author.name, msg.author.name,
                            parent_comment.author.name, amount, "tip receive",
                            False)
                        bot_logger.logger.info('user %s not registered' %
                                               parent_comment.author.name)
                        reddit.redditor(msg.author.name).message(
                            'tipped user not registered',
                            Template(lang.message_recipient_register).render(
                                username=parent_comment.author.name))

                        reddit.redditor(parent_comment.author.name).message(
                            Template(lang.message_recipient_need_register_title
                                     ).render(amount=str(amount)),
                            Template(
                                lang.message_recipient_need_register_message).
                            render(username=parent_comment.author.name,
                                   sender=msg.author.name,
                                   amount=str(amount),
                                   value_usd=str(value_usd)))
            elif user_function.user_exist(
                    msg.author.name) and (msg.author.name
                                          == parent_comment.author.name):
                reddit.redditor(msg.author.name).message(
                    'cannot tip self',
                    Template(lang.message_recipient_self).render(
                        username=msg.author.name))
            else:
                reddit.redditor(msg.author.name).message(
                    'tipped user not registered',
                    Template(lang.message_need_register).render(
                        username=msg.author.name))
        else:
            bot_logger.logger.info(lang.message_invalid_amount)
            reddit.redditor(msg.author.name).message(
                'invalid amount', lang.message_invalid_amount)