示例#1
0
    async def buy(self, ctx, amount: Abbreviated):
        """
        Command to buy Bitcoins.
        :param ctx: Discord Context
        :param amount: the amount of Bitcoins the user wants to buy
        """

        resp = checks.isValidAmount(ctx, amount)

        # Not a valid amount: send the appropriate error message
        if not resp[0]:
            return await ctx.send(resp[1])

        if amount == "all":
            amount = resp[1]

        # Calculate the amount of Bitcoins the user can buy with [amount] of Didier Dinks
        price = self.getPrice()
        purchased = round(float(amount) / price, 8)

        # Update the db
        currency.update(ctx.author.id, "dinks",
                        float(currency.dinks(ctx.author.id)) - float(amount))
        currency.update(
            ctx.author.id, "bitcoins",
            float(currency.getOrAddUser(ctx.author.id)[8]) + float(purchased))

        await ctx.send(
            "**{}** heeft **{:,}** Bitcoin{} gekocht voor **{:,}** Didier Dink{}!"
            .format(ctx.author.display_name, purchased,
                    checks.pluralS(purchased), round(float(amount)),
                    checks.pluralS(amount)))
示例#2
0
    async def claim(self, ctx, *args):
        """
        Command that claims profit out of the user's Didier Bank.
        :param ctx:
        :param args:
        :return:
        """
        user = currency.getOrAddUser(ctx.author.id)
        args = list(args)
        claimAll = False

        if len(args) == 0:
            args.append("all")
        if args[0] == "all":
            args[0] = float(user[5])
            claimAll = True

        if not claimAll:
            args[0] = abbreviated(str(args[0]))
            if args[0] is None:
                return await ctx.send("Dit is geen geldig bedrag.")

        try:
            # Checks if it can be parsed to int
            _ = int(args[0])
            args[0] = float(args[0])
            # Can't claim more than you have (or negative amounts)
            if args[0] < 0 or args[0] > float(user[5]):
                raise ValueError

            currency.update(ctx.author.id, "profit", float(user[5]) - args[0])
            currency.update(ctx.author.id, "dinks", float(user[1]) + args[0])
            s = stats.getOrAddUser(ctx.author.id)
            stats.update(ctx.author.id, "profit", float(s[7]) + args[0])

            # If you claim everything, you get your invest back as well & your days reset
            if claimAll:
                currency.update(
                    ctx.author.id, "dinks",
                    float(user[1]) + float(user[3]) + float(user[5]))
                currency.update(ctx.author.id, "investedamount", 0.0)
                currency.update(ctx.author.id, "investeddays", 0)
                await ctx.send(
                    "**{}** heeft **{:,}** Didier Dink{} geclaimt!".format(
                        ctx.author.display_name,
                        math.floor(args[0] + float(user[3])),
                        checks.pluralS(math.floor(args[0] + float(user[3])))))
            else:
                await ctx.send(
                    "**{}** heeft **{:,}** Didier Dink{} geclaimt!".format(
                        ctx.author.display_name, math.floor(args[0]),
                        checks.pluralS(math.floor(args[0]))))

        except ValueError:
            await ctx.send("Geef een geldig bedrag op.")
示例#3
0
文件: dinks.py 项目: lars-vc/didier
    async def dinks(self, ctx):
        """
        Command that shows the user's Didier Dinks & Platinum Dinks
        :param ctx: Discord Context
        """
        dinks = currency.dinksAll(ctx.author.id)

        answer = "**{}** heeft **{:,}** Didier Dink{}"\
            .format(ctx.author.display_name, math.floor(dinks["dinks"]), checks.pluralS(dinks["dinks"]))

        if dinks["platinum"] > 0:
            answer += " en **{}** Platinum Dink{}".format(dinks["platinum"], checks.pluralS(dinks["platinum"]))

        await ctx.send(answer + "!")
