It workie, but like not super well lol

main
Matt C 2 years ago
parent c87146b8d1
commit 776266e8c4

4
.gitignore vendored

@ -1,3 +1,7 @@
# Custom
data/
.webhook
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

@ -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)

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

@ -0,0 +1,11 @@
<form action="/" method="POST">
<h3>Discord Tag: </h3>
<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>
<br/>
<button type='submit' class="btn btn-primary">Register</button>
</form>

@ -0,0 +1,35 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
body {
background-color: #45475a;
color: #cdd6f4;
}
input, textarea {
background-color: #bac2de;
color: black;
}
</style>
<title>{{dist}} - SimpleFeedback</title>
</head>
<body>
<h1>{{dist}} - SimpleFeedback</h1>
{{extra|safe}}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
Loading…
Cancel
Save