This commit is contained in:
DasMoorhuhn 2023-02-04 18:06:01 +01:00
parent 31f2d9c7f5
commit a53b4fa041
3 changed files with 31 additions and 0 deletions

View File

@ -45,4 +45,26 @@ class XKCD:
if url != None:
response = requests.api.get(url=f"{url}/{self.__api}")
return Comic(json.loads(response.text))
class Reddit:
def __init__(self) -> None:
self.url = "https://www.reddit.com"
self.random = "random.json"
def _getRandomPost(self, community):
response = requests.get(f"{self.url}/{community}/{self.random}")
return json.loads(response.text)
class RedditProgrammerHumor(Reddit):
def __init__(self) -> None:
super().__init__()
self.community = "r/ProgrammerHumor"
def getRandomPost(self):
post = self._getRandomPost(self.community)
with open(file="data/log/test.json", mode="w") as file:
file.write(json.dumps(obj=post, indent=2))
file.close()
return post

View File

@ -5,6 +5,7 @@ import datetime
import secretHandler
from addons import ProgrammerExcuses
from addons import XKCD
from addons import RedditProgrammerHumor
from models.xkcdComic import Comic
@ -35,6 +36,7 @@ logger.addHandler(handler)
#Init Addons
programmerExcuses = ProgrammerExcuses()
redditProgrammerHumor = RedditProgrammerHumor()
xkcd = XKCD()
class client(discord.Client):
@ -103,6 +105,13 @@ async def slash(interaction: Interaction):
embed.set_image(url=comic.img)
await interaction.response.send_message(embed=embed)
@tree.command(name='programmer-humor', description='Get a random Post from r/ProgrammerHumor')
async def slash(interaction: Interaction):
post = redditProgrammerHumor.getRandomPost()
await interaction.response.send_message("hi")
@tree.command(name="info", description="get info about this server")
async def slash(interaction: Interaction):
logger.info("Command: info")

0
src/models/redditPost.py Normal file
View File