Updated Dockerfiles and implemented API endpoint
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
FROM python:3.10
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
COPY code /app
|
||||
|
||||
ENTRYPOINT [ "python", "wingl.py" ]
|
||||
13
Dockerfiles/api/Dockerfile
Normal file
13
Dockerfiles/api/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
FROM python:3.10-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements_api.txt .
|
||||
|
||||
RUN pip3 install -r requirements_api.txt
|
||||
|
||||
COPY code /app
|
||||
|
||||
ENTRYPOINT ["gunicorn", "api:app", "--workers", "4", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000"]
|
||||
|
||||
EXPOSE 8000
|
||||
11
Dockerfiles/bot/Dockerfile
Normal file
11
Dockerfiles/bot/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM python:3.10-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements_bot.txt .
|
||||
|
||||
RUN pip3 install -r requirements_bot.txt
|
||||
|
||||
COPY code /app
|
||||
|
||||
ENTRYPOINT [ "python", "bot.py" ]
|
||||
BIN
code/__pycache__/api.cpython-39.pyc
Normal file
BIN
code/__pycache__/api.cpython-39.pyc
Normal file
Binary file not shown.
BIN
code/__pycache__/wingl.cpython-39.pyc
Normal file
BIN
code/__pycache__/wingl.cpython-39.pyc
Normal file
Binary file not shown.
20
code/api.py
Normal file
20
code/api.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from typing import Union
|
||||
from fastapi import FastAPI
|
||||
from module.rainer_board import rainerSpruche
|
||||
import configparser
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
spruchDatei = config.get('GENERAL','spruchDatei')
|
||||
nameDatei = config.get('GENERAL', 'nameDatei')
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/")
|
||||
def getSpruch():
|
||||
rainer = rainerSpruche(spruchDatei, nameDatei)
|
||||
spruch = rainer.randomSpruch()
|
||||
name = rainer.randomName()
|
||||
print("**DEBUG** " + name + ": " + spruch)
|
||||
return {"name": name , "spruch": spruch}
|
||||
@@ -8,14 +8,13 @@ config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
spruchDatei = config.get('GENERAL','spruchDatei')
|
||||
nameDatei = config.get('GENERAL', 'nameDatei')
|
||||
botToken = config.get('BOT','token')
|
||||
|
||||
bot = lightbulb.BotApp(
|
||||
token=botToken
|
||||
)
|
||||
|
||||
|
||||
|
||||
@bot.listen(hikari.StartedEvent)
|
||||
async def onStarted(event):
|
||||
print('Der Bot wurde gestartet!')
|
||||
@@ -28,7 +27,9 @@ async def onStopped(event):
|
||||
@lightbulb.command('haider', 'Meddld nen krassen Spruch raus etzadla!')
|
||||
@lightbulb.implements(lightbulb.SlashCommand)
|
||||
async def haider(ctx):
|
||||
spruch = rainerSpruche(spruchDatei)
|
||||
await ctx.respond(spruch.randomSpruch())
|
||||
rainer = rainerSpruche(spruchDatei, nameDatei)
|
||||
spruch = rainer.randomSpruch()
|
||||
name = rainer.randomName()
|
||||
await ctx.respond(name + ' sagt: ' + '\n' + spruch)
|
||||
|
||||
bot.run()
|
||||
@@ -1,5 +1,6 @@
|
||||
[GENERAL]
|
||||
spruchDatei = sprueche.txt
|
||||
nameDatei = namen.txt
|
||||
|
||||
[BOT]
|
||||
token = MTA3ODc1MTc5NzY5NjUyODQ0Nw.GNMTke.Mf5kSPSR6YjBLbSGKdGHBrXmpm9Hv7bkZyvLDU
|
||||
Binary file not shown.
@@ -3,15 +3,18 @@ import random
|
||||
|
||||
class rainerSpruche():
|
||||
|
||||
def __init__(self, spruchDatei):
|
||||
|
||||
def __init__(self, spruchDatei, nameDatei):
|
||||
with open(spruchDatei, 'r') as f:
|
||||
self.zitate = [line.strip() for line in f]
|
||||
|
||||
|
||||
with open(nameDatei, 'r') as f:
|
||||
self.names = [line.strip() for line in f]
|
||||
self.letzte_zahl = []
|
||||
self.spruchDatei = spruchDatei
|
||||
self.nameDatei = nameDatei
|
||||
|
||||
def randomSpruch(self):
|
||||
self.aktuelle_zahl = random.randint(0, len(self.zitate)-1)
|
||||
self.aktuelle_zahl = random.sample(range(len(self.zitate)), 1)[0]
|
||||
mögliche_zahlen = list(range(len(self.zitate)))
|
||||
while self.aktuelle_zahl in self.letzte_zahl:
|
||||
mögliche_zahlen.remove(self.aktuelle_zahl)
|
||||
@@ -21,4 +24,17 @@ class rainerSpruche():
|
||||
if len(self.letzte_zahl) >= 3:
|
||||
self.letzte_zahl.pop(0)
|
||||
self.letzte_zahl.append(self.aktuelle_zahl)
|
||||
return(self.zitate[self.aktuelle_zahl])
|
||||
return(self.zitate[self.aktuelle_zahl])
|
||||
|
||||
def randomName(self):
|
||||
self.aktuelle_zahl = random.sample(range(len(self.names)), 1)[0]
|
||||
mögliche_zahlen = list(range(len(self.names)))
|
||||
while self.aktuelle_zahl in self.letzte_zahl:
|
||||
mögliche_zahlen.remove(self.aktuelle_zahl)
|
||||
if len(mögliche_zahlen) == 0:
|
||||
mögliche_zahlen = list(range(len(self.names)))
|
||||
self.aktuelle_zahl = random.choice(mögliche_zahlen)
|
||||
if len(self.letzte_zahl) >= 3:
|
||||
self.letzte_zahl.pop(0)
|
||||
self.letzte_zahl.append(self.aktuelle_zahl)
|
||||
return(self.names[self.aktuelle_zahl])
|
||||
|
||||
10
code/namen.txt
Normal file
10
code/namen.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
Rainer
|
||||
Wongl
|
||||
Wingler
|
||||
Winkler
|
||||
Der Drache
|
||||
Der Obdachlose
|
||||
Der Vierteltonner
|
||||
Der Lard
|
||||
Rainer Winkler Hosenpinkler
|
||||
Der Bewährungsversager
|
||||
@@ -24,6 +24,10 @@ Die Haut ist KEIN Organ!
|
||||
bidde ferlass uns
|
||||
Ich bin der Meinung, hätte man die...äh...hätte man Amerika nie entdeckt und die Indianer hätten da ihr Leben weitergelebt...dann bin ich fest der Überzeugung, dass diese Menschen, die damals da lebten heute sowas wie Elfen wären
|
||||
Ich hab Kopfhörer auf ich hör dich net!
|
||||
Rainer: Verpiss dich von meinem Land du Affe! Haider: Gehört dir Bayern?
|
||||
Verpiss dich von meinem Land du Affe!
|
||||
The Legend of Zelad: Bride of the Wind
|
||||
EZIOOOOO!!!!! Du bist ein verdammter Vollidiot!!!! Was machst du denn schon widder?
|
||||
EZIOOOOO!!!!! Du bist ein verdammter Vollidiot!!!! Was machst du denn schon widder?
|
||||
Hass ist keine Emotion!
|
||||
skurr skurr in mei Audi! Baller die Kurve zu krass, digga komm ich um die Kurve mach Platz... DIGGA!
|
||||
Was interessiert mich ein Amoklauf in Österreich??!! Bei mir ist jedentag sowas wie äh... ein Amoklauf!
|
||||
Was zitterst denn so?
|
||||
@@ -1,8 +1,17 @@
|
||||
version: "3"
|
||||
services:
|
||||
app:
|
||||
discord-bot:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfiles/Dockerfile
|
||||
container_name: winglbot
|
||||
dockerfile: Dockerfiles/bot/Dockerfile
|
||||
container_name: wingl-bot
|
||||
restart: always
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfiles/api/Dockerfile
|
||||
container_name: wingl-api
|
||||
restart: always
|
||||
ports:
|
||||
- 8000:8000
|
||||
4
requirements_api.txt
Normal file
4
requirements_api.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
fastapi
|
||||
uvicorn[standard]
|
||||
gunicorn
|
||||
Reference in New Issue
Block a user