コード例 #1
0
ファイル: pokemon.py プロジェクト: brenohq/poketwo
    async def evolve(self, ctx: commands.Context, *,
                     pokemon: converters.Pokemon):
        """Evolve a pokémon if it has reached the target level."""

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

        if (evo := pokemon.get_next_evolution(guild.is_day)) is None:
            return await ctx.send("That pokémon can't be evolved!")
コード例 #2
0
ファイル: market.py プロジェクト: brenohq/poketwo
    async def add(self, ctx: commands.Context, pokemon: converters.Pokemon,
                  price: int):
        """List a pokémon on the marketplace."""

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

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

        if price < 1:
            return await ctx.send("The price must be positive!")

        if price > 1000000000:
            return await ctx.send("Price is too high!")

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

        # confirm

        await ctx.send(
            f"Are you sure you want to list your **{pokemon.iv_percentage:.2%} {pokemon.species} "
            f"No. {pokemon.idx}** for **{price:,}** Pokécoins? [y/N]")

        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)
        except asyncio.TimeoutError:
            return await ctx.send("Time's up. Aborted.")

        if msg.content.lower() != "y":
            return await ctx.send("Aborted.")

        # create listing

        counter = await self.bot.mongo.db.counter.find_one_and_update(
            {"_id": "listing"}, {"$inc": {
                "next": 1
            }}, upsert=True)
        if counter is None:
            counter = {"next": 0}

        await self.bot.mongo.db.listing.insert_one({
            "_id":
            counter["next"],
            "pokemon":
            pokemon.to_mongo(),
            "user_id":
            ctx.author.id,
            "price":
            price,
        })

        await self.bot.mongo.db.pokemon.delete_one({"_id": pokemon.id})

        await ctx.send(
            f"Listed your **{pokemon.iv_percentage:.2%} {pokemon.species} "
            f"No. {pokemon.idx}** on the market for **{price:,}** Pokécoins.")