From 9527ef53e519eae743dbc2e307464f727e67658d Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Tue, 4 Apr 2017 06:18:28 +0000 Subject: [PATCH] Automatically fetching data with the server --- titanembeds/blueprints/embed/embed.py | 1 - titanembeds/static/js/embed.js | 30 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/titanembeds/blueprints/embed/embed.py b/titanembeds/blueprints/embed/embed.py index 60362f9..8f1a589 100644 --- a/titanembeds/blueprints/embed/embed.py +++ b/titanembeds/blueprints/embed/embed.py @@ -20,7 +20,6 @@ def get_logingreeting(): @embed.route("/") def guild_embed(guild_id): - print guild_id if check_guild_existance(guild_id): guild = discord_api.get_guild(guild_id)['content'] return render_template("embed.html.j2", diff --git a/titanembeds/static/js/embed.js b/titanembeds/static/js/embed.js index 7ea8bfb..b57502a 100644 --- a/titanembeds/static/js/embed.js +++ b/titanembeds/static/js/embed.js @@ -109,6 +109,8 @@ function prepare_guild(guildobj) { fill_discord_members(guildobj.discordmembers); fill_authenticated_users(guildobj.embedmembers.authenticated); fill_unauthenticated_users(guildobj.embedmembers.unauthenticated); + console.log("running fetch routine"); + run_fetch_routine(); } function fill_channels(channels) { @@ -176,6 +178,34 @@ function _wait_for_discord_login(index) { }, 5000); } +function run_fetch_routine() { + var channel_id = guild_id; //TODO: implement channel selector + var fet = fetch(channel_id); + fet.done(function(data) { + console.log(data); + + var guild = query_guild(); + guild.done(function(guildobj) { + fill_channels(guildobj.channels); + fill_discord_members(guildobj.discordmembers); + fill_authenticated_users(guildobj.embedmembers.authenticated); + fill_unauthenticated_users(guildobj.embedmembers.unauthenticated); + setTimeout(run_fetch_routine, 10000); + }); + }); + fet.fail(function(data) { + if (data.status == 403) { + $('#loginmodal').modal('open'); + Materialize.toast('Authentication error! You have been banned.', 10000); + } + if (data.status == 401) { + $('#loginmodal').modal('open'); + Materialize.toast('Session expired! You have been logged out.', 10000); + } + setTimeout(run_fetch_routine, 10000); + }); +} + $("#discordlogin_btn").click(function() { lock_login_fields(); wait_for_discord_login();