Esempio n. 1
0
    async def moveitem(
        self,
        ctx: commands.Context,
        from_pokemon: converters.Pokemon,
        to_pokemon: converters.Pokemon = None,
    ):
        """Move a pokémon's held item."""

        if to_pokemon is None:
            to_pokemon = from_pokemon
            converter = converters.Pokemon()
            from_pokemon = await converter.convert(ctx, "")

        from_pokemon, from_idx = from_pokemon
        to_pokemon, to_idx = to_pokemon

        if from_pokemon is None or to_pokemon is None:
            return await ctx.send("Couldn't find that pokémon!")

        if from_pokemon.held_item is None:
            return await ctx.send("That pokémon isn't holding an item!")

        if to_pokemon.held_item is not None:
            return await ctx.send("That pokémon is already holding an item!")

        num = await self.db.fetch_pokemon_count(ctx.author)
        from_idx = from_idx % num
        to_idx = to_idx % num

        await self.db.update_member(
            ctx.author,
            {
                "$set": {
                    f"pokemon.{from_idx}.held_item": None,
                    f"pokemon.{to_idx}.held_item": from_pokemon.held_item,
                }
            },
        )

        from_name = str(from_pokemon.species)

        if from_pokemon.nickname is not None:
            from_name += f' "{from_pokemon.nickname}"'

        to_name = str(to_pokemon.species)

        if to_pokemon.nickname is not None:
            to_name += f' "{to_pokemon.nickname}"'

        await ctx.send(
            f"Moved held item from your level {from_pokemon.level} {from_name} to your level {to_pokemon.level} {to_name}."
        )
Esempio n. 2
0
    async def moveset(self, ctx: commands.Context, *, search: str):
        """View all moves for your pokémon and how to get them."""

        search = search.strip()

        if len(search) > 0 and search[0] in "Nn#" and search[1:].isdigit():
            species = self.bot.data.species_by_number(int(search[1:]))
        else:
            species = self.bot.data.species_by_name(search)

            if species is None:
                converter = converters.Pokemon(raise_errors=False)
                pokemon = await converter.convert(ctx, search)
                if pokemon is not None:
                    species = pokemon.species

        if species is None:
            raise converters.PokemonConversionError(
                f"Please either enter the name of a pokémon species, nothing for your selected pokémon, a number for "
                f"a specific pokémon, `latest` for your latest pokémon. ",
                original=ValueError(),
            )

        async def get_page(pidx, clear):
            pgstart = (pidx) * 20
            pgend = min(pgstart + 20, len(species.moves))

            # Send embed

            embed = discord.Embed(color=0xE67D23)
            embed.title = f"{species} — Moveset"

            embed.set_footer(
                text=
                f"Showing {pgstart + 1}–{pgend} out of {len(species.moves)}.")

            for move in species.moves[pgstart:pgend]:
                embed.add_field(name=move.move.name, value=move.text)

            for i in range(-pgend % 3):
                embed.add_field(name="‎", value="‎")

            return embed

        paginator = pagination.Paginator(get_page,
                                         num_pages=math.ceil(
                                             len(species.moves) / 20))
        await paginator.send(self.bot, ctx, 0)
Esempio n. 3
0
    async def select(
        self, ctx: commands.Context, *, pokemon: converters.Pokemon(accept_blank=False)
    ):
        """Select a specific pokémon from your collection."""

        if pokemon is None:
            return await ctx.send("Couldn't find that pokémon!")

        num = await self.db.fetch_pokemon_count(ctx.author)

        await self.db.update_member(
            ctx.author,
            {"$set": {f"selected_id": pokemon.id}},
        )

        await ctx.send(
            f"You selected your level {pokemon.level} {pokemon.species}. No. {pokemon.idx}."
        )
