-
-
Couldn't load subscription status.
- Fork 254
Dadjoke #1693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Dadjoke #1693
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.