Ejemplo n.º 1
0
    async def userfriendly(
        self,
        ctx,
        *,
        date: DateNewerThan(
            datetime.date(year=1997, month=11, day=17)
        ) = datetime.date.today(),
    ):
        _(
            """`[date]` - The date on which the comic strip was released, see below for more info

            Sends today's userfriendly comic if no date info is given.
            Otherwise, the format is `YYYY MM DD` or `DD MM YYYY`, depending on where the year is, with the date parts being seperated with spaces.
            For example: `2013 12 25` is the same as `25 12 2013`, both meaning December 25th 2013."""
        )
        async with self.bot.session.get(
            f"http://ars.userfriendly.org/cartoons/?id={date.strftime('%Y%m%d')}&mode=classic"
        ) as r:
            stuff = await r.text()

        await ctx.send(
            embed=discord.Embed(
                color=self.bot.config.primary_colour,
                url="http://userfriendly.org",
                title=_("Taken from userfriendly.org"),
                description=str(date),
            ).set_image(
                url=re.compile('<img border="0" src="([^"]+)"').search(stuff).group(1)
            )
        )
Ejemplo n.º 2
0
    async def userfriendly(
        self,
        ctx,
        *,
        date: DateNewerThan(
            datetime.date(year=1997, month=11, day=17)
        ) = datetime.date.today(),
    ):
        _(
            """Sends today's userfriendly comic if no date info is passed. Else, it will use YYYY MM DD or DD MM YYYY depending on where the year is, with the date parts being seperated with spaces."""
        )
        async with self.bot.session.get(
            f"http://ars.userfriendly.org/cartoons/?id={date.strftime('%Y%m%d')}&mode=classic"
        ) as r:
            stuff = await r.text()

        await ctx.send(
            embed=discord.Embed(
                color=self.bot.config.primary_colour,
                url="http://userfriendly.org",
                title=_("Taken from userfriendly.org"),
                description=str(date),
            ).set_image(
                url=re.compile('<img border="0" src="([^"]+)"').search(stuff).group(1)
            )
        )
Ejemplo n.º 3
0
 async def garfield(
     self,
     ctx,
     *,
     date: DateNewerThan(datetime.date(year=1978, month=6,
                                       day=19)) = datetime.date.today(),
 ):
     _("""Sends today's garfield comic if no date info is passed. Else, it will use YYYY MM DD or DD MM YYYY depending on where the year is, with the date parts being seperated with spaces."""
       )
     await ctx.send(embed=discord.Embed(
         color=self.bot.config.primary_colour
     ).set_image(
         url=
         f"https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/{date.year}/{date.strftime('%Y-%m-%d')}.gif?format=png"
     ))
Ejemplo n.º 4
0
    async def garfield(
        self,
        ctx,
        *,
        date: DateNewerThan(datetime.date(year=1978, month=6,
                                          day=19)) = datetime.date.today(),
    ):
        _("""`[date]` - The date on which the comic strip was released, see below for more info

            Sends today's garfield comic if no date info is given.
            Otherwise, the format is `YYYY MM DD` or `DD MM YYYY`, depending on where the year is, with the date parts being seperated with spaces.
            For example: `2013 12 25` is the same as `25 12 2013`, both meaning December 25th 2013."""
          )
        await ctx.send(embed=discord.Embed(
            color=self.bot.config.primary_colour
        ).set_image(
            url=
            f"https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/{date.year}/{date.strftime('%Y-%m-%d')}.gif?format=png"
        ))
Ejemplo n.º 5
0
    async def shophistory(
        self,
        ctx,
        itemtype: str.title = "All",
        minstat: float = 0.00,
        after_date: DateNewerThan(
            datetime.date(year=2018, month=3, day=17)
        ) = datetime.date(year=2018, month=3, day=17),
    ):
        _(
            """`[itemtype]` - The type of item to filter; defaults to all item types
             `[minstat]` - The minimum damage/defense an item has to have to show up; defaults to 0
             `[after_date]` - Show sales only after this date, defaults to bot creation date, which means all

            Lists the past successful sales on the market by criteria and shows average, minimum and highest prices by category."""
        )
        if itemtype != "All" and ItemType.from_string(itemtype) is None:
            return await ctx.send(
                _("Use either {types} or `All` as a type to filter for.").format(
                    types=", ".join(f"`{t.value}`" for t in ALL_ITEM_TYPES)
                )
            )
        if itemtype == "All":
            sales = await self.bot.pool.fetch(
                "SELECT * FROM market_history WHERE"
                ' ("damage">=$1 OR "armor">=$1) AND "timestamp">=$2;',
                minstat,
                after_date,
            )
        elif itemtype == "Shield":
            sales = await self.bot.pool.fetch(
                "SELECT * FROM market_history WHERE"
                ' "armor">=$1 AND "timestamp">=$2 AND "type"=$3;',
                minstat,
                after_date,
                "Shield",
            )
        else:
            sales = await self.bot.pool.fetch(
                "SELECT * FROM market_history WHERE"
                ' "damage">=$1 AND "timestamp">=$2 AND "type"=$3;',
                minstat,
                after_date,
                itemtype,
            )
        if not sales:
            return await ctx.send(_("No results."))

        prices = [i["price"] for i in sales]
        max_price = max(prices)
        min_price = min(prices)
        avg_price = round(sum(prices) / len(prices), 2)

        items = [
            discord.Embed(
                title=_("IdleRPG Shop History"),
                colour=discord.Colour.blurple(),
            )
            .add_field(name=_("Name"), value=item["name"])
            .add_field(name=_("Type"), value=item["type"])
            .add_field(name=_("Damage"), value=item["damage"])
            .add_field(name=_("Armor"), value=item["armor"])
            .add_field(name=_("Value"), value=f"${item['value']}")
            .add_field(
                name=_("Price"),
                value=f"${item['price']}",
            )
            .set_footer(
                text=_("Item {num} of {total}").format(num=idx + 1, total=len(sales))
            )
            for idx, item in enumerate(sales)
        ]
        items.insert(
            0,
            discord.Embed(
                title=_("Search results"),
                color=discord.Colour.blurple(),
                description=_(
                    "The search found {amount} sales starting at ${min_price}, ending"
                    " at ${max_price}. The average sale price was"
                    " ${avg_price}.\n\nNavigate to see the sales."
                ).format(
                    amount=len(prices),
                    min_price=min_price,
                    max_price=max_price,
                    avg_price=avg_price,
                ),
            ),
        )

        await self.bot.paginator.Paginator(extras=items).paginate(ctx)