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 WORKDIR /app

View File

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

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