コード例 #1
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
コード例 #2
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
コード例 #3
0
ファイル: main.py プロジェクト: sjha2048/memeinvestor_bot
    def invest(self, sess, comment, investor, amount):
        if not isinstance(comment, praw.models.Comment):
            return

        if config.prevent_insiders:
            if comment.submission.author.name == comment.author.name:
                comment.reply_wrap(message.inside_trading_org)
                return

        try:
            amount = int(amount.replace(',',''))
        except ValueError:
            return

        if amount < 100:
            comment.reply_wrap(message.min_invest_org)
            return

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

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

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

        sess.add(Investment(
            post=comment.submission,
            upvotes=comment.submission.ups,
            comment=comment,
            name=author,
            amount=amount,
            response=response,
            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:
                comment.reply_wrap(message.INSIDE_TRADING_ORG)
                return

        try:
            amount = float(amount.replace(',', ''))
            amount = int(amount * CommentWorker.multipliers.get(suffix, 1))
        except ValueError:
            return

        if amount < 100:
            comment.reply_wrap(message.MIN_INVEST_ORG)
            return

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

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

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

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

        investor.balance = new_balance
コード例 #5
0
    def test_insufficient_funds(self):
        self.command('!create')

        replies = self.command('!invest 2000')
        self.assertEqual(len(replies), 1)
        self.assertEqual(replies[0], message.modify_insuff(1000))
コード例 #6
0
ファイル: invest.py プロジェクト: timendum/BancaDelMeme
 def test_insufficient_funds(self):
     self.command("!create")
     replies = self.command("!investi 2000")
     self.assertEqual(len(replies), 1)
     self.assertEqual(replies[0].body, message.modify_insuff(1000))