Example #1
0
    async def open(self, ctx, box_type):
        """Open a box"""

        member = await self.bot.mongo.fetch_member_info(ctx.author)

        box_type = box_type.lower()
        if box_type not in {"nice", "naughty"}:
            return await ctx.send("Need a valid box type!")

        if box_type == "nice" and member.christmas_boxes_nice <= 0:
            return await ctx.send("You don't have enough boxes to do that!")
        if box_type == "naughty" and member.christmas_boxes_naughty <= 0:
            return await ctx.send("You don't have enough boxes to do that!")

        await self.bot.mongo.update_member(
            ctx.author,
            {
                "$inc": {
                    f"christmas_boxes_{box_type}": -1,
                    f"christmas_boxes_{box_type}_opened": 1
                }
            },
        )

        # Go

        if box_type == "nice":
            reward = random.choices(*NICE, k=1)[0]
        else:
            reward = random.choices(*NAUGHTY, k=1)[0]

        if reward == "shards":
            shards = max(round(random.normalvariate(25, 10)), 2)
            await self.bot.mongo.update_member(
                ctx.author, {"$inc": {
                    "premium_balance": shards
                }})
            text = f"{shards} Shards"

        elif reward == "pokecoins":
            pokecoins = max(round(random.normalvariate(1000, 500)), 800)
            await self.bot.mongo.update_member(
                ctx.author, {"$inc": {
                    "balance": pokecoins
                }})
            text = f"{pokecoins} Pokécoins"

        elif reward == "redeem":
            await self.bot.mongo.update_member(ctx.author,
                                               {"$inc": {
                                                   "redeems": 1
                                               }})
            text = "1 redeem"

        elif reward in ("event", "pokemon", "rare", "shiny"):
            pool = [
                x for x in self.pools[reward]
                if x.catchable or reward == "event"
            ]
            species = random.choices(pool,
                                     weights=[x.abundance for x in pool],
                                     k=1)[0]
            level = min(max(int(random.normalvariate(30, 10)), 1), 100)
            shiny = reward == "shiny" or member.determine_shiny(species)
            ivs = [mongo.random_iv() for i in range(6)]

            pokemon = {
                "owner_id": ctx.author.id,
                "owned_by": "user",
                "species_id": species.id,
                "level": level,
                "xp": 0,
                "nature": mongo.random_nature(),
                "iv_hp": ivs[0],
                "iv_atk": ivs[1],
                "iv_defn": ivs[2],
                "iv_satk": ivs[3],
                "iv_sdef": ivs[4],
                "iv_spd": ivs[5],
                "iv_total": sum(ivs),
                "shiny": shiny,
                "idx": await self.bot.mongo.fetch_next_idx(ctx.author),
            }

            text = f"{self.bot.mongo.Pokemon.build_from_mongo(pokemon):lni} ({sum(ivs) / 186:.2%} IV)"

            await self.bot.mongo.db.pokemon.insert_one(pokemon)

        else:
            text = "Nothing"

        embed = self.bot.Embed(
            title=f"🎁 {box_type.title()} Box Reward",
            description=text,
        )
        embed.set_author(icon_url=ctx.author.display_avatar.url,
                         name=str(ctx.author))

        await ctx.send(embed=embed)
