more minor stuff

main
Matt C 2 years ago
parent 776266e8c4
commit 21b8deb5a0

@ -1,5 +1,4 @@
import time, os
from datetime import datetime
import os, sys
from flask import (
Flask,
@ -15,7 +14,16 @@ from werkzeug.exceptions import HTTPException
from discord_webhook import DiscordWebhook
APP_DIST = "Crystal Linux"
import yaml
if os.path.exists("settings.yaml"):
settings_obj = yaml.safe_load(open("settings.yaml").read().strip())
APP_DIST = settings_obj["app_dist"]
CAMP_EXTRA = settings_obj["camp_extra"]
else:
print("No 'settings.yaml', exiting")
sys.exit(1)
app = Flask(__name__)
app.secret_key = "SuperStrongAndComplicated"
@ -37,25 +45,54 @@ def oopsie(e):
def do_stuff():
if request.method == "GET":
return render_template(
"page.html", dist=APP_DIST, extra=render_template("form.html")
"page.html",
dist=APP_DIST,
extra=render_template("form.html", dist=APP_DIST, camp_extra=CAMP_EXTRA),
)
elif request.method == "POST":
dtag = request.form["discord-tag"]
feedback = request.form["feedback"]
if not os.path.exists("data"):
os.makedirs("data")
if os.path.exists("data/" + dtag):
return "Already submitted"
fail = False
if not "#" in dtag:
fail = True
elif len(dtag.split("#")[1]) != 4:
fail = True
if not fail:
if not os.path.exists("data"):
os.makedirs("data")
if os.path.exists("data/" + dtag):
return render_template(
"page.html",
dist=APP_DIST,
extra="<p style='color:red;'>This user has submitted before.</p>",
)
else:
with open("data/" + dtag, "w") as f:
f.write(feedback)
content = f"User: `{dtag}` submitted the following:\n```{feedback}\n```"
webhook = DiscordWebhook(
url=open(".webhook").read().strip(), content=content
)
response = webhook.execute()
return render_template(
"page.html", dist=APP_DIST, extra="<p>Thanks for your feedback!</p>"
)
else:
with open("data/" + dtag, "w") as f:
f.write(feedback)
content = f"User: `{dtag}` submitted the following:\n```{feedback}\n```"
webhook = DiscordWebhook(url=open(".webhook").read().strip(), content=content)
response = webhook.execute()
return "Thanks!"
return render_template(
"page.html",
dist=APP_DIST,
extra=f"<p style='color:red;'>Funky discord tag you got there: '{dtag}'</p>",
)
else:
return "How did we get here?"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=9090, debug=True)
app.run(
host=settings_obj["host"],
port=settings_obj["port"],
debug=settings_obj["debug"],
)

@ -1,4 +1,5 @@
Flask[async]
gunicorn
Flask-Limiter
discord-webhook
discord-webhook
pyyaml

@ -0,0 +1,5 @@
app_dist: "Crystal Linux"
camp_extra: "Please note that this particular event is only able to ship to the US and Canada."
host: "0.0.0.0"
port: 9090
debug: true

@ -3,9 +3,10 @@
<input type='text' name='discord-tag'/>
<br/>
<h3>Feedback: </h3>
<textarea name='feedback'>
What do you like, or dislike, about Crystal Linux, and how can we make it better? :)
<textarea name='feedback' rows="5">
What do you like, or dislike, about {{dist}}, and how can we make it better? :)
</textarea>
<br/>
<br/><br/>
<p>{{camp_extra}}</p>
<button type='submit' class="btn btn-primary">Register</button>
</form>

@ -23,6 +23,7 @@
</head>
<body>
<h1>{{dist}} - SimpleFeedback</h1>
<p>Worried about our usage of your data? Don't be, this program is <a href="https://github.com/crystal-linux/simplefeedback">open source</a>. :)</p>
{{extra|safe}}

Loading…
Cancel
Save