2017-02-10 06:10:44 +01:00
|
|
|
from config import config
|
2017-08-27 04:22:03 +02:00
|
|
|
try:
|
|
|
|
import uwsgi
|
2017-08-20 21:56:54 +02:00
|
|
|
from gevent import monkey
|
|
|
|
monkey.patch_all()
|
2017-08-27 04:22:03 +02:00
|
|
|
except:
|
|
|
|
if config.get("websockets-mode", None) == "eventlet":
|
|
|
|
import eventlet
|
|
|
|
eventlet.monkey_patch()
|
|
|
|
elif config.get("websockets-mode", None) == "gevent":
|
|
|
|
from gevent import monkey
|
|
|
|
monkey.patch_all()
|
2017-02-10 06:10:44 +01:00
|
|
|
|
2018-02-11 01:25:53 +01:00
|
|
|
from .database import db
|
|
|
|
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
|
|
|
|
from flask_sslify import SSLify
|
|
|
|
from titanembeds.utils import rate_limiter, discord_api, socketio, babel, redis_store, language_code_list
|
|
|
|
from .blueprints import api, user, admin, embed, gateway
|
|
|
|
import os
|
|
|
|
from titanembeds.database import get_administrators_list
|
|
|
|
import titanembeds.constants as constants
|
|
|
|
from datetime import timedelta
|
2018-03-24 07:03:33 +01:00
|
|
|
import datetime
|
2018-02-11 01:25:53 +01:00
|
|
|
|
2017-02-10 06:10:44 +01:00
|
|
|
os.chdir(config['app-location'])
|
2017-03-25 08:52:56 +01:00
|
|
|
app = Flask(__name__, static_folder="static")
|
2017-09-05 08:54:54 +02:00
|
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = config['database-uri']
|
2017-02-10 06:10:44 +01:00
|
|
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Suppress the warning/no need this on for now.
|
2017-04-04 07:53:27 +02:00
|
|
|
app.config['RATELIMIT_HEADERS_ENABLED'] = True
|
2018-01-23 20:01:17 +01:00
|
|
|
app.config['SQLALCHEMY_POOL_RECYCLE'] = 100
|
|
|
|
app.config['SQLALCHEMY_POOL_SIZE'] = 15
|
2017-12-29 18:40:32 +01:00
|
|
|
app.config['RATELIMIT_STORAGE_URL'] = config["redis-uri"]
|
2017-12-01 05:08:20 +01:00
|
|
|
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=3)
|
2017-12-29 18:40:32 +01:00
|
|
|
app.config['REDIS_URL'] = config["redis-uri"]
|
2017-02-10 06:10:44 +01:00
|
|
|
app.secret_key = config['app-secret']
|
|
|
|
|
|
|
|
db.init_app(app)
|
2017-03-27 01:37:27 +02:00
|
|
|
rate_limiter.init_app(app)
|
2017-12-20 02:01:50 +01:00
|
|
|
if config.get("enable-ssl", False):
|
|
|
|
sslify = SSLify(app, permanent=True)
|
2017-08-20 21:56:54 +02:00
|
|
|
socketio.init_app(app, message_queue=config["redis-uri"], path='gateway', async_mode=config.get("websockets-mode", None))
|
2017-11-15 07:13:42 +01:00
|
|
|
babel.init_app(app)
|
2017-12-29 18:40:32 +01:00
|
|
|
redis_store.init_app(app)
|
2017-02-10 06:10:44 +01:00
|
|
|
|
2017-08-19 02:33:50 +02:00
|
|
|
app.register_blueprint(api.api, url_prefix="/api", template_folder="/templates")
|
|
|
|
app.register_blueprint(admin.admin, url_prefix="/admin", template_folder="/templates")
|
|
|
|
app.register_blueprint(user.user, url_prefix="/user", template_folder="/templates")
|
|
|
|
app.register_blueprint(embed.embed, url_prefix="/embed", template_folder="/templates")
|
2017-08-19 07:09:13 +02:00
|
|
|
socketio.on_namespace(gateway.Gateway('/gateway'))
|
2017-02-10 06:10:44 +01:00
|
|
|
|
2017-11-16 04:09:53 +01:00
|
|
|
@babel.localeselector
|
|
|
|
def get_locale():
|
|
|
|
param_lang = request.args.get("lang", None)
|
2018-01-13 02:34:23 +01:00
|
|
|
if param_lang in language_code_list():
|
2017-11-16 04:09:53 +01:00
|
|
|
return param_lang
|
2018-01-13 02:34:23 +01:00
|
|
|
return request.accept_languages.best_match(language_code_list())
|
2017-11-16 04:09:53 +01:00
|
|
|
|
2017-02-10 06:10:44 +01:00
|
|
|
@app.route("/")
|
2017-03-25 08:52:56 +01:00
|
|
|
def index():
|
2017-03-26 05:31:47 +02:00
|
|
|
return render_template("index.html.j2")
|
2017-04-24 20:55:09 +02:00
|
|
|
|
2017-05-11 04:12:26 +02:00
|
|
|
@app.route("/about")
|
|
|
|
def about():
|
|
|
|
return render_template("about.html.j2")
|
|
|
|
|
2017-09-12 06:06:29 +02:00
|
|
|
@app.route("/terms")
|
|
|
|
def terms():
|
|
|
|
return render_template("terms_and_conditions.html.j2")
|
|
|
|
|
|
|
|
@app.route("/privacy")
|
|
|
|
def privacy():
|
|
|
|
return render_template("privacy_policy.html.j2")
|
|
|
|
|
2018-02-27 08:22:58 +01:00
|
|
|
@app.route("/vote")
|
|
|
|
def vote():
|
2018-02-27 22:22:25 +01:00
|
|
|
return render_template("discordbotsorg_vote.html.j2", referrer=request.args.get("referrer", None))
|
2018-02-27 08:22:58 +01:00
|
|
|
|
2018-07-09 03:37:35 +02:00
|
|
|
@app.route("/global_banned_words")
|
|
|
|
def global_banned_words():
|
|
|
|
return render_template("global_banned_words.html.j2")
|
|
|
|
|
2017-09-28 18:36:29 +02:00
|
|
|
@app.before_first_request
|
|
|
|
def before_first_request():
|
2017-04-24 20:55:09 +02:00
|
|
|
discord_api.init_discordrest()
|
2017-06-13 03:39:49 +02:00
|
|
|
|
|
|
|
@app.context_processor
|
|
|
|
def context_processor():
|
2018-06-28 01:11:36 +02:00
|
|
|
return {
|
|
|
|
"devs": get_administrators_list(),
|
|
|
|
"constants": constants,
|
|
|
|
"af_mode_enabled": datetime.datetime.now().date() == datetime.date(datetime.datetime.now().year, 4, 1),
|
|
|
|
"dbl_voted": session.get("unauthenticated", True) == False and bool(redis_store.get("DiscordBotsOrgVoted/" + str(session.get("user_id", -1))))
|
|
|
|
}
|