-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Veiled-Haven/feat_discord_application
feat: replace application form with discord link
- Loading branch information
Showing
7 changed files
with
15 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,14 @@ | ||
import os | ||
from flask import Flask, render_template, request, redirect, url_for | ||
from discord_webhook import DiscordWebhook, DiscordEmbed | ||
from flask_bootstrap import Bootstrap4 | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, IntegerField, TextAreaField, BooleanField, SubmitField, ValidationError | ||
from wtforms.validators import DataRequired, NumberRange | ||
from flask import Flask, render_template | ||
|
||
webhook_url = os.environ.get('DISCORD_WEBHOOK_URL', "") | ||
app = Flask( | ||
__name__, static_url_path="", static_folder="static/", template_folder="templates/" | ||
) | ||
|
||
app = Flask(__name__,static_url_path='',static_folder='static/',template_folder='templates/') | ||
SECRET_KEY = os.urandom(32) | ||
app.config['SECRET_KEY'] = SECRET_KEY | ||
bootstrap = Bootstrap4(app) | ||
|
||
class ValidateMath(object): | ||
def __init__(self, message=None): | ||
self.message = message | ||
|
||
def __call__(self, form, field): | ||
if field.data != 13: | ||
raise ValidationError(self.message) | ||
|
||
|
||
class ApplicationForm(FlaskForm): | ||
minecraft_username = StringField("What is your Minecraft username?*",description="We need this information to eventually Whitelist you on the Server!", validators=[DataRequired()]) | ||
discord_username = StringField("What is your Discord username?*", description="<b>Please make sure you accept Friend Requests</b>, Discord is where we will get in touch with you!", validators=[DataRequired()]) | ||
why_would_you_like_to_join = TextAreaField("Why would you like to join?*", validators=[DataRequired()]) | ||
favorite_aspect = TextAreaField("What is your favorite aspect of playing Minecraft online?*", validators=[DataRequired()]) | ||
how_long_have_you_played = TextAreaField("How long have you been playing Minecraft?") | ||
have_you_been_part_of_an_smp = TextAreaField("Have you been part of any SMP's before, if so why did you leave?") | ||
age = IntegerField("What is your age?*", validators=[DataRequired(),NumberRange(min=16,max=200,message="Sorry, you are to Young to play with us :(")]) | ||
math = IntegerField("What is Five plus Eight?*",validators=[DataRequired(),ValidateMath(message="Are you sure your Math is correct?")]) | ||
rules_accepted = BooleanField("Do you accept the Rules?*", validators=[DataRequired()]) | ||
submit = SubmitField() | ||
|
||
|
||
|
||
@app.route("/", methods=["GET", "POST"]) | ||
@app.route("/") | ||
def home(): | ||
form = ApplicationForm() | ||
if request.method == "POST" and form.validate_on_submit(): #on form submission | ||
webhook = DiscordWebhook(url=webhook_url) | ||
embed = DiscordEmbed(title='Form Submission') | ||
print(form.data) | ||
for form_field in form.data: | ||
print(f"{form_field}: {form.data[form_field]}") | ||
embed.add_embed_field(name=form_field, value=form.data[form_field]) | ||
# add embed object to webhook | ||
webhook.add_embed(embed) | ||
if webhook_url != "": | ||
response = webhook.execute() | ||
return redirect(location=url_for("success"),code=302) | ||
elif form.errors: | ||
return render_template("index.html", form=form, anchor=list(form.errors.keys())[0]) | ||
else: | ||
return render_template("index.html", form=form) | ||
|
||
return render_template("index.html") | ||
|
||
@app.route("/success") | ||
def success(): | ||
return render_template("success.html") | ||
|
||
app.run(host='0.0.0.0', port=5000) | ||
app.run(host="0.0.0.0", port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
flask | ||
discord-webhook | ||
bootstrap-flask | ||
flask-wtf |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.