diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index 6bd5672a8..4930c5301 100644 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -9,6 +9,11 @@ import user_agents import time def calc_users(v): + # Some globals we expect aren't available when rendering error pages + if (not g or not hasattr(g, 'agent') + or not session or not ('session_id' in session)): + return '' + loggedin = cache.get(f'{SITE}_loggedin') or {} loggedout = cache.get(f'{SITE}_loggedout') or {} timestamp = int(time.time()) diff --git a/files/routes/comments.py b/files/routes/comments.py index 0efbd291f..4465b82ee 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -255,7 +255,9 @@ def comment(v): if parent.author.any_block_exists(v) and v.admin_level < PERMS['POST_COMMENT_MODERATION']: abort(403, "You can't reply to users who have blocked you or users that you have blocked.") - is_bot = v.id != BBBB_ID and v.client or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID) + is_bot = (v.client is not None + and v.id != BBBB_ID + or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID)) execute_antispam_comment_check(body, v) diff --git a/files/routes/posts.py b/files/routes/posts.py index 15db20131..2f3fdadf0 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -877,8 +877,6 @@ def submit_post(v, sub=None): if embed and len(embed) > 1500: embed = None - is_bot = v.id != BBBB_ID and v.client or (SITE == 'pcmemes.net' and v.id == SNAPPY_ID) - if request.values.get("ghost") and v.coins >= 100: v.charge_account('coins', 100) ghost = True @@ -894,7 +892,7 @@ def submit_post(v, sub=None): over_18=bool(request.values.get("over_18","")), new=bool(request.values.get("new","")), app_id=v.client.application.id if v.client else None, - is_bot = is_bot, + is_bot=(v.client is not None), url=url, body=body, body_html=body_html, diff --git a/files/routes/users.py b/files/routes/users.py index d2e5ec54e..c3869bf1a 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -913,7 +913,7 @@ def u_username_comments(username, v=None): listing = get_comments(ids, v=v) - if v.client or request.path.endswith(".json"): + if (v and v.client) or request.path.endswith(".json"): return {"data": [c.json for c in listing]} return render_template("userpage_comments.html", u=user, v=v, listing=listing, page=page, sort=sort, t=t,next_exists=next_exists, is_following=is_following, standalone=True)