Esempio n. 1
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))
Esempio n. 2
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))
Esempio n. 3
0
def withdraw_user(msg, failover_time):
    split_message = msg.body.strip().split()

    user = models.User(msg.author.name)
    if user.is_registered():

        if utils.check_amount_valid(
                split_message[1]) and split_message[4] != user.address:
            amount = float(split_message[1])
            amount = round(amount - 0.5)

            user_balance = user.get_balance_confirmed()
            user_spendable_balance = crypto.get_user_spendable_balance(
                user.username)

            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'
                    % (user.username, amount, user_balance))
                msg.reply(
                    Template(lang.message_balance_low_withdraw).render(
                        username=user.username,
                        user_balance=str(user_balance),
                        amount=str(amount)) + lang.message_footer)
            else:
                receiver_address = split_message[4]
                tip_id = random.randint(0, 99999999)

                history.add_to_history(user.username, user.username,
                                       receiver_address, amount, "withdraw",
                                       "", tip_id)

                send = crypto.tip_user(user.address, receiver_address, amount,
                                       None, failover_time)

                if send:
                    history.update_withdraw(user.username, True, send, tip_id)

                    value_usd = utils.get_coin_value(amount)
                    msg.reply(
                        Template(lang.message_withdraw +
                                 lang.message_footer).render(
                                     username=user.username,
                                     receiver_address=receiver_address,
                                     amount=str(amount),
                                     value_usd=str(value_usd)))

        elif split_message[4] == user.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))
Esempio n. 4
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))
Esempio n. 5
0
def register_user(msg, reddit):
    rpc = crypto.get_rpc()

    user = models.User(msg.author.name)
    if not user.is_registered():
        user.get_new_address()
        if user.address:
            content_reply = Template(lang.message_register_success +
                                     lang.message_footer).render(
                                         username=user.username,
                                         address=user.address)
            tittle_reply = 'you are registered'

            user_function.add_user(msg.author.name, user.address)

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

            # create a backup of wallet
            crypto.backup_wallet()
        else:
            bot_logger.logger.warning('Error during register !')
    else:
        bot_logger.logger.info('%s are already registered ' % msg.author.name)

        balance = user.get_balance_confirmed()
        pending_balance = user.get_balance_unconfirmed()
        spendable_balance = crypto.get_user_spendable_balance(
            msg.author.name) + balance
        pending_value_usd = utils.get_coin_value(pending_balance)
        spendable_value_usd = utils.get_coin_value(spendable_balance)
        content_reply = Template(
            lang.message_already_registered + lang.message_account_details +
            lang.message_footer).render(
                username=msg.author.name,
                address=user.address,
                pending_balance=str(pending_balance),
                pending_value_usd=str(pending_value_usd),
                spendable_balance=str(spendable_balance),
                spendable_value_usd=str(spendable_value_usd))
        tittle_reply = 'you are already registered'

    # send PM so just reply
    if type(msg) is Message:
        msg.reply(content_reply)

    # we have just comment so send info in PM
    if type(msg) is Comment:
        reddit.redditor(msg.author.name).message(tittle_reply, content_reply)
Esempio n. 6
0
    def get_balance(self, failover_time=None):
        balance = 0
        if self.is_registered():

            # get confirmed balance
            balance = float(self.get_balance_confirmed())

            # get unconfirmed balance come of bot
            balance += float(crypto.get_user_spendable_balance(self.address))

            if failover_time is not None and type(failover_time) is type(
                    multiprocessing.Value):
                # if we call function without failover_time, we consider we are in safe mode
                if int(time.time()) > int(failover_time.value) + 86400:
                    # not in safe mode so add unconfirmed balance
                    balance += float(self.get_balance_unconfirmed())

        return balance
