xkcd
This commit is contained in:
parent
cd02852691
commit
cb86ea391c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
secret.txt
|
secret.txt
|
||||||
|
data
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
import requests
|
import requests
|
||||||
|
from models.xkcdComic import Comic
|
||||||
|
import json
|
||||||
|
|
||||||
class ProgrammerExcuses:
|
class ProgrammerExcuses:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@ -16,9 +18,11 @@ class ProgrammerExcuses:
|
|||||||
class XKCD:
|
class XKCD:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.__url = "https://xkcd.com"
|
self.__url = "https://xkcd.com"
|
||||||
|
self.__api = "info.0.json"
|
||||||
|
|
||||||
def getRandomComic(self):
|
def getRandomComic(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def getLastComic(self):
|
def getLastComic(self):
|
||||||
pass
|
response = requests.api.get(f"{self.__url}/{self.__api}")
|
||||||
|
return Comic(json.loads(response.text))
|
||||||
10
src/main.py
10
src/main.py
@ -2,11 +2,12 @@ import time as t
|
|||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import datetime
|
import datetime
|
||||||
from unicodedata import category
|
|
||||||
import secretHandler
|
import secretHandler
|
||||||
from addons import ProgrammerExcuses
|
from addons import ProgrammerExcuses
|
||||||
from addons import XKCD
|
from addons import XKCD
|
||||||
|
|
||||||
|
from models.xkcdComic import Comic
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord import Status
|
from discord import Status
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
@ -86,9 +87,12 @@ async def on_guild_join(guild: Guild):
|
|||||||
async def slash(interaction: Interaction):
|
async def slash(interaction: Interaction):
|
||||||
await interaction.response.send_message(programmerExcuses.getExcuse())
|
await interaction.response.send_message(programmerExcuses.getExcuse())
|
||||||
|
|
||||||
|
@tree.command(name='get-latest-comic', description='Get latest comic from XKCD')
|
||||||
|
async def slash(interaction: Interaction):
|
||||||
|
comic = xkcd.getLastComic()
|
||||||
|
|
||||||
|
embed = discord.Embed(title=comic.title, description=comic.alt, color=Color.blue(), url=comic.img)
|
||||||
|
await interaction.response.send_message(embed=embed)
|
||||||
|
|
||||||
@tree.command(name="info", description="get info about this server")
|
@tree.command(name="info", description="get info about this server")
|
||||||
async def slash(interaction: Interaction):
|
async def slash(interaction: Interaction):
|
||||||
|
|||||||
13
src/models/response.json
Normal file
13
src/models/response.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"month": "2",
|
||||||
|
"num": 2732,
|
||||||
|
"link": "",
|
||||||
|
"year": "2023",
|
||||||
|
"news": "",
|
||||||
|
"safe_title": "Bursa of Fabricius",
|
||||||
|
"transcript": "",
|
||||||
|
"alt": "If an anatomical structure is named for a person, it means they were the only person to have it. Pierre Paul Broca had a special area of his brain that created powerful magnetic fields, enabling him to do 19th century fMRI research.",
|
||||||
|
"img": "https://imgs.xkcd.com/comics/bursa_of_fabricius.png",
|
||||||
|
"title": "Bursa of Fabricius",
|
||||||
|
"day": "1"
|
||||||
|
}
|
||||||
13
src/models/xkcdComic.py
Normal file
13
src/models/xkcdComic.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class Comic:
|
||||||
|
def __init__(self, data) -> None:
|
||||||
|
self.day = data['day']
|
||||||
|
self.month = data['month']
|
||||||
|
self.year = data['year']
|
||||||
|
self.num = data['num']
|
||||||
|
self.link = data['link']
|
||||||
|
self.news = data['news']
|
||||||
|
self.safe_title = data['safe_title']
|
||||||
|
self.transcript = data['transcript']
|
||||||
|
self.alt = data['alt']
|
||||||
|
self.img = data['img']
|
||||||
|
self.title = data['title']
|
||||||
Loading…
x
Reference in New Issue
Block a user