Esempio n. 1
0
    def _expire_pending_tips(self):
        """
        Decline any pending tips that have reached expiration time limit
        """
        # Calculate timestamp
        seconds = int(self._config['misc']['expire_pending_hours'] * 3600)
        created_before = time.mktime(time.gmtime()) - seconds
        counter = 0

        # Get expired actions and decline them
        for a in ctb_action._get_actions(atype='givetip', state='pending', created_utc='< ' + str(created_before), ctb=self):
            a.expire()
            counter += 1

        # Done
        return (counter > 0)
Esempio n. 2
0
    def _self_checks(self):
        """
        Run self-checks before starting the bot
        """
        # Ensure bot is a registered user
        b = ctb_user.CtbUser(name=self._config['reddit']['user'].lower(), ctb=self)
        if not b.is_registered():
            b.register()

        # Ensure (total pending tips) < (CointipBot's balance)
        for c in self._coins:
            ctb_balance = b.get_balance(coin=c, kind='givetip')
            pending_tips = float(0)
            actions = ctb_action._get_actions(atype='givetip', state='pending', coin=c, ctb=self)
            for a in actions:
                pending_tips += a._COIN_VAL
            if (ctb_balance - pending_tips) < -0.000001:
                raise Exception("CointipBot::_self_checks(): CointipBot's %s balance (%s) < total pending tips (%s)" % (c.upper(), ctb_balance, pending_tips))

        # Ensure coin balances are positive
        for c in self._coins:
            b = float(self._coins[c].conn.getbalance())
            if b < 0:
                raise Exception("CointipBot::_self_checks(): negative balance of %s: %s" % (c, b))

        # Ensure user accounts are intact and balances are not negative
        sql = "SELECT username FROM t_users ORDER BY username"
        for mysqlrow in self._mysqlcon.execute(sql):
            u = ctb_user.CtbUser(name=mysqlrow['username'], ctb=self)
            if not u.is_registered():
                raise Exception("CointipBot::_self_checks(): user %s is_registered() failed" % mysqlrow['username'])
        #    for c in self._coins:
        #        if u.get_balance(coin=c, kind='givetip') < 0:
        #            raise Exception("CointipBot::_self_checks(): user %s %s balance is negative" % (mysqlrow['username'], c))

        # Done
        return True