Merge branch 'develop' into 'main'

Develop into main

See merge request HendrikHeine/tux-discord-bot!2
This commit is contained in:
DasMoorhuhn 2023-03-02 22:56:39 +00:00
commit 24aa41f8d7
4 changed files with 48 additions and 25 deletions

View File

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

View File

@ -46,3 +46,25 @@ class XKCD:
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
@ -17,8 +18,8 @@ from discord import Guild
from discord import Color
from discord.activity import Game
botVersion = "1.0.1"
botDate = "03.02.2023"
botVersion = "1.0.23"
botDate = "02.03.2023"
secret = secretHandler.secret()
token = secret.loadSecret("secret.txt")
@ -35,6 +36,7 @@ logger.addHandler(handler)
#Init Addons
programmerExcuses = ProgrammerExcuses()
#redditProgrammerHumor = RedditProgrammerHumor()
xkcd = XKCD()
class client(discord.Client):
@ -83,7 +85,7 @@ async def on_guild_join(guild: Guild):
@tree.command(name='excuse', description='Get a random excuse from programmer excuses')
@tree.command(name='excuse', description='Get a random excuse from programmingexcuses')
async def slash(interaction: Interaction):
await interaction.response.send_message(programmerExcuses.getExcuse())
@ -103,41 +105,40 @@ async def slash(interaction: Interaction):
embed.set_image(url=comic.img)
await interaction.response.send_message(embed=embed)
@tree.command(name="info", description="get info about this server")
#@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 bot")
async def slash(interaction: Interaction):
logger.info("Command: info")
timeNow = getDateTime()[2]
uptime = timeNow - startTime
serverString = \
f"""\
Owner: {interaction.guild.owner}
Name: {interaction.guild.name}
"""
botString = \
f"""\
Uptime: {int(round(uptime/60, 1))}m
Version: {botVersion} from {botDate}
Developer: DasMoorhuhn.py#2604
Sourcecode: https://gitlab.com/HendrikHeine/tux-discord-bot
"""
botString = ""
botString += f"Uptime : {int(round(uptime, 0))}s\n"
botString += f"Version : {botVersion} from {botDate}\n"
botString += f"Developer : DasMoorhuhn.py#2604\n"
botString += f"Sourcecode: https://gitlab.com/HendrikHeine/tux-discord-bot"
embed = discord.Embed(title=f"Info", description="about this Server", timestamp=datetime.datetime.utcnow(), color=Color.blue())
#embed.set_thumbnail(url=interaction.guild.icon)
embed.add_field(name="Server", value=serverString, inline=False)
embed.add_field(name="Bot", value=botString, inline=False)
await interaction.response.send_message(embed=embed)
@tree.command(name="help", description="List of all Commands")
async def slash(interaction: Interaction):
logger.info("Command: help")
commandListString = \
"""\
`/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
"""
commandListString = ""
commandListString += "`/info` : Get infos about the server and the Bot\n"
commandListString += "`/help` : Get this view\n"
commandListString += "`/get-random-comic`: Get a randowm XCCD comic\n"
commandListString += "`/get-latest-comic`: Get latest comic from XKCD\n"
commandListString += "`/excuse` : Get a random excuse from programmingexcuses"
embed = discord.Embed(title=f"Help", description="List of commands", color=Color.blue())
#embed.set_thumbnail(url=interaction.guild.icon)
embed.add_field(name="Commands", value=commandListString, inline=True)

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