Add xkcd command

This commit is contained in:
Stijn De Clercq 2022-01-16 19:55:07 +01:00
parent 3c5221f32e
commit bf272f17c4
5 changed files with 69 additions and 2 deletions

View file

@ -1,3 +1,4 @@
from data.embeds.xkcd import XKCDEmbed
from data.menus import paginatedLeaderboard
from decorators import help
import discord
@ -137,6 +138,14 @@ class Fun(commands.Cog):
r = requests.get("https://official-joke-api.appspot.com/jokes/programming/random").json()
await ctx.send(r[0]["setup"] + "\n" + r[0]["punchline"])
@commands.command(name="xkcd")
@help.Category(category=Category.Fun)
async def xkcd(self, ctx, n: int = None):
"""
Send an xkcd comic
"""
return await ctx.reply(embed=XKCDEmbed(n).create())
def setup(client):
client.add_cog(Fun(client))

View file

@ -8,7 +8,7 @@ from functions.timeFormatters import fromString
from startup.didier import Didier
class Slash(commands.Cog):
class DBSlash(commands.Cog):
def __init__(self, client: Didier):
self.client: Didier = client
@ -84,4 +84,4 @@ class Slash(commands.Cog):
def setup(client: Didier):
client.add_cog(Slash(client))
client.add_cog(DBSlash(client))

29
cogs/slash/fun_slash.py Normal file
View file

@ -0,0 +1,29 @@
from discord.ext import commands
from dislash import SlashInteraction, slash_command, Option, OptionType
from data.embeds.xkcd import XKCDEmbed
from startup.didier import Didier
class FunSlash(commands.Cog):
def __init__(self, client: Didier):
self.client: Didier = client
@slash_command(
name="xkcd",
description="Zoek xkcd comics",
options=[
Option(
"num",
description="Nummer van de comic (default de comic van vandaag).",
type=OptionType.INTEGER,
required=False
)
]
)
async def _xkcd_slash(self, interaction: SlashInteraction, num: int = None):
return await interaction.reply(embed=XKCDEmbed(num).create())
def setup(client: Didier):
client.add_cog(FunSlash(client))