Merge branch 'develop' into 'main'
Develop into main See merge request HendrikHeine/tux-discord-bot!2
This commit is contained in:
commit
24aa41f8d7
@ -1,4 +1,4 @@
|
||||
FROM python:3.11-alpine
|
||||
FROM python:3.11.2-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
49
src/main.py
49
src/main.py
@ -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
0
src/models/redditPost.py
Normal file
Loading…
x
Reference in New Issue
Block a user