better code + allow reason before link

master
Aevann 2024-05-23 00:02:02 +03:00
parent ff0539780d
commit 157ff82ff9
1 changed files with 10 additions and 14 deletions

View File

@ -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}"'