Exemple #1
0
    async def give(self, ctx: commands.Context, user: discord.Member, *,
                   species: str):
        """Give a pokémon."""

        member = await self.db.fetch_member_info(user)

        species = models.GameData.species_by_name(species)

        if species is None:
            return await ctx.send(
                f"Could not find a pokemon matching `{species}`.")

        await self.db.update_member(
            user,
            {
                "$push": {
                    "pokemon": {
                        "species_id": species.id,
                        "level": 1,
                        "xp": 0,
                        "nature": mongo.random_nature(),
                        "iv_hp": mongo.random_iv(),
                        "iv_atk": mongo.random_iv(),
                        "iv_defn": mongo.random_iv(),
                        "iv_satk": mongo.random_iv(),
                        "iv_sdef": mongo.random_iv(),
                        "iv_spd": mongo.random_iv(),
                    }
                },
            },
        )

        await ctx.send(f"Gave {user.mention} a {species}.")
Exemple #2
0
    async def setup(self,
                    ctx: commands.Context,
                    user: discord.Member,
                    num: int = 100):
        """Test setup pokémon."""

        # This is for development purposes.

        member = await self.db.fetch_member_info(user)

        pokemon = []
        idx = await self.db.fetch_next_idx(user, reserve=num)

        for i in range(num):
            spid = random.randint(1, 809)
            pokemon.append({
                "owner_id": user.id,
                "species_id": spid,
                "level": 80,
                "xp": 0,
                "nature": mongo.random_nature(),
                "iv_hp": mongo.random_iv(),
                "iv_atk": mongo.random_iv(),
                "iv_defn": mongo.random_iv(),
                "iv_satk": mongo.random_iv(),
                "iv_sdef": mongo.random_iv(),
                "iv_spd": mongo.random_iv(),
                "shiny": False,
                "idx": idx + i,
            })

        await self.bot.mongo.db.pokemon.insert_many(pokemon)
        await ctx.send(f"Gave {user.mention} {num} pokémon.")
Exemple #3
0
    async def give(self, ctx: commands.Context, user: discord.Member, *,
                   species: str):
        """Give a pokémon."""

        member = await self.db.fetch_member_info(user)

        shiny = False

        if species.lower().startswith("shiny"):
            shiny = True
            species = species.lower().replace("shiny", "").strip()

        species = self.bot.data.species_by_name(species)

        if species is None:
            return await ctx.send(
                f"Could not find a pokemon matching `{species}`.")

        await self.bot.mongo.db.pokemon.insert_one({
            "owner_id":
            user.id,
            "species_id":
            species.id,
            "level":
            1,
            "xp":
            0,
            "nature":
            mongo.random_nature(),
            "iv_hp":
            mongo.random_iv(),
            "iv_atk":
            mongo.random_iv(),
            "iv_defn":
            mongo.random_iv(),
            "iv_satk":
            mongo.random_iv(),
            "iv_sdef":
            mongo.random_iv(),
            "iv_spd":
            mongo.random_iv(),
            "shiny":
            shiny,
            "idx":
            await self.db.fetch_next_idx(user),
        })

        await ctx.send(f"Gave {user.mention} a {species}.")
Exemple #4
0
    async def setup(self,
                    ctx: commands.Context,
                    user: discord.Member,
                    num: int = 100):
        """Test setup pokémon."""

        # This is for development purposes.

        member = await self.db.fetch_member_info(user)

        pokemon = []
        pokedex = {}

        for i in range(num):
            spid = random.randint(1, 809)
            pokemon.append({
                "species_id": spid,
                "level": 80,
                "xp": 0,
                "nature": mongo.random_nature(),
                "iv_hp": mongo.random_iv(),
                "iv_atk": mongo.random_iv(),
                "iv_defn": mongo.random_iv(),
                "iv_satk": mongo.random_iv(),
                "iv_sdef": mongo.random_iv(),
                "iv_spd": mongo.random_iv(),
                "shiny": random.randint(1, 4096) == 1,
            })
            pokedex["pokedex." +
                    str(spid)] = pokedex.get("pokedex." + str(spid), 0) + 1

        await self.db.update_member(
            user,
            {
                "$push": {
                    "pokemon": {
                        "$each": pokemon
                    }
                },
                "$inc": pokedex
            },
        )

        await ctx.send(f"Gave {user.mention} {num} pokémon.")
