From 13e9649c100e9443ede853eb607c4ea205b6cae8 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 5 Apr 2017 18:43:59 +0000 Subject: [PATCH] Fixes for authenticated discord user check and other small fixes --- titanembeds/blueprints/api/api.py | 3 ++- titanembeds/static/js/embed.js | 19 ++++++++++++------- titanembeds/utils.py | 7 ++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/titanembeds/blueprints/api/api.py b/titanembeds/blueprints/api/api.py index dd87d19..b46cbc9 100644 --- a/titanembeds/blueprints/api/api.py +++ b/titanembeds/blueprints/api/api.py @@ -93,7 +93,8 @@ def check_user_in_guild(guild_id): if user_unauthenticated(): return guild_id in session['user_keys'] else: - return 200 == discord_api.get_guild_member_nocache(guild_id, session['user_id'])['code'] + dbUser = db.session.query(AuthenticatedUsers).filter(and_(AuthenticatedUsers.guild_id == guild_id, AuthenticatedUsers.client_id == session['user_id'])).first() + return 200 == discord_api.get_guild_member_nocache(guild_id, session['user_id'])['code'] and dbUser is not None def format_post_content(message): if (session['unauthenticated']): diff --git a/titanembeds/static/js/embed.js b/titanembeds/static/js/embed.js index eec5768..0bf036f 100644 --- a/titanembeds/static/js/embed.js +++ b/titanembeds/static/js/embed.js @@ -204,12 +204,14 @@ function _wait_for_discord_login(index) { } function select_channel(channel_id) { - selected_channel = channel_id; - last_message_id = null; - $("#channels-list > li.active").removeClass("active"); - $("#channel-"+selected_channel).parent().addClass("active"); - clearTimeout(fetchtimeout); - run_fetch_routine(); + if (selected_channel != channel_id) { + selected_channel = channel_id; + last_message_id = null; + $("#channels-list > li.active").removeClass("active"); + $("#channel-"+selected_channel).parent().addClass("active"); + clearTimeout(fetchtimeout); + run_fetch_routine(); + } } function replace_message_mentions(message) { @@ -332,8 +334,11 @@ $("#custom_username_field").keyup(function(event){ }); $("#messagebox").keyup(function(event){ - $(this).val($.trim($(this).val())); + if ($(this).val().length == 1) { + $(this).val($.trim($(this).val())); + } if(event.keyCode == 13 && $(this).val().length >= 1 && $(this).val().length <= 350) { + $(this).val($.trim($(this).val())); $(this).blur(); var funct = post(selected_channel, $(this).val()); funct.done(function(data) { diff --git a/titanembeds/utils.py b/titanembeds/utils.py index 6f285df..f053010 100644 --- a/titanembeds/utils.py +++ b/titanembeds/utils.py @@ -56,11 +56,8 @@ def check_guild_existance(guild_id): dbGuild = Guilds.query.filter_by(guild_id=guild_id).first() if not dbGuild: return False - guilds = discord_api.get_all_guilds() - for guild in guilds: - if guild_id == guild['id']: - return True - return False + guild = discord_api.get_guild(guild_id) + return guild['code'] == 200 def guild_query_unauth_users_bool(guild_id): dbGuild = db.session.query(Guilds).filter(Guilds.guild_id==guild_id).first()