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))
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))
def get_balance_unconfirmed(self): return crypto.get_user_unconfirmed_balance(self.address)
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)