Example #1
0
    async def bail(self, ctx):
        """
        Command to bail yourself out of prison.
        :param ctx: Discord Context
        """
        user = prison.getUser(ctx.author.id)
        if len(user) == 0:
            return await ctx.send("Je zit niet in de gevangenis, **{}**.".format(ctx.author.display_name))

        user = user[0]

        # Check if user can afford this
        valid = checks.isValidAmount(ctx, math.floor(user[1]))
        if not valid[0]:
            return await ctx.send(valid[1])

        dinks = currency.dinks(ctx.author.id)
        prison.remove(ctx.author.id)
        currency.update(ctx.author.id, "dinks", float(dinks) - float(user[1]))
        await ctx.send("**{}** heeft zichzelf vrijgekocht!".format(ctx.author.display_name))

        # Update the user's stats
        s = stats.getOrAddUser(ctx.author.id)
        stats.update(ctx.author.id, "bails", int(s[10]) + 1)

        # Increase the bail in the stats file
        with open("files/stats.json", "r") as fp:
            s = json.load(fp)

        s["rob"]["bail_paid"] += float(user[1])

        with open("files/stats.json", "w") as fp:
            json.dump(s, fp)
Example #2
0
    async def prison(self, ctx):
        """
        Command that shows how long you have to sit in prison for.
        :param ctx: Discord Context
        """
        user = prison.getUser(ctx.author.id)

        if len(user) == 0:
            await ctx.send("Je zit niet in de gevangenis, **{}**.".format(ctx.author.display_name))
            return

        user = user[0]

        embed = discord.Embed(colour=discord.Colour.blue())
        embed.set_author(name="De Gevangenis")
        embed.add_field(name="Borgsom:", value="{:,}".format(math.floor(user[1])), inline=False)
        embed.add_field(name="Resterende dagen:", value="{}".format((user[2])), inline=False)
        await ctx.send(embed=embed)
Example #3
0
    async def canRob(self, ctx, target):
        """
        Function that performs checks to see if a user can rob another user.
        In case the rob is not possible, it already sends an error message to show this.
        Returns the database dictionaries corresponding to these two users as they are
        needed in this function anyways, so it prevents an unnecessary database call
        in the rob command.
        :param ctx: Discord Context
        :param target: the target victim to be robbed
        :return: success: boolean, user1 ("Caller"): tuple, user2 ("Target"): tuple
        """
        # Can't rob in DM's
        if str(ctx.channel.type) == "private":
            await ctx.send("Dat doe je niet, {}.".format(
                ctx.author.display_name))
            return False, None, None

        # Can't rob bots
        if str(ctx.author.id) in constants.botIDs:
            await ctx.send("Nee.")

        # Can't rob in prison
        if len(prison.getUser(ctx.author.id)) != 0:
            await ctx.send(
                "Je kan niemand bestelen als je in de gevangenis zit.")
            return False, None, None

        # Check the database for these users
        user1 = currency.getOrAddUser(ctx.author.id)
        user2 = currency.getOrAddUser(target.id)

        # Can't rob without Didier Dinks
        if float(user1[1]) < 1.0:
            await ctx.send("Mensen zonder Didier Dinks kunnen niet stelen.")
            return False, None, None

        # Target has no Didier Dinks to rob
        if float(user2[1]) < 1.0 and float(user2[3]) < 1.0:
            await ctx.send("Deze persoon heeft geen Didier Dinks om te stelen."
                           )
            return False, None, None

        # Passed all tests
        return True, user1, user2
Example #4
0
    async def bankInterest(self):
        """
        Task that gives daily interest
        """
        # Don't do it multiple times a day if bot dc's, ...
        with open("files/lastTasks.json", "r") as fp:
            lastTasks = json.load(fp)
        if int(self.getCurrentHour()) == 0 and int(time.time()) - int(
                lastTasks["interest"]) > 10000:
            users = currency.getAllRows()
            bitcoinPrice = self.getCurrentBitcoinPrice()
            for user in users:
                # People in prison don't get interest
                if len(prison.getUser(int(user[0]))) != 0:
                    continue

                if float(user[3]) != 0.0:
                    currency.update(user[0], "investeddays", int(user[4]) + 1)
                    profit = ((float(user[3]) + float(user[5])) *
                              (1 + (float(user[2]) * 0.01))) - float(user[3])
                    # Can't exceed 1 quadrillion
                    # Check BC as well so they can't put everything into BC to cheat the system
                    if float(user[1]) + float(user[3]) + float(
                            user[5]) + profit + (float(
                                user[8]) * bitcoinPrice) > Numbers.q.value:
                        # In case adding profit would exceed 1q, only add the difference
                        profit = Numbers.q.value - float(user[1]) - float(
                            user[3]) - float(
                                user[5]) - (float(user[8]) * bitcoinPrice)
                        # Don't reduce the current profit if Dinks were gained some other way (rob, bc, ...)
                        if profit > 0:
                            currency.update(user[0], "profit",
                                            float(user[5]) + profit)

                            await self.client.get_user(int(user[0])).send(
                                "Je hebt de invest-limiet van 1Q Didier Dinks bereikt.\nIndien je nog meer Didier Dinks wil sparen, kan je 1q Didier Dinks omruilen voor een Platinum Dink in de shop."
                            )

                    else:
                        currency.update(user[0], "profit",
                                        float(user[5]) + profit)
            lastTasks["interest"] = int(round(time.time()))
            with open("files/lastTasks.json", "w") as fp:
                json.dump(lastTasks, fp)