forked from MarseyWorld/MarseyWorld
master
parent
9c13a93afb
commit
c2b1f50099
|
@ -7,7 +7,7 @@ from .sanitize import *
|
|||
from .const import *
|
||||
|
||||
|
||||
def send_notification(vid, user, text, db=None):
|
||||
def send_notification(vid, user, text):
|
||||
|
||||
# for when working outside request context
|
||||
if isinstance(user, int):
|
||||
|
@ -15,9 +15,6 @@ def send_notification(vid, user, text, db=None):
|
|||
else:
|
||||
uid = user.id
|
||||
|
||||
if not db:
|
||||
db = g.db
|
||||
|
||||
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
||||
text = text.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n")
|
||||
text_html = CustomRenderer().render(mistletoe.Document(text))
|
||||
|
@ -28,20 +25,20 @@ def send_notification(vid, user, text, db=None):
|
|||
parent_submission=None,
|
||||
distinguish_level=6,
|
||||
)
|
||||
db.add(new_comment)
|
||||
g.db.add(new_comment)
|
||||
|
||||
db.flush()
|
||||
g.db.flush()
|
||||
|
||||
new_aux = CommentAux(id=new_comment.id,
|
||||
body=text,
|
||||
body_html=text_html,
|
||||
)
|
||||
db.add(new_aux)
|
||||
g.db.add(new_aux)
|
||||
|
||||
notif = Notification(comment_id=new_comment.id,
|
||||
user_id=uid)
|
||||
db.add(notif)
|
||||
db.commit()
|
||||
g.db.add(notif)
|
||||
g.db.commit()
|
||||
|
||||
|
||||
def send_follow_notif(vid, user, text):
|
||||
|
|
|
@ -92,15 +92,14 @@ def check_ban_evade(v):
|
|||
g.db.add(ma)
|
||||
except: pass
|
||||
|
||||
g.db.flush()
|
||||
try: abort(403)
|
||||
except Exception as e: print(e)
|
||||
|
||||
else:
|
||||
v.ban_evade +=1
|
||||
g.db.add(v)
|
||||
g.db.flush()
|
||||
|
||||
g.db.commit()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -96,5 +96,6 @@ def activate(v):
|
|||
g.db.add(mail_badge)
|
||||
|
||||
g.db.add(user)
|
||||
g.db.commit()
|
||||
|
||||
return render_template("message_success.html", v=v, title="Email verified.", message=f"Your email {email} has been verified. Thank you.")
|
||||
|
|
|
@ -42,7 +42,7 @@ def revert_actions(v, username):
|
|||
for user in users:
|
||||
user.unban()
|
||||
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
return {"message": "Admin actions reverted!"}
|
||||
|
||||
@app.post("/@<username>/club_allow")
|
||||
|
@ -97,7 +97,7 @@ def make_admin(v, username):
|
|||
if not user: abort(404)
|
||||
user.admin_level = 6
|
||||
g.db.add(user)
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
return {"message": "User has been made admin!"}
|
||||
|
||||
|
||||
|
@ -109,7 +109,7 @@ def remove_admin(v, username):
|
|||
if not user: abort(404)
|
||||
user.admin_level = 0
|
||||
g.db.add(user)
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
return {"message": "Admin removed!"}
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ def make_fake_admin(v, username):
|
|||
if not user: abort(404)
|
||||
user.admin_level = 1
|
||||
g.db.add(user)
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
return {"message": "User has been made fake admin!"}
|
||||
|
||||
|
||||
|
@ -133,7 +133,7 @@ def remove_fake_admin(v, username):
|
|||
if not user: abort(404)
|
||||
user.admin_level = 0
|
||||
g.db.add(user)
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
return {"message": "Fake admin removed!"}
|
||||
|
||||
|
||||
|
@ -436,7 +436,7 @@ def badge_grant_post(v):
|
|||
|
||||
g.db.add(user)
|
||||
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
return redirect("/admin/badge_grant")
|
||||
|
||||
|
||||
|
@ -720,7 +720,6 @@ def agendaposter(user_id, v):
|
|||
note = note
|
||||
)
|
||||
g.db.add(ma)
|
||||
g.db.flush()
|
||||
|
||||
if user.agendaposter:
|
||||
if not user.has_badge(26):
|
||||
|
@ -891,8 +890,6 @@ def ban_user(user_id, v):
|
|||
)
|
||||
g.db.add(ma)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
if 'reason' in request.args:
|
||||
if reason.startswith("/post/"):
|
||||
post = reason.split("/post/")[1].split("/")[0]
|
||||
|
@ -904,8 +901,11 @@ def ban_user(user_id, v):
|
|||
comment = get_comment(comment)
|
||||
comment.bannedfor = True
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
return {"message": f"@{user.username} was banned!"}
|
||||
else: return redirect(user.url)
|
||||
else:
|
||||
g.db.commit()
|
||||
return redirect(user.url)
|
||||
|
||||
|
||||
@app.post("/unban_user/<user_id>")
|
||||
|
@ -937,10 +937,8 @@ def unban_user(user_id, v):
|
|||
|
||||
g.db.commit()
|
||||
|
||||
if "@" in request.referrer:
|
||||
return redirect(user.url)
|
||||
else:
|
||||
return {"message": f"@{user.username} was unbanned!"}
|
||||
if "@" in request.referrer: return redirect(user.url)
|
||||
else: return {"message": f"@{user.username} was unbanned!"}
|
||||
|
||||
@app.post("/ban_post/<post_id>")
|
||||
@admin_level_required(3)
|
||||
|
|
|
@ -252,8 +252,7 @@ def award_post(pid, v):
|
|||
|
||||
send_notification(NOTIFICATIONS_ACCOUNT, post.author, msg)
|
||||
|
||||
if kind in ACTIONS:
|
||||
ACTIONS[kind](post=post)
|
||||
if kind in ACTIONS: ACTIONS[kind](post=post)
|
||||
|
||||
post.author.received_award_count += 1
|
||||
g.db.add(post.author)
|
||||
|
|
|
@ -130,12 +130,11 @@ def admin_app_revoke(v, aid):
|
|||
if app.id:
|
||||
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
||||
|
||||
g.db.flush()
|
||||
send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been revoked.")
|
||||
|
||||
g.db.delete(app)
|
||||
|
||||
g.db.commit()
|
||||
g.db.commit()
|
||||
|
||||
return {"message": f"App revoked"}
|
||||
|
||||
|
@ -149,7 +148,6 @@ def admin_app_reject(v, aid):
|
|||
|
||||
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
|
||||
|
||||
g.db.flush()
|
||||
send_notification(NOTIFICATIONS_ACCOUNT, app.author, f"Your application `{app.app_name}` has been rejected.")
|
||||
|
||||
g.db.delete(app)
|
||||
|
|
|
@ -448,7 +448,7 @@ def filter_title(title):
|
|||
IMGUR_KEY = environ.get("IMGUR_KEY", "").strip()
|
||||
|
||||
|
||||
def check_processing_thread(v, post, link, db):
|
||||
def check_processing_thread(v, post, link):
|
||||
|
||||
image_id = link.split('/')[-1].rstrip('.mp4')
|
||||
headers = {"Authorization": f"Client-ID {IMGUR_KEY}"}
|
||||
|
@ -463,16 +463,15 @@ def check_processing_thread(v, post, link, db):
|
|||
status = req.json()['data']['processing']['status']
|
||||
if status == 'completed':
|
||||
post.processing = False
|
||||
db.add(post)
|
||||
g.db.add(post)
|
||||
|
||||
send_notification(
|
||||
NOTIFICATIONS_ACCOUNT,
|
||||
v,
|
||||
f"Your video has finished processing and your [post](/post/{post.id}) is now live.",
|
||||
db=db
|
||||
f"Your video has finished processing and your [post](/post/{post.id}) is now live."
|
||||
)
|
||||
|
||||
db.commit()
|
||||
g.db.commit()
|
||||
break
|
||||
# just in case
|
||||
elif status == 'failed':
|
||||
|
@ -933,7 +932,7 @@ def submit_post(v):
|
|||
post_url += 'mp4'
|
||||
new_post.url = post_url
|
||||
new_post.processing = True
|
||||
gevent.spawn(check_processing_thread, v.id, new_post, post_url, g.db)
|
||||
gevent.spawn(check_processing_thread, v.id, new_post, post_url)
|
||||
except UploadException as e:
|
||||
if request.headers.get("Authorization"):
|
||||
return {
|
||||
|
@ -1211,8 +1210,8 @@ def unsave_post(pid, v):
|
|||
|
||||
save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
|
||||
|
||||
if save: g.db.delete(save)
|
||||
|
||||
g.db.commit()
|
||||
if save:
|
||||
g.db.delete(save)
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "Post unsaved!"}
|
||||
|
|
|
@ -131,11 +131,12 @@ def transfer_coins(v, username):
|
|||
receiver.coins += amount
|
||||
g.db.add(receiver)
|
||||
g.db.add(v)
|
||||
g.db.commit()
|
||||
|
||||
transfer_message = f"🤑 [@{v.username}]({v.url}) has gifted you {amount} {app.config['COINS_NAME']}!"
|
||||
send_notification(NOTIFICATIONS_ACCOUNT, receiver, transfer_message)
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return {"message": f"{app.config['COINS_NAME']} transferred!"}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue