2017-05-22 03:07:32 +02:00
|
|
|
from flask import Blueprint, render_template, abort, redirect, url_for, session, request
|
2017-11-15 07:13:42 +01:00
|
|
|
from flask_babel import gettext
|
2018-07-21 01:10:24 +02:00
|
|
|
from titanembeds.utils import check_guild_existance, guild_query_unauth_users_bool, guild_accepts_visitors, guild_unauthcaptcha_enabled, is_int, redisqueue
|
2017-04-05 06:00:44 +02:00
|
|
|
from titanembeds.oauth import generate_guild_icon_url, generate_avatar_url
|
2018-01-05 09:52:22 +01:00
|
|
|
from titanembeds.database import db, Guilds, UserCSS, list_disabled_guilds
|
2017-04-05 08:25:07 +02:00
|
|
|
from config import config
|
2017-04-04 07:53:27 +02:00
|
|
|
import random
|
2017-06-05 05:32:13 +02:00
|
|
|
import json
|
2018-01-13 19:37:42 +01:00
|
|
|
from urllib.parse import urlparse
|
2017-03-26 06:14:42 +02:00
|
|
|
|
|
|
|
embed = Blueprint("embed", __name__)
|
|
|
|
|
2017-04-04 07:53:27 +02:00
|
|
|
def get_logingreeting():
|
|
|
|
greetings = [
|
2017-11-15 07:13:42 +01:00
|
|
|
gettext("Let's get to know each other! My name is Titan, what's yours?"),
|
|
|
|
gettext("Hello and welcome!"),
|
|
|
|
gettext("What brings you here today?"),
|
|
|
|
gettext("....what do you expect this text to say?"),
|
|
|
|
gettext("Aha! ..made you look!"),
|
|
|
|
gettext("Initiating launch sequence..."),
|
|
|
|
gettext("Captain, what's your option?"),
|
|
|
|
gettext("Alright, here's the usual~"),
|
2017-04-04 07:53:27 +02:00
|
|
|
]
|
|
|
|
return random.choice(greetings)
|
|
|
|
|
2017-05-22 03:07:32 +02:00
|
|
|
def get_custom_css():
|
|
|
|
css = request.args.get("css", None)
|
2018-03-28 06:51:05 +02:00
|
|
|
if not is_int(css):
|
|
|
|
css = None
|
2017-05-22 03:07:32 +02:00
|
|
|
if css:
|
|
|
|
css = db.session.query(UserCSS).filter(UserCSS.id == css).first()
|
|
|
|
return css
|
|
|
|
|
2017-06-05 05:32:13 +02:00
|
|
|
def parse_css_variable(css):
|
|
|
|
CSS_VARIABLES_TEMPLATE = """:root {
|
|
|
|
/*--<var>: <value>*/
|
|
|
|
--modal: %(modal)s;
|
|
|
|
--noroleusers: %(noroleusers)s;
|
|
|
|
--main: %(main)s;
|
|
|
|
--placeholder: %(placeholder)s;
|
|
|
|
--sidebardivider: %(sidebardivider)s;
|
|
|
|
--leftsidebar: %(leftsidebar)s;
|
|
|
|
--rightsidebar: %(rightsidebar)s;
|
|
|
|
--header: %(header)s;
|
|
|
|
--chatmessage: %(chatmessage)s;
|
|
|
|
--discrim: %(discrim)s;
|
|
|
|
--chatbox: %(chatbox)s;
|
|
|
|
}"""
|
|
|
|
if not css:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
variables = css.css_variables
|
2017-09-08 02:37:37 +02:00
|
|
|
if variables:
|
|
|
|
variables = json.loads(variables)
|
|
|
|
return CSS_VARIABLES_TEMPLATE % variables
|
|
|
|
return None
|
2017-06-05 05:32:13 +02:00
|
|
|
|
2018-01-13 19:37:42 +01:00
|
|
|
def parse_url_domain(url):
|
|
|
|
parsed = urlparse(url)
|
|
|
|
if parsed.netloc != "":
|
|
|
|
return parsed.netloc
|
|
|
|
return url
|
|
|
|
|
2018-03-28 06:51:05 +02:00
|
|
|
@embed.route("/<int:guild_id>")
|
2017-03-26 06:14:42 +02:00
|
|
|
def guild_embed(guild_id):
|
2017-04-04 07:53:27 +02:00
|
|
|
if check_guild_existance(guild_id):
|
2018-07-21 01:10:24 +02:00
|
|
|
guild = redisqueue.get_guild(guild_id)
|
|
|
|
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
|
2018-10-09 23:23:53 +02:00
|
|
|
if not dbguild:
|
|
|
|
abort(404)
|
2017-05-08 21:13:53 +02:00
|
|
|
guild_dict = {
|
2018-07-21 01:10:24 +02:00
|
|
|
"id": guild["id"],
|
|
|
|
"name": guild["name"],
|
|
|
|
"unauth_users": dbguild.unauth_users,
|
|
|
|
"icon": guild["icon"],
|
|
|
|
"invite_link": dbguild.invite_link,
|
|
|
|
"invite_domain": parse_url_domain(dbguild.invite_link),
|
|
|
|
"post_timeout": dbguild.post_timeout,
|
2017-05-08 21:13:53 +02:00
|
|
|
}
|
2017-06-05 05:32:13 +02:00
|
|
|
customcss = get_custom_css()
|
2017-04-24 08:02:03 +02:00
|
|
|
return render_template("embed.html.j2",
|
2018-01-05 09:52:22 +01:00
|
|
|
disabled=guild_id in list_disabled_guilds(),
|
2017-04-24 08:02:03 +02:00
|
|
|
login_greeting=get_logingreeting(),
|
2017-09-21 09:12:49 +02:00
|
|
|
guild_id=guild_id,
|
|
|
|
guild=guild_dict,
|
2017-04-24 08:02:03 +02:00
|
|
|
generate_guild_icon=generate_guild_icon_url,
|
2017-04-05 08:25:07 +02:00
|
|
|
unauth_enabled=guild_query_unauth_users_bool(guild_id),
|
2017-06-09 06:22:33 +02:00
|
|
|
visitors_enabled=guild_accepts_visitors(guild_id),
|
2017-11-04 03:58:26 +01:00
|
|
|
unauth_captcha_enabled=guild_unauthcaptcha_enabled(guild_id),
|
2017-05-22 03:07:32 +02:00
|
|
|
client_id=config['client-id'],
|
2017-09-21 09:12:49 +02:00
|
|
|
recaptcha_site_key=config["recaptcha-site-key"],
|
2017-06-05 05:32:13 +02:00
|
|
|
css=customcss,
|
2017-11-13 23:01:34 +01:00
|
|
|
cssvariables=parse_css_variable(customcss),
|
2018-02-02 09:49:48 +01:00
|
|
|
same_target=request.args.get("sametarget", False) == "true",
|
2018-05-07 21:17:58 +02:00
|
|
|
userscalable=request.args.get("userscalable", "True").lower().startswith("t"),
|
|
|
|
fixed_sidenav=request.args.get("fixedsidenav", "False").lower().startswith("t")
|
2017-04-04 07:53:27 +02:00
|
|
|
)
|
|
|
|
abort(404)
|
|
|
|
|
|
|
|
@embed.route("/signin_complete")
|
|
|
|
def signin_complete():
|
|
|
|
return render_template("signin_complete.html.j2")
|
|
|
|
|
|
|
|
@embed.route("/login_discord")
|
|
|
|
def login_discord():
|
2017-04-24 08:02:03 +02:00
|
|
|
return redirect(url_for("user.login_authenticated", redirect=url_for("embed.signin_complete", _external=True)))
|
2018-01-05 00:27:05 +01:00
|
|
|
|
|
|
|
@embed.route("/noscript")
|
|
|
|
def noscript():
|
|
|
|
return render_template("noscript.html.j2")
|