Exemple #5
0
    async def catch(self, ctx: commands.Context, *, guess: str):
        """Catch a wild pokémon."""

        # Retrieve correct species and level from tracker

        if ctx.channel.id not in self.bot.spawns:
            return

        species, level, hint, shiny, users = self.bot.spawns[ctx.channel.id]

        if (models.deaccent(guess.lower().replace("′", "'"))
                not in species.correct_guesses):
            return await ctx.send("That is the wrong pokémon!")

        # Correct guess, add to database

        if ctx.channel.id == 759559123657293835:
            if ctx.author.id in users:
                return await ctx.send("You have already caught this pokémon!")

            users.append(ctx.author.id)
        else:
            del self.bot.spawns[ctx.channel.id]

        member = await self.db.fetch_member_info(ctx.author)

        if shiny is None:
            shiny = member.determine_shiny(species)

        moves = [x.move.id for x in species.moves if level >= x.method.level]
        random.shuffle(moves)

        await self.bot.mongo.db.pokemon.insert_one({
            "owner_id":
            ctx.author.id,
            "species_id":
            species.id,
            "level":
            level,
            "xp":
            0,
            "nature":
            mongo.random_nature(),
            "iv_hp":
            mongo.random_iv(),
            "iv_atk":
            mongo.random_iv(),
            "iv_defn":
            mongo.random_iv(),
            "iv_satk":
            mongo.random_iv(),
            "iv_sdef":
            mongo.random_iv(),
            "iv_spd":
            mongo.random_iv(),
            "moves":
            moves[:4],
            "shiny":
            shiny,
            "idx":
            await self.db.fetch_next_idx(ctx.author),
        })
        if shiny:
            await self.db.update_member(ctx.author,
                                        {"$inc": {
                                            "shinies_caught": 1
                                        }})

        message = f"Congratulations {ctx.author.mention}! You caught a level {level} {species}!"

        memberp = await self.db.fetch_pokedex(ctx.author, species.dex_number,
                                              species.dex_number + 1)

        if str(species.dex_number) not in memberp.pokedex:
            message += " Added to Pokédex. You received 35 Pokécoins!"

            await self.db.update_member(
                ctx.author,
                {
                    "$set": {
                        f"pokedex.{species.dex_number}": 1
                    },
                    "$inc": {
                        "balance": 35
                    },
                },
            )

        else:
            inc_bal = 0

            if memberp.pokedex[str(species.dex_number)] + 1 == 10:
                message += f" This is your 10th {species}! You received 350 Pokécoins."
                inc_bal = 350

            elif memberp.pokedex[str(species.dex_number)] + 1 == 100:
                message += (
                    f" This is your 100th {species}! You received 3500 Pokécoins."
                )
                inc_bal = 3500

            elif memberp.pokedex[str(species.dex_number)] + 1 == 1000:
                message += (
                    f" This is your 1000th {species}! You received 35000 Pokécoins."
                )
                inc_bal = 35000

            await self.db.update_member(
                ctx.author,
                {
                    "$inc": {
                        "balance": inc_bal,
                        f"pokedex.{species.dex_number}": 1
                    },
                },
            )

        if member.shiny_hunt == species.dex_number:
            if shiny:
                message += f"\n\nShiny streak reset."
                await self.db.update_member(ctx.author,
                                            {"$set": {
                                                "shiny_streak": 0
                                            }})
            else:
                message += f"\n\n+1 Shiny chain! (**{member.shiny_streak + 1}**)"
                await self.db.update_member(ctx.author,
                                            {"$inc": {
                                                "shiny_streak": 1
                                            }})

        if shiny:
            message += "\n\nThese colors seem unusual... ✨"

        await ctx.send(message)