Esempio n. 4
0
    async def release(self, ctx: commands.Context,
                      args: commands.Greedy[converters.Pokemon]):
        """Release pokémon from your collection."""

        if ctx.author.id in self.bot.trades:
            return await ctx.send("You can't do that in a trade!")

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

        converter = converters.Pokemon(accept_blank=False)

        ids = set()
        mons = list()

        for pokemon in args:

            if pokemon is None:
                continue

            # can't release selected/fav

            if pokemon.id in ids:
                continue

            if member.selected_id == pokemon.id:
                await ctx.send(
                    f"{pokemon.idx}: You can't release your selected pokémon!")
                continue

            if pokemon.favorite:
                await ctx.send(
                    f"{pokemon.idx}: You can't release favorited pokémon!")
                continue

            ids.add(pokemon.id)
            mons.append(pokemon)

        # Confirmation msg

        if len(mons) == 0:
            return

        if len(args) == 1:
            await ctx.send(
                f"Are you sure you want to release your level {pokemon.level} {pokemon.species}. No. {pokemon.idx}? This action is irreversible! [y/N]"
            )
        else:
            embed = self.bot.Embed()
            embed.title = (
                f"Are you sure you want to release the following pokémon? [y/N]"
            )

            embed.description = "\n".join(
                f"Level {x.level} {x.species} ({x.idx})" for x in mons)

            await ctx.send(embed=embed)

        def check(m):
            return m.channel.id == ctx.channel.id and m.author.id == ctx.author.id

        try:
            msg = await self.bot.wait_for("message", timeout=30, check=check)

            if msg.content.lower() != "y":
                return await ctx.send("Aborted.")
        except asyncio.TimeoutError:
            return await ctx.send("Time's up. Aborted.")

        # confirmed, release

        await self.bot.mongo.db.pokemon.delete_many(
            {"_id": {
                "$in": list(ids)
            }})
        await ctx.send(f"You released {len(mons)} pokémon.")
Esempio n. 5
0
    async def release(self, ctx: commands.Context,
                      args: commands.Greedy[converters.Pokemon]):
        """Release pokémon from your collection."""

        if ctx.author.id in self.bot.trades:
            return await ctx.send("You can't do that in a trade!")

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

        converter = converters.Pokemon(accept_blank=False)

        dec = 0

        idxs = set()
        mons = list()

        for pokemon, idx in args:

            if pokemon is None:
                await ctx.send(f"{idx + 1}: Couldn't find that pokémon!")
                continue

            # can't release selected/fav

            if idx in idxs:
                continue

            if member.selected == idx:
                await ctx.send(
                    f"{idx + 1}: You can't release your selected pokémon!")
                continue

            if pokemon.favorite:
                await ctx.send(
                    f"{idx + 1}: You can't release favorited pokémon!")
                continue

            idxs.add(idx)
            mons.append((pokemon, idx))

            if (idx % num) < member.selected:
                dec += 1

        # Confirmation msg

        if len(mons) == 0:
            return

        if len(args) == 1:
            await ctx.send(
                f"Are you sure you want to release your level {pokemon.level} {pokemon.species}. No. {idx + 1}? This action is irreversible! [y/N]"
            )
        else:
            embed = self.bot.Embed()
            embed.title = (
                f"Are you sure you want to release the following pokémon? [y/N]"
            )

            embed.description = "\n".join(
                f"Level {x[0].level} {x[0].species} ({x[1] + 1})"
                for x in mons)

            await ctx.send(embed=embed)

        def check(m):
            return m.channel.id == ctx.channel.id and m.author.id == ctx.author.id

        try:
            msg = await self.bot.wait_for("message", timeout=30, check=check)

            if msg.content.lower() != "y":
                return await ctx.send("Aborted.")
        except asyncio.TimeoutError:
            return await ctx.send("Time's up. Aborted.")

        # confirmed, release

        unsets = {f"pokemon.{idx}": 1 for idx in idxs}

        # mongo is bad so we have to do two steps here

        await self.db.update_member(ctx.author, {"$unset": unsets})
        await self.db.update_member(
            ctx.author,
            {"$pull": {
                f"pokemon": {
                    "species_id": {
                        "$exists": False
                    }
                }
            }},
        )
        await self.db.update_member(ctx.author, {
            "$pull": {
                "pokemon": None
            },
            "$inc": {
                f"selected": -dec
            }
        })

        await ctx.send(f"You released {len(mons)} pokémon.")