diff --git a/app.py b/app.py index f8a0b71..7940fff 100644 --- a/app.py +++ b/app.py @@ -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="

This user has submitted before.

", + ) + 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="

Thanks for your feedback!

" + ) 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"

Funky discord tag you got there: '{dtag}'

", + ) 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"], + ) diff --git a/requirements.txt b/requirements.txt index f7bca4f..d5eb850 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask[async] gunicorn Flask-Limiter -discord-webhook \ No newline at end of file +discord-webhook +pyyaml \ No newline at end of file diff --git a/settings.yaml b/settings.yaml new file mode 100644 index 0000000..43e9552 --- /dev/null +++ b/settings.yaml @@ -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 \ No newline at end of file diff --git a/templates/form.html b/templates/form.html index b6c09a6..3af4c0b 100644 --- a/templates/form.html +++ b/templates/form.html @@ -3,9 +3,10 @@

Feedback:

- -
+

+

{{camp_extra}}

\ No newline at end of file diff --git a/templates/page.html b/templates/page.html index 59fc373..93ae7a3 100644 --- a/templates/page.html +++ b/templates/page.html @@ -23,6 +23,7 @@

{{dist}} - SimpleFeedback

+

Worried about our usage of your data? Don't be, this program is open source. :)

{{extra|safe}}