Пример #1
0
    def test_broke(self):
        self.command('!create')

        self.set_balance(0)
        replies = self.command('!broke')
        self.assertEqual(len(replies), 1)
        self.assertEqual(replies[0], message.modify_broke(1))

        self.set_balance(0)
        replies = self.command('!broke')
        self.assertEqual(len(replies), 1)
        self.assertEqual(replies[0], message.modify_broke(2))
Пример #2
0
    def broke(self, sess, comment, investor):
        if investor.balance >= 100:
            return comment.reply_wrap(message.modify_broke_money(investor.balance))

        active = sess.query(
            func.count(Investment.id)
        ).filter(Investment.done).filter(Investment.name == investor.name).scalar()
        if active:
            comment.reply_wrap(message.modify_broke_active(active))

        # Indeed, broke
        sess.query(Investor).filter(Investor.name == investor.name).update({
            Investor.balance: 100,
            Investor.broke: investor.broke + 1,
        }, synchronize_session=False)

        comment.reply_wrap(message.modify_broke(investor.broke + 1))
Пример #3
0
    def broke(self, sess, comment, investor):
        if investor.balance >= 100:
            return comment.reply_wrap(message.modify_broke_money(investor.balance))

        active = sess.query(func.count(Investment.id)).\
            filter(Investment.done == 0).\
            filter(Investment.name == investor.name).\
            scalar()

        if active > 0:
            return comment.reply_wrap(message.modify_broke_active(active))

        # Indeed, broke
        investor.balance = 100
        investor.broke += 1

        comment.reply_wrap(message.modify_broke(investor.broke))
Пример #4
0
    def broke(self, sess, comment, investor):
        """
        Checks if the user is broke. If he is, resets his/her balance to 100 MemeCoins
        """
        if investor.balance >= 100:
            return comment.reply_wrap(message.modify_broke_money(investor.balance))

        active = sess.query(func.count(Investment.id)).\
            filter(Investment.done == 0).\
            filter(Investment.name == investor.name).\
            scalar()

        if active > 0:
            return comment.reply_wrap(message.modify_broke_active(active))

        # Indeed, broke
        investor.balance = 100
        investor.broke += 1

        return comment.reply_wrap(message.modify_broke(investor.broke))
Пример #5
0
def broke(comment, author):

    balance_amount = database.investor_get_balance(author)
    active_number = database.investor_get_active(author)

    if (balance_amount < 100):
        if (active_number < 1):
            # Indeed, broke
            database.investor_update_balance(author, 100)
            database.investor_update_active(author, 0)
            broke_times = database.investor_get_broke(author)
            broke_times += 1
            database.investor_update_broke(author, broke_times)
            # Sure, you can do it like
            # database.investor_get_broke(author, database.investor_get_broke(author) + 1)
            # But it is way to messy, we are for the code understandability
            
            send_reply(comment, message.modify_broke(broke_times))
        else:
            # Still has investments
            send_reply(comment, message.modify_broke_active(active_number))
    else:
        # Still can invest
        send_reply(comment, message.modify_broke_money(balance_amount))