forked from rDrama/rDrama
OPs can now rehole their posts
parent
faa4f993f2
commit
35e2e12e24
|
@ -164,4 +164,24 @@ if PUSHER_ID != 'blahblahblah':
|
|||
}
|
||||
},
|
||||
)
|
||||
stdout.flush()
|
||||
stdout.flush()
|
||||
|
||||
|
||||
|
||||
def on_post_hole_entered(post, v=None):
|
||||
if not post.sub or not post.subr:
|
||||
return
|
||||
hole = post.subr.name
|
||||
author = post.author
|
||||
|
||||
# Notify hole followers
|
||||
if not post.ghost and not post.private and not author.shadowbanned:
|
||||
text = f"<a href='/h/{hole}'>/h/{hole}</a> has a new " \
|
||||
+ f"post: [{post.title}]({post.shortlink}) by @{author.username}"
|
||||
cid = notif_comment(text, autojanny=True)
|
||||
for follow in post.subr.followers:
|
||||
if follow.user_id == author.id or (v and follow.user_id == v.id):
|
||||
continue
|
||||
user = get_account(follow.user_id)
|
||||
if post.club and not user.paid_dues: continue
|
||||
add_notif(cid, user.id)
|
|
@ -10,7 +10,6 @@ from files.helpers.regex import *
|
|||
from files.helpers.slots import *
|
||||
from files.helpers.get import *
|
||||
from files.classes import *
|
||||
from files.routes.subs import on_post_hole_entered
|
||||
from flask import *
|
||||
from io import BytesIO
|
||||
from files.__main__ import app, limiter, cache, db_session
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from files.helpers.wrappers import *
|
||||
from files.helpers.get import *
|
||||
from files.helpers.alerts import *
|
||||
from flask import g
|
||||
from files.__main__ import app, limiter
|
||||
from os import path
|
||||
from files.helpers.sanitize import filter_emojis_only
|
||||
from files.routes.subs import rehole_post
|
||||
|
||||
@app.post("/report/post/<pid>")
|
||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||
|
@ -40,8 +40,33 @@ def api_flag_post(pid, v):
|
|||
_note=f'"{post.flair}"'
|
||||
)
|
||||
g.db.add(ma)
|
||||
elif reason.startswith('/h/') and v.admin_level >= 2:
|
||||
rehole_post(pid=post.id, hole=reason[3:])
|
||||
elif reason.startswith('/h/') and v.admin_level >= 2 or v.id == post.author_id:
|
||||
|
||||
sub_from = post.sub
|
||||
sub_to = reason[3:].strip().lower()
|
||||
sub_to = g.db.query(Sub).filter_by(name=sub_to).one_or_none()
|
||||
sub_to = sub_to.name if sub_to else None
|
||||
|
||||
if sub_from == sub_to: abort(400)
|
||||
post.sub = sub_to
|
||||
g.db.add(post)
|
||||
|
||||
if v.admin_level and v.id != post.author_id:
|
||||
sub_from_str = 'frontpage' if sub_from is None else \
|
||||
f'<a href="/h/{sub_from}">/h/{sub_from}</a>'
|
||||
sub_to_str = 'frontpage' if sub_to is None else \
|
||||
f'<a href="/h/{sub_to}">/h/{sub_to}</a>'
|
||||
ma = ModAction(
|
||||
kind='move_hole',
|
||||
user_id=v.id,
|
||||
target_submission_id=post.id,
|
||||
_note=f'{sub_from_str} → {sub_to_str}',
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
on_post_hole_entered(post, v)
|
||||
|
||||
return {"message": f"Post moved to /h/{post.sub}"}
|
||||
else:
|
||||
flag = Flag(post_id=post.id, user_id=v.id, reason=reason)
|
||||
g.db.add(flag)
|
||||
|
|
|
@ -315,56 +315,6 @@ def kick(v, pid):
|
|||
|
||||
return {"message": "Post kicked successfully!"}
|
||||
|
||||
@app.post("/rehole/<pid>", defaults={'hole': ''})
|
||||
@app.post("/rehole/<pid>/<hole>")
|
||||
@admin_level_required(2)
|
||||
def rehole_post(v, pid, hole):
|
||||
post = get_post(pid)
|
||||
|
||||
sub_from = post.sub
|
||||
sub_to = hole.strip().lower()
|
||||
sub_to = g.db.query(Sub).filter_by(name=sub_to).one_or_none()
|
||||
sub_to = sub_to.name if sub_to else None
|
||||
|
||||
if sub_from == sub_to:
|
||||
abort(400)
|
||||
post.sub = sub_to
|
||||
g.db.add(post)
|
||||
|
||||
sub_from_str = 'frontpage' if sub_from is None else \
|
||||
f'<a href="/h/{sub_from}">/h/{sub_from}</a>'
|
||||
sub_to_str = 'frontpage' if sub_to is None else \
|
||||
f'<a href="/h/{sub_to}">/h/{sub_to}</a>'
|
||||
ma = ModAction(
|
||||
kind='move_hole',
|
||||
user_id=v.id,
|
||||
target_submission_id=post.id,
|
||||
_note=f'{sub_from_str} → {sub_to_str}',
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
on_post_hole_entered(post, v)
|
||||
|
||||
return {"message": f"Post moved to {sub_to_str}!"}
|
||||
|
||||
def on_post_hole_entered(post, v=None):
|
||||
if not post.sub or not post.subr:
|
||||
return
|
||||
hole = post.subr.name
|
||||
author = post.author
|
||||
|
||||
# Notify hole followers
|
||||
if not post.ghost and not post.private and not author.shadowbanned:
|
||||
text = f"<a href='/h/{hole}'>/h/{hole}</a> has a new " \
|
||||
+ f"post: [{post.title}]({post.shortlink}) by @{author.username}"
|
||||
cid = notif_comment(text, autojanny=True)
|
||||
for follow in post.subr.followers:
|
||||
if follow.user_id == author.id or (v and follow.user_id == v.id):
|
||||
continue
|
||||
user = get_account(follow.user_id)
|
||||
if post.club and not user.paid_dues: continue
|
||||
add_notif(cid, user.id)
|
||||
|
||||
@app.get('/h/<sub>/settings')
|
||||
@is_not_permabanned
|
||||
def sub_settings(v, sub):
|
||||
|
|
Loading…
Reference in New Issue