Exemple #6
0
    async def open(self, ctx: commands.Context, type: str = "", amt: int = 1):
        """Open mystery boxes received from voting."""

        do_emojis = (ctx.guild is None or ctx.guild.me.permissions_in(
            ctx.channel).external_emojis)

        if type.lower() not in ("normal", "great", "ultra", "master"):
            if type.lower() in ("n", "g", "u", "m"):
                type = constants.BOXES[type.lower()]
            else:
                return await ctx.send(
                    "Please type `normal`, `great`, `ultra`, or `master`!")

        member = await self.db.fetch_member_info(ctx.author)

        if amt <= 0:
            return await ctx.send("Nice try...")

        if amt > getattr(member, f"gifts_{type.lower()}"):
            return await ctx.send("You don't have enough boxes to do that!")

        if amt > 15:
            return await ctx.send("You can only open 15 boxes at once!")

        await self.db.update_member(ctx.author,
                                    {"$inc": {
                                        f"gifts_{type.lower()}": -amt
                                    }})

        rewards = random.choices(constants.REWARDS,
                                 constants.REWARD_WEIGHTS[type.lower()],
                                 k=amt)

        update = {
            "$inc": {
                "balance": 0,
                "redeems": 0
            },
        }

        added_pokemon = []

        embed = self.bot.Embed(color=0xE67D23)
        if do_emojis:
            embed.title = (
                f" Opening {amt} {getattr(self.bot.sprites, f'gift_{type.lower()}')} {type.title()} Mystery Box"
                + ("" if amt == 1 else "es") + "...")
        else:
            embed.title = (f" Opening {amt} {type.title()} Mystery Box" +
                           ("" if amt == 1 else "es") + "...")

        text = []

        for reward in rewards:
            if reward["type"] == "pp":
                update["$inc"]["balance"] += reward["value"]
                text.append(f"{reward['value']} Pokécoins")
            elif reward["type"] == "redeem":
                update["$inc"]["redeems"] += reward["value"]
                text.append(f"{reward['value']} redeem" +
                            ("" if reward["value"] == 1 else "s"))
            elif reward["type"] == "pokemon":
                species = self.bot.data.random_spawn(rarity=reward["value"])
                level = min(max(int(random.normalvariate(70, 10)), 1), 100)
                shiny = reward["value"] == "shiny" or member.determine_shiny(
                    species)

                lower_bound = 0
                absolute_lower_bound = 0

                if reward["value"] == "iv1":
                    lower_bound = 21

                if reward["value"] == "iv2":
                    lower_bound = 25

                if reward["value"] == "iv3":
                    lower_bound = 25
                    absolute_lower_bound = 10

                ivs = [
                    random.randint(lower_bound, 31),
                    random.randint(lower_bound, 31),
                    random.randint(lower_bound, 31),
                    random.randint(absolute_lower_bound, 31),
                    random.randint(absolute_lower_bound, 31),
                    random.randint(0, 31),
                ]

                random.shuffle(ivs)

                pokemon = {
                    "owner_id": ctx.author.id,
                    "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],
                    "shiny": shiny,
                    "idx": await self.db.fetch_next_idx(ctx.author),
                }

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

                added_pokemon.append(pokemon)

        embed.add_field(name="Rewards Received", value="\n".join(text))

        await self.db.update_member(ctx.author, update)
        if len(added_pokemon) > 0:
            await self.bot.mongo.db.pokemon.insert_many(added_pokemon)
        await ctx.send(embed=embed)
    async def catch(self, ctx: commands.Context, *, guess: str):
        """Catch a wild pokémon."""

        # Retrieve correct species and level from tracker

        if ctx.channel.id not in self.bot.spawns:
            return

        species, level, hint, shiny, users = self.bot.spawns[ctx.channel.id]

        if (models.deaccent(guess.lower().replace("′", "'"))
                not in species.correct_guesses):
            return await ctx.send("That is the wrong pokémon!")

        # Correct guess, add to database

        if ctx.channel.id == 720944005856100452:
            if ctx.author.id in users:
                return await ctx.send("You have already caught this pokémon!")

            users.append(ctx.author.id)
        else:
            del self.bot.spawns[ctx.channel.id]

        member = await self.db.fetch_member_info(ctx.author)

        if shiny is None:
            shiny = random.randint(1, 4096) == 1

        await self.db.update_member(
            ctx.author,
            {
                "$inc": {
                    "shinies_caught": 1 if shiny else 0
                },
                "$push": {
                    "pokemon": {
                        "species_id": species.id,
                        "level": level,
                        "xp": 0,
                        "nature": mongo.random_nature(),
                        "iv_hp": mongo.random_iv(),
                        "iv_atk": mongo.random_iv(),
                        "iv_defn": mongo.random_iv(),
                        "iv_satk": mongo.random_iv(),
                        "iv_sdef": mongo.random_iv(),
                        "iv_spd": mongo.random_iv(),
                        "shiny": shiny,
                    }
                },
            },
        )

        message = f"Congratulations {ctx.author.mention}! You caught a level {level} {species}!"

        memberp = await self.db.fetch_pokedex(ctx.author, species.dex_number,
                                              species.dex_number + 1)

        if str(species.dex_number) not in memberp.pokedex:
            message += " Added to Pokédex. You received 35 Pokécoins!"

            await self.db.update_member(
                ctx.author,
                {
                    "$set": {
                        f"pokedex.{species.dex_number}": 1
                    },
                    "$inc": {
                        "balance": 35
                    },
                },
            )

        else:
            inc_bal = 0

            if memberp.pokedex[str(species.dex_number)] + 1 == 10:
                message += f" This is your 10th {species}! You received 350 Pokécoins."
                inc_bal = 350

            elif memberp.pokedex[str(species.dex_number)] + 1 == 100:
                message += (
                    f" This is your 100th {species}! You received 3500 Pokécoins."
                )
                inc_bal = 3500

            elif memberp.pokedex[str(species.dex_number)] + 1 == 1000:
                message += (
                    f" This is your 1000th {species}! You received 35000 Pokécoins."
                )
                inc_bal = 35000

            await self.db.update_member(
                ctx.author,
                {
                    "$inc": {
                        "balance": inc_bal,
                        f"pokedex.{species.dex_number}": 1
                    },
                },
            )

        if shiny:
            message += "\n\nThese colors seem unusual... ✨"

        await ctx.send(message)
