2019-10-08 17:37:09 -07:00
|
|
|
from redbot.core import commands
|
|
|
|
|
import aiohttp
|
|
|
|
|
|
2020-08-26 17:57:43 +01:00
|
|
|
|
2019-10-08 17:37:09 -07:00
|
|
|
class DadJokes(commands.Cog):
|
|
|
|
|
"""Random dad jokes from icanhazdadjoke.com"""
|
|
|
|
|
|
2020-08-26 17:57:43 +01:00
|
|
|
async def red_delete_data_for_user(self, **kwargs):
|
|
|
|
|
""" Nothing to delete """
|
|
|
|
|
return
|
|
|
|
|
|
2019-10-08 17:37:09 -07:00
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
|
|
@commands.command()
|
|
|
|
|
async def dadjoke(self, ctx):
|
|
|
|
|
"""Gets a random dad joke."""
|
2021-10-24 19:02:55 +02:00
|
|
|
try:
|
|
|
|
|
async with aiohttp.request("GET", "https://icanhazdadjoke.com/", headers={"Accept": "text/plain"}) as r:
|
|
|
|
|
if r.status != 200:
|
|
|
|
|
return await ctx.send("Oops! Cannot get a dad joke...")
|
|
|
|
|
result = await r.text(encoding="UTF-8")
|
|
|
|
|
except aiohttp.ClientConnectionError:
|
|
|
|
|
return await ctx.send("Oops! Cannot get a dad joke...")
|
|
|
|
|
|
|
|
|
|
await ctx.send(f"`{result}`")
|