Skip to content
Open

Dadjoke #1693

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions bot/exts/fun/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,26 @@ async def caesarcipher_decrypt(self, ctx: Context, offset: int, *, msg: str) ->
await self._caesar_cipher(ctx, offset, msg, left_shift=True)

@commands.command()
async def joke(self, ctx: commands.Context, category: Literal["neutral", "chuck", "all"] = "all") -> None:
"""Retrieves a joke of the specified `category` from the pyjokes api."""
joke = pyjokes.get_joke(category=category)
await ctx.send(joke)
async def joke(self, ctx: commands.Context, category: Literal["dad", "neutral", "chuck", "all"] = "all") -> None:
"""
Retrieves a joke of the specified `category` from the pyjokes api.

- dad uses icanhazdadjoke.
- others use pyjokes.
"""
if category == "dad":
async with self.bot.http_session.get(
"https://icanhazdadjoke.com",
headers={
"Accept":"application/json",
"User-Agent": "Sir-lancebot (https://github.com/python-discord/sir-lancebot)"
}) as res:
res.raise_for_status()
data = await res.json()
await ctx.send(data["joke"])
else:
joke = pyjokes.get_joke(category=category)
await ctx.send(joke)


async def setup(bot: Bot) -> None:
Expand Down