Exemple #8
0
    async def redeem(self, ctx: commands.Context, *, species: str = None):
        """Use a redeem to receive a pokémon of your choice."""

        member = await self.db.fetch_member_info(ctx.author)

        if species is None:
            embed = self.bot.Embed()
            embed.title = f"Your Redeems: {member.redeems}"
            embed.description = "You can use redeems to receive any pokémon of your choice. You can receive redeems by supporting the bot on Patreon or through voting rewards."

            embed.add_field(
                name=f"{ctx.prefix}redeem <pokémon>",
                value="Use a redeem to receive a pokémon of your choice.",
            )

            embed.add_field(
                name=f"{ctx.prefix}redeemspawn <pokémon>",
                value=
                "Use a redeem to spawn a pokémon of your choice in the current channel (careful, if something else spawns, it'll be overrided).",
            )

            return await ctx.send(embed=embed)

        if member.redeems == 0:
            return await ctx.send("You don't have any redeems!")

        species = self.bot.data.species_by_name(species)
        if species is None:
            return await ctx.send(
                f"Could not find a pokemon matching `{species}`.")

        if not species.catchable or "Alolan" in species.name:
            return await ctx.send("You can't redeem this pokémon!")

        await self.db.update_member(
            ctx.author,
            {
                "$inc": {
                    "redeems": -1
                },
                "$push": {
                    "pokemon": {
                        "species_id": species.id,
                        "level": 1,
                        "xp": 0,
                        "nature": mongo.random_nature(),
                        "iv_hp": mongo.random_iv(),
                        "iv_atk": mongo.random_iv(),
                        "iv_defn": mongo.random_iv(),
                        "iv_satk": mongo.random_iv(),
                        "iv_sdef": mongo.random_iv(),
                        "iv_spd": mongo.random_iv(),
                        "shiny": member.determine_shiny(species),
                    }
                },
            },
        )

        await ctx.send(
            f"You used a redeem and received a {species}! View it with `{ctx.prefix}info latest`."
        )
