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
27 changes: 23 additions & 4 deletions bot/exts/fun/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Literal

import aiohttp
import pyjokes
from discord import Embed
from discord.ext import commands
Expand Down Expand Up @@ -153,10 +154,28 @@ 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 aiohttp.ClientSession() as session, session.get(
"https://icanhazdadjoke.com",
headers={
"Accept":"application/json",
"User-Agent": "Sir-lancebot"
}) as res:
if res.status == 200:
data = await res.json()
await ctx.send(data["joke"])
else:
await ctx.send("There is no dad joke now")
else:
joke = pyjokes.get_joke(category=category)
await ctx.send(joke)


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