Пример #1
0
 def test_allin_low(self):
     self.command("!create")
     replies = self.command("!investi 1000", post="testpost1")
     self.assertEqual(len(replies), 1)
     replies = self.command("!investitutto", post="testpost2")
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body, message.modify_min_invest(0))
Пример #2
0
 def test_allin_low(self):
     self.command('!create')
     replies = self.command('!investi 1000', post='testpost1')
     self.assertEqual(len(replies), 1)
     replies = self.command('!investitutto', post='testpost2')
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body, message.modify_min_invest(0))
Пример #3
0
    def investi(self, sess, comment, investor, amount, suffix):
        """
        This function invests
        """
        if config.CLOSED:
            return comment.reply_wrap(message.CLOSED_ORG)

        multiplier = CommentWorker.multipliers.get(suffix, 1)

        # Allows input such as '!invest 100%' and '!invest 50%'
        if multiplier == "%":
            amount = int(investor.balance * (int(amount) / 100))
        else:
            try:
                amount = int(amount.replace(",", ""))
                amount = amount * multiplier
            except ValueError:
                return

        # Sets the minimum investment to 1% of an investor's balance or 100 Mc
        minim = int(investor.balance / 100)
        if amount < minim or amount < 100:
            return comment.reply_wrap(message.modify_min_invest(minim))

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            return comment.reply_wrap(message.modify_insuff(investor.balance))

        upvotes_now = int(comment.submission.ups)
        # apply 15 minute grace period
        if comment.created_utc - comment.submission.created_utc < 60 * 15:
            upvotes_now = min(upvotes_now,
                              int(math.pow(3, upvotes_now / 5) - 1))
        # 0 upvotes is too strong, so what we do is make around 1 minumum
        if upvotes_now < 1:
            upvotes_now = 1
        deltatime = min(
            int((comment.created_utc - comment.submission.created_utc) / 60),
            60)

        # Sending a confirmation
        response = comment.reply_wrap(
            message.modify_invest(amount, upvotes_now, new_balance))

        sess.add(
            Investment(
                post=comment.submission.id,
                upvotes=upvotes_now,
                deltatime=deltatime,
                comment=comment.id,
                name=author,
                amount=amount,
                response=response.id,
                done=False,
            ))

        investor.balance = new_balance
Пример #4
0
    def invest(self, sess, comment, investor, amount, suffix):
        """
        This function invests
        """
        if config.PREVENT_INSIDERS:
            if comment.submission.author.name == comment.author.name:
                return comment.reply_wrap(message.INSIDE_TRADING_ORG)
        multiplier = CommentWorker.multipliers.get(suffix, 1)

        # Allows input such as '!invest 100%' and '!invest 50%'
        if multiplier == '%':
            amount = int(investor.balance * (int(amount)/100))
        else:
            try:
                amount = int(amount.replace(',', ''))
                amount = amount * multiplier
            except ValueError:
                return

        # Sets the minimum investment to 1% of an investor's balance or 100 Mc
        minim = int(investor.balance / 100)
        if amount < minim or amount < 100:
            return comment.reply_wrap(message.modify_min_invest(minim))

        author = comment.author.name
        new_balance = investor.balance - amount

        if new_balance < 0:
            return comment.reply_wrap(message.modify_insuff(investor.balance))

        # Sending a confirmation
        response = comment.reply_wrap(message.modify_invest(
            amount,
            comment.submission.ups,
            new_balance
        ))

        # 0 upvotes is too OP, so what we do is make around 5 minumum
        upvotes_now = int(comment.submission.ups)
        if upvotes_now < 5:
            upvotes_now = 5

        sess.add(Investment(
            post=comment.submission,
            upvotes=upvotes_now,
            comment=comment,
            name=author,
            amount=amount,
            response=response,
            done=False,
        ))

        investor.balance = new_balance
Пример #5
0
    def test_under_minimum(self):
        self.command('!create')

        replies = self.command('!invest 50')
        self.assertEqual(len(replies), 1)
        self.assertEqual(replies[0], message.modify_min_invest(10))
Пример #6
0
 def test_under_minimum(self):
     self.command("!create")
     replies = self.command("!investi 50")
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body,
                      message.modify_min_invest(1000 / 100))