示例#4
0
    async def invest(self, ctx, *amount: Abbreviated):
        """
        Command that invests Didier Dinks into the user's bank.
        :param ctx: Discord Context
        :param amount: the amount of Didier Dinks to invest
        """
        # Tuples don't support assignment
        amount = list(amount)

        if len(amount) != 1:
            await ctx.send("Geef een geldig bedrag op.")
        elif not checks.isValidAmount(ctx, amount[0])[0]:
            await ctx.send(checks.isValidAmount(ctx, amount[0])[1])
        else:
            user = currency.getOrAddUser(ctx.author.id)
            if str(amount[0]).lower() == "all":
                amount[0] = user[1]

            amount[0] = float(amount[0])
            currency.update(ctx.author.id, "investedamount",
                            float(user[3]) + amount[0])
            currency.update(ctx.author.id, "dinks", float(user[1]) - amount[0])
            await ctx.send(
                "**{}** heeft **{:,}** Didier Dink{} geïnvesteerd!".format(
                    ctx.author.display_name, math.floor(amount[0]),
                    checks.pluralS(amount[0])))
示例#5
0
    async def give(self, ctx, person: discord.Member, amount: Abbreviated):
        """
        Command that gives your Didier Dinks to another user.
        :param ctx: Discord Context
        :param person: user to give the Didier Dinks to
        :param amount: the amount of Didier Dinks to give
        """
        # Invalid amount
        if amount is None:
            return

        # Disable DM abuse
        if ctx.guild is None:
            return await ctx.send("Muttn")

        valid = checks.isValidAmount(ctx, amount)
        if not valid[0]:
            return await ctx.send(valid[1])

        amount = float(valid[1])

        currency.update(ctx.author.id, "dinks",
                        float(currency.dinks(ctx.author.id)) - amount)
        currency.update(person.id, "dinks",
                        float(currency.dinks(person.id)) + amount)

        rep = getRep(math.floor(amount), Numbers.t.value)

        await ctx.send(
            "**{}** heeft **{}** zowaar **{}** Didier Dink{} geschonken!".
            format(ctx.author.display_name, person.display_name, rep,
                   checks.pluralS(amount)))
示例#6
0
    async def bc(self, ctx):
        """
        Command that shows your Bitcoin bank.
        :param ctx: Discord Context
        """
        price = self.getPrice()
        bc = float(currency.getOrAddUser(ctx.author.id)[8])

        currentTime = timeFormatters.dateTimeNow()
        currentTimeFormatted = currentTime.strftime('%m/%d/%Y om %H:%M:%S')

        # Create the embed
        embed = discord.Embed(colour=discord.Colour.gold())
        embed.set_author(
            name="Bitcoin Bank van {}".format(ctx.author.display_name))
        embed.add_field(name="Aantal Bitcoins:",
                        value="{:,}".format(round(bc, 8)),
                        inline=False)
        embed.add_field(name="Huidige waarde:",
                        value="{:,} Didier Dink{}".format(
                            round(bc * price, 8), checks.pluralS(bc * price)),
                        inline=False)
        embed.set_footer(text="Huidige Bitcoin prijs: €{:,} ({})".format(
            price, str(currentTimeFormatted)))

        # Add the Bitcoin icon to the embed
        file = discord.File("files/images/bitcoin.png", filename="icon.png")
        embed.set_thumbnail(url="attachment://icon.png")

        await ctx.send(embed=embed, file=file)
示例#7
0
    async def buy(self, ctx, item, amount: Abbreviated = 1):
        if amount is None:
            return

        try:
            item = int(item)
        except ValueError:
            return await ctx.send("Dit is geen geldig id.")

        success, message = store.buy(ctx, ctx.author.id, item, amount)
        if not success:
            return await ctx.send(message)

        rep = getRep(message["price"], Numbers.t.value)

        return await ctx.send(
            "**{}** heeft **{} {}{}** gekocht voor **{}** Didier Dink{}.".
            format(ctx.author.display_name, amount, message["name"],
                   checks.pluralS(amount), rep,
                   checks.pluralS(message["price"])))
