From 5fa502035a5d488df6c6f9d4f15bf6b334d3f5ca Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Sat, 20 May 2017 01:04:45 +0000 Subject: [PATCH] Webapp modification for the new invite process splash --- webapp/titanembeds/blueprints/user/user.py | 7 +- webapp/titanembeds/oauth.py | 2 +- webapp/titanembeds/static/js/add-bot.js | 53 +++++++++++++ webapp/titanembeds/templates/add_bot.html.j2 | 82 ++++++++++++++++++++ 4 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 webapp/titanembeds/static/js/add-bot.js create mode 100644 webapp/titanembeds/templates/add_bot.html.j2 diff --git a/webapp/titanembeds/blueprints/user/user.py b/webapp/titanembeds/blueprints/user/user.py index 91bd00b..fc14507 100644 --- a/webapp/titanembeds/blueprints/user/user.py +++ b/webapp/titanembeds/blueprints/user/user.py @@ -76,7 +76,7 @@ def administrate_guild(guild_id): db_guild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first() if not db_guild: session["redirect"] = url_for("user.administrate_guild", guild_id=guild_id, _external=True) - return redirect(generate_bot_invite_url(guild_id)) + return redirect(url_for("user.add_bot", guild_id=guild_id)) session["redirect"] = None permissions=[] if check_user_permission(guild_id, 5): @@ -121,6 +121,11 @@ def update_administrate_guild(guild_id): mentions_limit=db_guild.mentions_limit, ) +@user.route("/add-bot/") +@discord_users_only() +def add_bot(guild_id): + return render_template("add_bot.html.j2", guild_id=guild_id, guild_invite_url=generate_bot_invite_url(guild_id)) + def prepare_guild_members_list(members, bans): all_users = [] ip_pool = [] diff --git a/webapp/titanembeds/oauth.py b/webapp/titanembeds/oauth.py index f9ca6cb..389d32e 100644 --- a/webapp/titanembeds/oauth.py +++ b/webapp/titanembeds/oauth.py @@ -96,5 +96,5 @@ def generate_guild_icon_url(id, hash): return guild_icon_url + str(id) + "/" + str(hash) + ".jpg" def generate_bot_invite_url(guild_id): - url = "https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}&guild_id={}&response_type=code&redirect_uri={}".format(config['client-id'], '536083583', guild_id, url_for("user.dashboard", _external=True)) + url = "https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}&guild_id={}".format(config['client-id'], '536083583', guild_id) return url diff --git a/webapp/titanembeds/static/js/add-bot.js b/webapp/titanembeds/static/js/add-bot.js new file mode 100644 index 0000000..664cbdd --- /dev/null +++ b/webapp/titanembeds/static/js/add-bot.js @@ -0,0 +1,53 @@ +/* global $ */ +/* global guild_id */ +/* global guild_invite_url */ + +(function () { + function query_guild() { + var funct = $.ajax({ + dataType: "json", + url: "/api/query_guild", + data: {"guild_id": guild_id} + }); + return funct.promise(); + } + + $(function(){ + $("#invite-waiting").hide(); + $("#invite-waiting-fail").hide(); + $("#invite-done").hide(); + + $("#invite-btn").click(startInviteProcess); + }); + + function startInviteProcess() { + $("#invite-initial").hide("slow"); + $("#invite-waiting").show("slow"); + window.open(guild_invite_url); + query_guild_process(0); + } + + function query_guild_process(index) { + setTimeout(function() { + var guild = query_guild(); + guild.done(function(data) { + $("#invite-waiting").hide("slow"); + $("#invite-done").show("slow"); + return; + }); + guild.fail(function(data) { + if (data.status != 404 && data.status < 500) { // technically good + $("#invite-waiting").hide("slow"); + $("#invite-done").show("slow"); + return; + } else if (index < 7) { + query_guild_process(index + 1); + } else { + $("#invite-waiting").hide("slow"); + $("#invite-waiting-fail").show("slow"); + return; + } + }); + }, 5000); + } +})(); \ No newline at end of file diff --git a/webapp/titanembeds/templates/add_bot.html.j2 b/webapp/titanembeds/templates/add_bot.html.j2 new file mode 100644 index 0000000..bde3999 --- /dev/null +++ b/webapp/titanembeds/templates/add_bot.html.j2 @@ -0,0 +1,82 @@ +{% extends 'site_layout.html.j2' %} +{% block title %}Adding bot to server{% endblock %} + +{% block content %} +

Would you like to invite Titan to your server?

+

Please keep in mind that Titan currently requires Administrator permissions to function.
+This is strictly enforced for the bot to send messages to all the channels, read role permissions, access banned users list, etc.

+
+
+
+ +

Step 1

+
Once you are ready to add the bot to your server, please hit the button below to start the process.
+
+ Invite Titan! +

(Opens in a new window)

+
+
+ +
+ +

Step 2

+
Please wait a moment for the bot tries to situate itself...
+
+
+
+
+
+
+ +
+ +

Step 2

+
Oops!
+

There seems to be a problem processing the invite.
+ Please make sure that the bot is given Administrator permission in the server.

+
+

You may try adding the bot to the server again, or report the bug on our + Discord server.

+
+ +
+ Try again +
+
+
+
+ +
+ +

Step 3

+
Congratulations! You have added Titan to your server!
+

You may start configuring your server to your likings.

+

+ Keep in mind that if your server is large (500+ members(?) overall), it may + take a while for the bot to index. Please allow five to ten minutes. If you are still + unable to login to the embed with your Discord account, please talk to us and + we'll sort this out right away! +

+ +
+
+
+
+{% endblock %} +{% block script %} + + + +{% endblock %} \ No newline at end of file