mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Add xkcd command
This commit is contained in:
parent
3c5221f32e
commit
bf272f17c4
5 changed files with 69 additions and 2 deletions
28
data/embeds/xkcd.py
Normal file
28
data/embeds/xkcd.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import discord
|
||||
from requests import get
|
||||
from functions.stringFormatters import leading_zero
|
||||
|
||||
|
||||
class XKCDEmbed:
|
||||
n: int
|
||||
|
||||
def __init__(self, n: int = None):
|
||||
self.n = n
|
||||
|
||||
def create(self) -> discord.Embed:
|
||||
endpoint = "https://xkcd.com/info.0.json" if self.n is None else f"https://xkcd.com/{self.n}/info.0.json"
|
||||
response = get(endpoint)
|
||||
|
||||
if response.status_code != 200:
|
||||
embed = discord.Embed(colour=discord.Colour.red())
|
||||
embed.set_author(name="xkcd")
|
||||
embed.description = f"Er ging iets mis (status {response.status_code})."
|
||||
return embed
|
||||
|
||||
data = response.json()
|
||||
|
||||
embed = discord.Embed(colour=discord.Colour.from_rgb(150, 168, 200), title=data["safe_title"])
|
||||
embed.set_author(name=f"xkcd #{data['num']}")
|
||||
embed.set_image(url=data["img"])
|
||||
embed.set_footer(text=f"{leading_zero(data['day'])}/{leading_zero(data['month'])}/{data['year']}")
|
||||
return embed
|
||||
Loading…
Add table
Add a link
Reference in a new issue