diff --git a/files/routes/admin.py b/files/routes/admin.py index 95b8b53ba..7ec34f5a8 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -989,6 +989,9 @@ def admin_change_flair(user_id, v): @admin_level_required(PERMS['USER_BAN']) def ban_user(fullname, v): + post = None + comment = None + if fullname.startswith('p_'): post_id = fullname.split('p_')[1] post = g.db.get(Post, post_id) @@ -1062,21 +1065,14 @@ def ban_user(fullname, v): if 'reason' in request.values: reason = request.values["reason"] - if reason.startswith("/post/"): - try: post_id = int(reason.split("/post/")[1].split(None, 1)[0]) - except: abort(400) - actual_reason = reason.split(str(post_id))[1].strip() - post = get_post(post_id) - if post.hole != 'chudrama': - post.bannedfor = f'{duration} by @{v.username}' - if actual_reason: - post.bannedfor += f' for "{actual_reason}"' + if post: + actual_reason = reason.replace(f'/post/{post.id}', '').strip() + post.bannedfor = f'{duration} by @{v.username}' + if actual_reason: + post.bannedfor += f' for "{actual_reason}"' g.db.add(post) - elif reason.startswith("/comment/"): - try: comment_id = int(reason.split("/comment/")[1].split(None, 1)[0]) - except: abort(400) - actual_reason = reason.split(str(comment_id))[1].strip() - comment = get_comment(comment_id) + elif comment: + actual_reason = reason.replace(f'/comment/{comment.id}', '').strip() comment.bannedfor = f'{duration} by @{v.username}' if actual_reason: comment.bannedfor += f' for "{actual_reason}"'