示例#8
0
    async def sell(self, ctx, amount: Abbreviated):
        """
        Command to sell Bitcoins.
        :param ctx: Discord Context
        :param amount: the amount of Bitcoins the user wants to sell
        """
        if amount == "all":
            amount = float(currency.getOrAddUser(ctx.author.id)[8])

        try:
            amount = float(amount)
            if amount <= 0:
                raise ValueError

            bc = float(currency.getOrAddUser(ctx.author.id)[8])

            if bc == 0.0:
                # User has no Bitcoins
                await ctx.send("Je hebt geen Bitcoins, **{}**".format(
                    ctx.author.display_name))
            elif amount > bc:
                # User is trying to sell more Bitcoins that he has
                await ctx.send(
                    "Je hebt niet genoeg Bitcoins om dit te doen, **{}**".
                    format(ctx.author.display_name))
            else:
                price = self.getPrice()
                dinks = float(currency.dinks(ctx.author.id))

                currency.update(ctx.author.id, "bitcoins", bc - amount)
                currency.update(ctx.author.id, "dinks",
                                dinks + (price * amount))

                await ctx.send(
                    "**{}** heeft **{:,}** Bitcoin{} verkocht voor **{:,}** Didier Dink{}!"
                    .format(ctx.author.display_name, round(amount, 8),
                            checks.pluralS(amount), round((price * amount), 8),
                            checks.pluralS(price * amount)))
        except ValueError:
            # Can't be parsed to float -> random string OR smaller than 0
            await ctx.send("Geef een geldig bedrag op.")
示例#9
0
文件: games.py 项目: stijndcl/didier
    async def gamble(self, ctx, bet, result, wager, factor, pre="", post=""):
        """
        Function for gambling because it's the same thing every time.
        :param ctx: Discord Context
        :param bet: the option the user bet on
        :param result: randomly generated result
        :param wager: size of the bet of the user
        :param factor: the factor by which the person's wager is amplified
        :param pre: any string that might have to be pre-pended to the output string
        :param post: any string that might have to be appended to the output string
        :return: a boolean indicating whether or not the user has won
        """
        # Code no longer first removes your bet to then add profit,
        # resulting in triple coinflip profit (@Clement).
        # Subtract one off of the factor to compensate for the initial wager
        factor -= 1
        answer = "**{}**! ".format(result)
        won = False

        # Check if won
        if result[0].lower() == bet[0].lower():
            won = True
            answer += "Je wint **{:,}** Didier Dink{}"
            currency.update(
                ctx.author.id, "dinks",
                float(currency.dinks(ctx.author.id)) + (float(wager) * factor))
        else:
            answer += "Je hebt je inzet (**{:,}** Didier Dink{}) verloren"
            currency.update(
                ctx.author.id, "dinks",
                float(currency.dinks(ctx.author.id)) - float(wager))
            self.loseDinks(round(float(wager)))

        # If won -> multiple dinkS, if lost, it's possible that the user only bet on 1 dinK
        await ctx.send(pre + answer.format(
            round(float(wager) * factor if won else float(wager)),
            checks.pluralS(float(wager) * factor if won else float(wager))) +
                       ", **{}**!".format(ctx.author.display_name))
        return won
示例#10
0
    async def award(self, ctx, user: discord.User, amount: Abbreviated):
        """
        Command that awards a user a certain amount of Didier Dinks.
        :param ctx: Discord Context
        :param user: the user to give the Didier Dinks to
        :param amount: the amount of Didier Dinks to award [user]
        """
        # No amount was passed
        if amount is None:
            return

        # Update the db
        currency.update(user.id, "dinks",
                        float(currency.dinks(user.id)) + float(amount))

        # Gets the abbreviated representation of the amount
        rep = getRep(amount, Numbers.t.value)

        await ctx.send(
            "**{}** heeft **{}** zowaar **{}** Didier Dink{} beloond!".format(
                ctx.author.display_name,
                self.utilsCog.getDisplayName(ctx, user.id), rep,
                checks.pluralS(amount)))
