finished xkcd
This commit is contained in:
parent
a632d1b76c
commit
67b39a42a9
@ -22,16 +22,24 @@ class XKCD:
|
||||
|
||||
def getRandomComic(self):
|
||||
response = requests.get(url=f"https://c.xkcd.com/random/comic")
|
||||
with open(file="data/log/comic.html", mode="w") as file:
|
||||
file.write(response.text)
|
||||
file.close()
|
||||
|
||||
for line in response.text:
|
||||
for line in response.text.split("\n"):
|
||||
if '<meta property="og:url"' in line:
|
||||
with open(file="data/log/test.txt", mode="a") as file:
|
||||
file.write(line)
|
||||
file.close()
|
||||
line = line.split('"')
|
||||
for cell in line:
|
||||
if "https" in cell:
|
||||
return self.getSpecificComic(url=cell)
|
||||
|
||||
def getLastComic(self):
|
||||
response = requests.api.get(f"{self.url}/{self.__api}")
|
||||
return Comic(json.loads(response.text))
|
||||
|
||||
def getSpecificComic(self, num=None, url=None):
|
||||
if num != None:
|
||||
response = requests.api.get(url=f"{self.url}/{num}/{self.__api}")
|
||||
return Comic(json.loads(response.text))
|
||||
|
||||
if url != None:
|
||||
response = requests.api.get(url=f"{url}/{self.__api}")
|
||||
return Comic(json.loads(response.text))
|
||||
|
||||
13
src/main.py
13
src/main.py
@ -97,8 +97,11 @@ async def slash(interaction: Interaction):
|
||||
|
||||
@tree.command(name='get-random-comic', description='Get a random comic from XKCD')
|
||||
async def slash(interaction: Interaction):
|
||||
xkcd.getRandomComic()
|
||||
await interaction.response.send_message("hi")
|
||||
comic = xkcd.getRandomComic()
|
||||
|
||||
embed = discord.Embed(title=comic.title, color=Color.blue(), url=f"{xkcd.url}/{comic.num}")
|
||||
embed.set_image(url=comic.img)
|
||||
await interaction.response.send_message(embed=embed)
|
||||
|
||||
@tree.command(name="info", description="get info about this server")
|
||||
async def slash(interaction: Interaction):
|
||||
@ -130,9 +133,9 @@ async def slash(interaction: Interaction):
|
||||
logger.info("Command: help")
|
||||
commandListString = \
|
||||
"""\
|
||||
`/info`: Get infos about the server and the Bot
|
||||
`/get-random-comic`: Not working yet
|
||||
`/get-latest-comic`: Get latest comic from XKCD
|
||||
`/info`: Get infos about the server and the Bot\n
|
||||
`/get-random-comic`: Not working yet\n
|
||||
`/get-latest-comic`: Get latest comic from XKCD\n
|
||||
`/help`: Get this view
|
||||
"""
|
||||
embed = discord.Embed(title=f"Help", description="List of commands", color=Color.blue())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user