From 776266e8c453a76f7fff4752b0a881e994e24a5f Mon Sep 17 00:00:00 2001 From: Matt C Date: Thu, 6 Oct 2022 22:57:53 -0400 Subject: [PATCH] It workie, but like not super well lol --- .gitignore | 4 +++ app.py | 61 +++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 4 +++ templates/form.html | 11 ++++++++ templates/page.html | 35 ++++++++++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 app.py create mode 100644 requirements.txt create mode 100644 templates/form.html create mode 100644 templates/page.html diff --git a/.gitignore b/.gitignore index b6e4761..33a056e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# Custom +data/ +.webhook + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/app.py b/app.py new file mode 100644 index 0000000..f8a0b71 --- /dev/null +++ b/app.py @@ -0,0 +1,61 @@ +import time, os +from datetime import datetime + +from flask import ( + Flask, + render_template, + request, + make_response, + redirect, +) + +from flask_limiter import Limiter +from flask_limiter.util import get_remote_address +from werkzeug.exceptions import HTTPException + +from discord_webhook import DiscordWebhook + +APP_DIST = "Crystal Linux" + +app = Flask(__name__) +app.secret_key = "SuperStrongAndComplicated" + +limiter = Limiter( + app, + key_func=get_remote_address, + default_limits=["20 per day", "5 per hour"], + storage_uri="memory://", +) + + +@app.errorhandler(HTTPException) +def oopsie(e): + return f"Oops: {str(e)}" + + +@app.route("/", methods=["GET", "POST"]) +def do_stuff(): + if request.method == "GET": + return render_template( + "page.html", dist=APP_DIST, extra=render_template("form.html") + ) + 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" + 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!" + else: + return "How did we get here?" + + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=9090, debug=True) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f7bca4f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +Flask[async] +gunicorn +Flask-Limiter +discord-webhook \ No newline at end of file diff --git a/templates/form.html b/templates/form.html new file mode 100644 index 0000000..b6c09a6 --- /dev/null +++ b/templates/form.html @@ -0,0 +1,11 @@ +
+

Discord Tag:

+ +
+

Feedback:

+ +
+ +
\ No newline at end of file diff --git a/templates/page.html b/templates/page.html new file mode 100644 index 0000000..59fc373 --- /dev/null +++ b/templates/page.html @@ -0,0 +1,35 @@ + + + + + + + + + + + + + {{dist}} - SimpleFeedback + + +

{{dist}} - SimpleFeedback

+ + {{extra|safe}} + + + + + + + + \ No newline at end of file