示例#11
0
    async def rob(self, ctx, target: discord.User):
        """
        Command to rob another user.
        :param ctx: Discord Context
        :param target: the target victim to be robbed
        :return:
        """
        canRob, caller, target = await self.canRob(ctx, target)

        if not canRob:
            return

        threshold = 50 + round(int(target[6]) * 0.7)
        rg = random.randint(0 + int(caller[7]), 100)
        stat = stats.getOrAddUser(ctx.author.id)

        # Rob succeeded
        if rg > threshold:
            capacity = float(calcCapacity(caller[7]))
            remaining = capacity

            # Try robbing out of invest first, then Dinks pouch
            amount = capacity if float(target[3]) >= capacity else float(
                target[3])
            remaining -= amount
            currency.update(target[0], "investedamount",
                            float(target[3]) - amount)

            # Rob out of Dinks pouch
            if amount != capacity and not float(target[1]) < 1:
                if float(target[1]) >= remaining:
                    amount += remaining
                    currency.update(target[0], "dinks",
                                    float(target[1]) - remaining)
                else:
                    amount += float(target[1])
                    currency.update(target[0], "dinks", 0.0)

            # Update db
            currency.update(caller[0], "dinks", float(caller[1]) + amount)
            await ctx.send(
                "**{}** heeft **{:,}** Didier Dink{} gestolen van **{}**!".
                format(ctx.author.display_name, math.floor(amount),
                       checks.pluralS(math.floor(amount)),
                       self.utilsCog.getDisplayName(ctx, target[0])))

            stats.update(ctx.author.id, "robs_success", int(stat[2]) + 1)
            stats.update(ctx.author.id, "robs_total", float(stat[4]) + amount)
        else:
            # Rob failed

            # Calculate what happens
            fate = random.randint(1, 10)

            # Leave Dinks behind instead of robbing
            if fate < 8:
                punishment = float(calcCapacity(caller[7])) / 2
                prisoned = round(float(caller[1])) < round(punishment)

                # Doesn't have enough Dinks -> prison
                if prisoned:
                    diff = round(punishment - float(caller[1]))
                    punishment = round(float(caller[1]))
                    days = 1 + round(int(caller[7]) // 10)
                    prison.imprison(caller[0], diff, days,
                                    round(round(diff) // days))

                # Update db
                currency.update(target[0], "dinks",
                                float(target[1]) + punishment)
                currency.update(caller[0], "dinks",
                                float(caller[1]) - punishment)
                await ctx.send(
                    "**{}** was zo vriendelijk om **{}** zowaar **{:,}** Didier Dink{} te geven!"
                    .format(ctx.author.display_name,
                            self.utilsCog.getDisplayName(ctx, target[0]),
                            math.floor(punishment),
                            checks.pluralS(math.floor(punishment))))

                # Can't put this in the previous if- because the value of Punishment changes
                if prisoned:
                    await ctx.send(
                        "Je bent naar de gevangenis verplaatst omdat je niet genoeg Didier Dinks had."
                    )
            elif fate == 9:
                # Prison
                totalSum = round(calcCapacity(caller[7]))
                days = 1 + (int(caller[7]) // 10)

                prison.imprison(caller[0], totalSum, days, totalSum / days)
                await ctx.send(
                    "**{}** niet stelen, **{}** niet stelen!\nJe bent naar de gevangenis verplaatst."
                    .format(ctx.author.display_name, ctx.author.display_name))
            else:
                # Escape
                await ctx.send(
                    "Je poging is mislukt, maar je kon nog net op tijd vluchten, **{}**."
                    "\nAllez, 't is goed voor ene keer e, deugeniet.".format(
                        ctx.author.display_name))

            stats.update(ctx.author.id, "robs_failed", int(stat[3]) + 1)