Automatically fetching data with the server

This commit is contained in:
Jeremy Zhang 2017-04-04 06:18:28 +00:00
parent 8a441720a0
commit 9527ef53e5
2 changed files with 30 additions and 1 deletions

View File

@ -20,7 +20,6 @@ def get_logingreeting():
@embed.route("/<string:guild_id>")
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",

View File

@ -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();