示例#1
0
def nightly(userid):
    user = getOrAddUser(userid)
    today = datetime.datetime.today().date()
    lastNightly = datetime.datetime.fromtimestamp(user[9]).date()
    streak = int(user[10])
    if lastNightly < today:
        update(userid, "dinks", float(user[1]) + 420.0)
        update(userid, "nightly", int(time.time()))

        # Update the streak
        if (today - lastNightly).days > 1:
            update(userid, "nightly_streak", 1)
            streak = 1
        else:
            update(userid, "nightly_streak", streak + 1)
            streak += 1

        s = stats.getOrAddUser(userid)

        if streak > int(s[5]):
            stats.update(userid, "longest_streak", streak)

        stats.update(userid, "nightlies_count", int(s[6]) + 1)

        return [True, 420, streak]
    return [False, 0, -1]
示例#2
0
文件: stats.py 项目: lars-vc/didier
    async def stats(self, ctx):
        s = stats.getOrAddUser(ctx.author.id)

        # Calculate the percentages
        robAttempts = int(s[2]) + int(
            s[3]) if int(s[2]) + int(s[3]) != 0 else 1
        robSuccessPercent = round(100 * int(s[2]) / robAttempts, 2)
        robFailedPercent = round(100 * int(s[3]) / robAttempts, 2)

        embed = discord.Embed(colour=discord.Colour.blue())
        embed.set_author(name="{}'s Stats".format(ctx.author.display_name))
        embed.add_field(name="Geslaagde Rob Pogingen",
                        value="{} ({})%".format(s[2], robSuccessPercent))
        embed.add_field(name="Gefaalde Rob Pogingen",
                        value="{} ({})%".format(s[3], robFailedPercent))
        embed.add_field(name="Aantal Dinks Gestolen",
                        value="{:,}".format(round(s[4])))
        embed.add_field(name="Aantal Nightlies", value=str(s[6]))
        embed.add_field(name="Langste Nightly Streak", value=str(s[5]))
        embed.add_field(name="Totale Profit", value="{:,}".format(round(s[7])))
        embed.add_field(name="Aantal keer gepoked", value=str(s[1]))
        embed.add_field(name="Aantal Gewonnen Coinflips", value=str(s[8]))
        embed.add_field(name="Totale winst uit Coinflips",
                        value="{:,}".format(round(s[9])))
        embed.add_field(name="Aantal Bails", value="{:,}".format(int(s[10])))
        await ctx.send(embed=embed)
示例#3
0
文件: dinks.py 项目: lars-vc/didier
    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)
示例#4
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.")
示例#5
0
    async def poke(self, ctx, member=None):
        if not await self.pokeChecks(ctx):
            return

        member = ctx.message.mentions[0]
        await ctx.send("**{}** heeft **{}** getikt. **{}** is hem!".format(
            ctx.author.display_name, member.display_name, member.display_name))

        # Add into the database
        poke.update(ctx.author.id, member.id)
        stats.update(member.id, "poked", int(stats.getOrAddUser(member.id)[1]) + 1)
示例#6
0
    async def xp(self, ctx, user: discord.Member = None):
        if user is not None and str(ctx.author.id) != constants.myId:
            return await ctx.send("Je hebt geen toegang tot dit commando.")

        target = user if user is not None else ctx.author

        target_stats = stats.getOrAddUser(target.id)

        embed = discord.Embed(colour=discord.Colour.blue())
        embed.set_author(name=target.display_name, icon_url=target.avatar_url)
        embed.add_field(name="Aantal Berichten", value="{}".format(int(target_stats[11])))
        embed.add_field(name="Level", value=str(xp.calculate_level(target_stats[12])))
        embed.add_field(name="XP", value="{:,}".format(int(target_stats[12])))
        embed.set_footer(text="*Sinds Didier 2.0 Launch")
        await ctx.send(embed=embed)
示例#7
0
文件: games.py 项目: stijndcl/didier
    async def coinflip(self, ctx, *args):
        """
        Command to flip a coin, optionally for Didier Dinks.
        :param ctx: Discord Context
        :param args: bet & wager
        """
        args = list(args)
        choices = ["Kop", "Munt"]
        result = random.choice(choices)

        # No choice made & no wager
        if len(args) == 0:
            await ctx.send("**{}**!".format(result))
            self.updateStats("cf", "h" if result == "Kop" else "t")
            return

        # Check for invalid args
        if len(args) == 1 or args[0][0].lower() not in "kmht":
            return await ctx.send("Controleer je argumenten.")

        args[1] = abbreviated(args[1])
        valid = checks.isValidAmount(ctx, args[1])

        # Invalid amount
        if not valid[0]:
            return await ctx.send(valid[1])

        # Allow full words, abbreviations, and English alternatives
        args[0] = "k" if args[0][0].lower() == "k" or args[0][0].lower(
        ) == "h" else "m"
        won = await self.gamble(ctx, args[0], result, valid[1], 2)

        if won:
            s = stats.getOrAddUser(ctx.author.id)
            stats.update(ctx.author.id, "cf_wins", int(s[8]) + 1)
            stats.update(ctx.author.id, "cf_profit",
                         float(s[9]) + float(valid[1]))

        self.updateStats("cf", "h" if result == "Kop" else "t")
示例#8
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)