Merge branch 'develop' into 'main'

Develop

See merge request HendrikHeine/tux-discord-bot!1
This commit is contained in:
DasMoorhuhn 2023-02-04 13:12:29 +00:00
commit c9993783d8
3 changed files with 25 additions and 14 deletions

View File

@ -1,4 +1,4 @@
FROM python:3.11-slim
FROM python:3.11-alpine
WORKDIR /app

View File

@ -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))
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))

View File

@ -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())