Example #2
0
    async def gift(self, ctx, user: discord.Member, *, message):
        if user == ctx.author:
            return await ctx.send("You cannot gift yourself!")

        author_data = await self.bot.mongo.fetch_member_info(ctx.author)
        user_data = await self.bot.mongo.fetch_member_info(user)

        # Checks

        if user_data is None:
            return await ctx.send("That user has not picked a starter Pokémon!"
                                  )

        if author_data.joined_at is not None and author_data.joined_at >= JOIN_DATE:
            return await ctx.send(
                "Your account is not old enough to participate in this event.")
        if user_data.joined_at is not None and user_data.joined_at > JOIN_DATE:
            return await ctx.send(
                "That account is not old enough to participate in this event.")
        if author_data.valentines_purchased >= 5:
            return await ctx.send(
                "You have already purchased the maximum number of gifts!")

        price = 5000 if author_data.valentines_purchased == 0 else 10000
        if author_data.balance < price:
            return await ctx.send("You don't have enough Pokécoins for that!")

        # Confirm

        if not await ctx.confirm(
                f"Are you sure you would like to gift {user.mention} a **Valentine's Nidoran** for **{price:,} Pokécoins**?"
        ):
            return await ctx.send("Aborted.")

        # Go

        species = self.bot.data.species_by_number(50058)
        shiny = user_data.determine_shiny(species)
        level = min(max(int(random.normalvariate(20, 10)), 1), 100)

        ivs = [mongo.random_iv() for i in range(6)]

        author_data = await self.bot.mongo.fetch_member_info(ctx.author)
        if author_data.balance < price:
            return await ctx.send("You don't have enough Pokécoins for that!")
        if author_data.valentines_purchased >= 5:
            return await ctx.send(
                "You have already purchased the maximum number of gifts!")
        await self.bot.mongo.update_member(
            ctx.author,
            {"$inc": {
                "balance": -price,
                "valentines_purchased": 1
            }})

        await self.bot.mongo.db.pokemon.insert_one({
            "owner_id":
            user.id,
            "owned_by":
            "user",
            "species_id":
            species.id,
            "level":
            level,
            "xp":
            0,
            "nature":
            mongo.random_nature(),
            "iv_hp":
            ivs[0],
            "iv_atk":
            ivs[1],
            "iv_defn":
            ivs[2],
            "iv_satk":
            ivs[3],
            "iv_sdef":
            ivs[4],
            "iv_spd":
            ivs[5],
            "iv_total":
            sum(ivs),
            "moves": [],
            "shiny":
            shiny,
            "idx":
            await self.bot.mongo.fetch_next_idx(user),
            "nickname":
            f"Gift from {ctx.author}",
        })

        embed = discord.Embed(
            title="Valentine's Day Card \N{HEART WITH RIBBON}",
            description=message.strip() or "Happy Valentine's Day!",
            color=0xFF6F77,
        )
        embed.set_author(name=ctx.author,
                         icon_url=ctx.author.display_avatar.url)
        embed.set_image(url=species.image_url)
        embed.set_footer(text="You have received a Valentine's Nidoran.")
        await user.send(embed=embed)

        await ctx.send("Your gift has been sent.")
Example #3
0
    async def trickortreat(self, ctx):
        """Use a ticket to trick or treat."""

        member = await self.bot.mongo.fetch_member_info(ctx.author)

        if member.halloween_tickets_2021 <= 0:
            return await ctx.send("You don't have enough tickets to do that!")

        await self.bot.mongo.update_member(ctx.author, {
            "$inc": {
                "halloween_trick_or_treats": 1,
                "halloween_tickets_2021": -1
            }
        })

        # Go

        reward = random.choices(*CRATE_REWARDS, k=1)[0]

        if reward == "shards":
            shards = round(random.normalvariate(25, 10))
            await self.bot.mongo.update_member(
                ctx.author, {"$inc": {
                    "premium_balance": shards
                }})
            text = f"{shards} Shards"

        elif reward == "redeem":
            await self.bot.mongo.update_member(ctx.author,
                                               {"$inc": {
                                                   "redeems": 1
                                               }})
            text = "1 redeem"

        elif reward in ("event", "spooky", "rare", "shiny"):
            pool = [
                x for x in self.pools[reward]
                if x.catchable or reward == "event"
            ]
            species = random.choices(pool,
                                     weights=[x.abundance for x in pool],
                                     k=1)[0]
            level = min(max(int(random.normalvariate(30, 10)), 1), 100)
            shiny = reward == "shiny" or member.determine_shiny(species)
            ivs = [mongo.random_iv() for i in range(6)]

            pokemon = {
                "owner_id": ctx.author.id,
                "owned_by": "user",
                "species_id": species.id,
                "level": level,
                "xp": 0,
                "nature": mongo.random_nature(),
                "iv_hp": ivs[0],
                "iv_atk": ivs[1],
                "iv_defn": ivs[2],
                "iv_satk": ivs[3],
                "iv_sdef": ivs[4],
                "iv_spd": ivs[5],
                "iv_total": sum(ivs),
                "shiny": shiny,
                "idx": await self.bot.mongo.fetch_next_idx(ctx.author),
            }

            text = f"{self.bot.mongo.Pokemon.build_from_mongo(pokemon):lni} ({sum(ivs) / 186:.2%} IV)"

            await self.bot.mongo.db.pokemon.insert_one(pokemon)

        else:
            text = "Nothing"

        embed = self.bot.Embed(
            title="🍬 Treat!" if reward == "event" else "👻 Trick!",
            description=text)
        embed.set_author(icon_url=ctx.author.display_avatar.url,
                         name=str(ctx.author))

        await ctx.send(embed=embed)