Exemple #9
0
    async def open(self, ctx: commands.Context, type: str = "", amt: int = 1):
        """Open mystery boxes received from voting."""

        if type.lower() not in ("normal", "great", "ultra"):
            return await ctx.send("Please type `normal`, `great`, or `ultra`!")

        member = await self.db.fetch_member_info(ctx.author)

        if amt <= 0:
            return await ctx.send("Nice try...")

        if amt > getattr(member, f"gifts_{type.lower()}"):
            return await ctx.send("You don't have enough boxes to do that!")

        if amt > 15:
            return await ctx.send("You can only open 15 boxes at once!")

        await self.db.update_member(ctx.author,
                                    {"$inc": {
                                        f"gifts_{type.lower()}": -amt
                                    }})

        rewards = random.choices(constants.REWARDS,
                                 constants.REWARD_WEIGHTS[type.lower()],
                                 k=amt)

        update = {
            "$inc": {
                "balance": 0,
                "redeems": 0
            },
            "$push": {
                "pokemon": {
                    "$each": []
                }
            },
        }

        embed = discord.Embed()
        embed.color = 0xF44336
        embed.title = (
            f" Opening {amt} {getattr(constants.EMOJIS, f'gift_{type.lower()}')} {type.title()} Mystery Box"
            + ("" if amt == 1 else "es") + "...")

        text = []

        for reward in rewards:
            if reward["type"] == "pp":
                update["$inc"]["balance"] += reward["value"]
                text.append(f"{reward['value']} Pokécoins")
            elif reward["type"] == "redeem":
                update["$inc"]["redeems"] += reward["value"]
                text.append(f"{reward['value']} redeem" +
                            ("" if reward["value"] == 1 else "s"))
            elif reward["type"] == "pokemon":
                species = models.GameData.random_spawn(rarity=reward["value"])
                level = min(max(int(random.normalvariate(70, 10)), 1), 100)
                shiny = reward["value"] == "shiny" or member.determine_shiny(
                    species)

                lower_bound = 0

                if reward["value"] == "iv1":
                    lower_bound = 21

                if reward["value"] == "iv2":
                    lower_bound = 25

                ivs = [
                    random.randint(lower_bound, 31),
                    random.randint(lower_bound, 31),
                    random.randint(lower_bound, 31),
                    random.randint(0, 31),
                    random.randint(0, 31),
                    random.randint(0, 31),
                ]

                random.shuffle(ivs)

                pokemon = {
                    "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],
                    "shiny": shiny,
                }

                text.append(
                    f"{constants.EMOJIS.get(species.dex_number, shiny=shiny)} Level {level} {species} ({sum(ivs) / 186:.2%} IV)"
                    + (" ✨" if shiny else ""))

                update["$push"]["pokemon"]["$each"].append(pokemon)

        embed.add_field(name="Rewards Received", value="\n".join(text))

        await self.db.update_member(ctx.author, update)
        await ctx.send(embed=embed)