Beispiel #1
0
    async def search(self, ctx, **flags):
        """Search pokémon from auctions."""

        if flags["page"] < 1:
            return await ctx.send("Page must be positive!")

        aggregations = await self.bot.get_cog("Pokemon").create_filter(
            flags, ctx, order_by=flags["order"]
        )

        if aggregations is None:
            return

        # Filter pokemon

        now = datetime.utcnow()

        def padn(p, n):
            return " " * (len(str(n)) - len(str(p.id))) + str(p.id)

        def prepare_page(menu, items):
            menu.maxn = max(x.id for x in items)

        def format_item(menu, x):
            if x.bidder_id is not None:
                return (
                    f"`{padn(x, menu.maxn)}` **{x.pokemon:Li}** • "
                    f"{x.pokemon.iv_total / 186:.2%} • CB: {x.current_bid:,} • "
                    f"BI: {x.bid_increment:,} pc • {converters.strfdelta(x.ends - now, max_len=1)}"
                )
            else:
                return (
                    f"`{padn(x, menu.maxn)}` **{x.pokemon:Li}** • "
                    f"{x.pokemon.iv_total / 186:.2%} • SB: {x.current_bid + x.bid_increment:,} pc • "
                    f"{converters.strfdelta(x.ends - now, max_len=1)}"
                )

        count = await self.bot.mongo.fetch_auction_count(ctx.guild, aggregations)
        pokemon = self.bot.mongo.fetch_auction_list(ctx.guild, aggregations)

        pages = pagination.ContinuablePages(
            pagination.AsyncListPageSource(
                pokemon,
                title=f"Auctions in {ctx.guild.name}",
                prepare_page=prepare_page,
                format_item=format_item,
                per_page=15,
                count=count,
            )
        )
        pages.current_page = flags["page"] - 1
        self.bot.menus[ctx.author.id] = pages

        try:
            await pages.start(ctx)
        except IndexError:
            await ctx.send("No auctions found.")
Beispiel #2
0
    async def pokemon(self, ctx, **flags):
        """View or filter the pokémon in your collection."""

        if flags["page"] < 1:
            return await ctx.send("Page must be positive!")

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

        aggregations = await self.create_filter(flags,
                                                ctx,
                                                order_by=member.order_by)
        if aggregations is None:
            return

        # Filter pokemon

        def padn(p, n):
            return " " * (len(str(n)) - len(str(p.idx))) + str(p.idx)

        def prepare_page(menu, items):
            menu.maxn = max(x.idx for x in items)

        def format_item(menu, p):
            return f"`{padn(p, menu.maxn)}` **{p:nif}** • Lvl. {p.level} • {p.iv_total / 186:.2%}"

        count = await self.bot.mongo.fetch_pokemon_count(
            ctx.author, aggregations)
        pokemon = self.bot.mongo.fetch_pokemon_list(ctx.author, aggregations)

        pages = pagination.ContinuablePages(
            pagination.AsyncListPageSource(
                pokemon,
                title="Your pokémon",
                prepare_page=prepare_page,
                format_item=format_item,
                per_page=20,
                count=count,
            ))
        pages.current_page = flags["page"] - 1
        self.bot.menus[ctx.author.id] = pages

        try:
            await pages.start(ctx)
        except IndexError:
            await ctx.send("No pokémon found.")
Beispiel #3
0
    async def search(self, ctx, **flags):
        """Search pokémon from the marketplace."""
        def map_field(field):
            if field == "_id":
                return f"market_data._id"
            return field

        aggregations = await self.bot.get_cog("Pokemon").create_filter(
            flags, ctx, order_by=flags["order"], map_field=map_field)

        if aggregations is None:
            return

        # Filter pokemon

        def padn(p, n):
            return " " * (len(str(n)) - len(str(p))) + str(p)

        def prepare_page(menu, items):
            menu.maxn = max(x["market_data"]["_id"] for x in items)

        def format_item(menu, x):
            pokemon = self.bot.mongo.Pokemon.build_from_mongo(x)
            return f"`{padn(x['market_data']['_id'], menu.maxn)}` **{pokemon:li}** • {pokemon.iv_total / 186:.2%} • {x['market_data']['price']:,} pc"

        pokemon = self.bot.mongo.fetch_market_list(aggregations)

        pages = pagination.ContinuablePages(
            pagination.AsyncListPageSource(
                pokemon,
                title=f"Pokétwo Marketplace",
                prepare_page=prepare_page,
                format_item=format_item,
                per_page=20,
            ),
            allow_last=False,
            allow_go=False,
        )
        self.bot.menus[ctx.author.id] = pages

        try:
            await pages.start(ctx)
        except IndexError:
            await ctx.send("No listings found.")
Beispiel #4
0
    async def search(self, ctx, **flags):
        """Search pokémon from the marketplace."""

        if flags["page"] < 1:
            return await ctx.send("Page must be positive!")

        aggregations = await self.bot.get_cog("Pokemon").create_filter(
            flags, ctx, order_by=flags["order"])

        if aggregations is None:
            return

        # Filter pokemon

        def padn(p, n):
            return " " * (len(str(n)) - len(str(p.id))) + str(p.id)

        def prepare_page(menu, items):
            menu.maxn = max(x.id for x in items)

        def format_item(menu, x):
            return f"`{padn(x, menu.maxn)}` **{x.pokemon:li}** • {x.pokemon.iv_total / 186:.2%} • {x.price:,} pc"

        pokemon = self.bot.mongo.fetch_market_list(aggregations)

        pages = pagination.ContinuablePages(
            pagination.AsyncListPageSource(
                pokemon,
                title=f"Pokétwo Marketplace",
                prepare_page=prepare_page,
                format_item=format_item,
                per_page=20,
            ),
            allow_last=False,
            allow_go=False,
        )
        pages.current_page = flags["page"] - 1
        self.bot.menus[ctx.author.id] = pages

        try:
            await pages.start(ctx)
        except IndexError:
            await ctx.send("No listings found.")