Esempio n. 7
0
def info_user(msg):
    rpc = crypto.get_rpc()

    user = models.User(msg.author.name)
    if user.is_registered():
        balance = user.get_balance_confirmed()

        # pending_tips is balance of tip send to unregistered users
        pending_tips = user.get_balance_unregistered_tip()

        pending_balance = user.get_balance_unconfirmed()
        spendable_balance = crypto.get_user_spendable_balance(
            msg.author.name) + balance

        bot_logger.logger.info('user %s balance = %s' %
                               (msg.author.name, balance))
        bot_logger.logger.info('user %s spendable_balance = %s' %
                               (msg.author.name, spendable_balance))

        pending_value_usd = utils.get_coin_value(pending_balance)
        spendable_value_usd = utils.get_coin_value(spendable_balance)
        pending_tips_value_usd = utils.get_coin_value(pending_tips)

        msg.reply(
            Template(lang.message_account_details +
                     lang.message_footer).render(
                         username=msg.author.name,
                         spendable_balance=str(spendable_balance),
                         spendable_value_usd=str(spendable_value_usd),
                         pending_balance=str(pending_balance),
                         pending_value_usd=str(pending_value_usd),
                         pending_tips=str(pending_tips),
                         pending_tips_value_usd=str(pending_tips_value_usd),
                         address=user.address))

        history.add_to_history(msg.author.name, "", "", spendable_balance,
                               "info")
    else:
        bot_logger.logger.info('user %s not registered (command : info) ' %
                               msg.author.name)
        msg.reply(
            Template(lang.message_need_register +
                     lang.message_footer).render(username=msg.author.name))
Esempio n. 8
0
    def parse_message(self, message_to_parse, rpc=None):
        if rpc is None:
            # init rpc to validate address
            rpc = crypto.get_rpc()

        p = re.compile(
            '(\+\/u\/' + config.bot_name + ')\s?(@?[0-9a-zA-Z-_\/\+]+)?\s+(\d+|[0-9a-zA-Z,.]+)\s(doge)\s?(verify)?',
            re.IGNORECASE)
        m = p.search(message_to_parse.strip())
        # Group 1 is +/u/sodogetiptest
        # Group 2 is either blank(tip to the commentor), an address, or a user
        self.receiver = m.group(2)
        # Group 3 is the tip amount in integers(ex.  100) or a word(ex.roll)
        self.amount = m.group(3).replace(',', '.')
        # Group 4 is doge
        self.currency = m.group(4)
        # Group 5 is either blank(no verify message) or verify(verify message)
        self.verify = True if (m.group(5) == "verify") else False

        if self.receiver is not None:
            # to support send tip to username
            if '+/u/' in self.receiver:
                self.receiver = User(self.receiver[4:])
            elif '/u/' in self.receiver:
                self.receiver = User(self.receiver[3:])
            elif 'u/' in self.receiver:
                self.receiver = User(self.receiver[2:])
            elif '@' in self.receiver:
                self.receiver = User(self.receiver[1:])
            # to support send tip to an address
            elif len(self.receiver) == 34 and rpc.validateaddress(self.receiver)['isvalid']:
                address = self.receiver
                bot_logger.logger.info("Send an tip to address")
                self.receiver = User("address-" + address)
                self.receiver.address = address

        # to support any type of randomXXX amount
        if 'random' in self.amount and utils.check_amount_valid(self.amount[6:]):
            self.amount = random.randint(1, int(self.amount[6:]))

        # here amount is numeric, make magic to support not whole tips
        if utils.check_amount_valid(self.amount):
            self.amount = round(float(self.amount) - 0.5)

        # if amount is all, get balance
        if self.amount == 'all':
            # get user balance
            self.amount = crypto.get_user_spendable_balance(self.sender.address, rpc)

        bot_logger.logger.debug("isinstance self.amount = %s" % str(isinstance(self.amount, str)))
        bot_logger.logger.debug("type self.amount = %s" % str(type(self.amount)))

        if type(self.amount) is unicode or type(self.amount) is str:
            bot_logger.logger.debug("self.amount is str")
            if self.amount == "roll":
                self.amount = random.randint(1, 6)

            elif self.amount == "flip":
                self.amount = random.randint(1, 2)

            elif self.amount in config.tip_keyword.keys():
                self.amount = config.tip_keyword[self.amount]

        bot_logger.logger.debug("self.amount = %s" % str(self.amount))

        # if tip is over 1000 doge set verify
        if float(self.amount) >= float(1000):
            self.verify = True