forked from rDrama/rDrama
1
0
Fork 0

Merge pull request #51 from Aevann1/yolo2

Yolo2
master
Aevann1 2021-09-24 04:54:54 +02:00 committed by GitHub
commit ecefa7e292
6 changed files with 233 additions and 311 deletions

View File

@ -12,23 +12,12 @@ import time
site = environ.get("DOMAIN").strip() site = environ.get("DOMAIN").strip()
class CommentAux(Base):
__tablename__ = "comments_aux"
key_id = Column(Integer, primary_key=True)
id = Column(Integer, ForeignKey("comments.id"))
body = deferred(Column(String(10000)))
body_html = deferred(Column(String(20000)))
ban_reason = Column(String(256))
class Comment(Base): class Comment(Base):
__tablename__ = "comments" __tablename__ = "comments"
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
comment_aux = relationship("CommentAux", lazy="joined", uselist=False, innerjoin=True, primaryjoin="Comment.id==CommentAux.id")
author_id = Column(Integer, ForeignKey("users.id")) author_id = Column(Integer, ForeignKey("users.id"))
parent_submission = Column(Integer, ForeignKey("submissions.id")) parent_submission = Column(Integer, ForeignKey("submissions.id"))
created_utc = Column(Integer, default=0) created_utc = Column(Integer, default=0)
@ -41,25 +30,23 @@ class Comment(Base):
is_approved = Column(Integer, default=0) is_approved = Column(Integer, default=0)
level = Column(Integer, default=0) level = Column(Integer, default=0)
parent_comment_id = Column(Integer, ForeignKey("comments.id")) parent_comment_id = Column(Integer, ForeignKey("comments.id"))
over_18 = Column(Boolean, default=False) over_18 = Column(Boolean, default=False)
is_bot = Column(Boolean, default=False) is_bot = Column(Boolean, default=False)
is_pinned = Column(String) is_pinned = Column(String)
sentto=Column(Integer) sentto=Column(Integer)
app_id = Column(Integer, ForeignKey("oauth_apps.id")) app_id = Column(Integer, ForeignKey("oauth_apps.id"))
oauth_app = relationship("OauthApp", viewonly=True) oauth_app = relationship("OauthApp", viewonly=True)
upvotes = Column(Integer, default=1)
downvotes = Column(Integer, default=0)
body = deferred(Column(String(10000)))
body_html = deferred(Column(String(20000)))
ban_reason = Column(String(256))
post = relationship("Submission", viewonly=True) post = relationship("Submission", viewonly=True)
flags = relationship("CommentFlag", lazy="dynamic", viewonly=True) flags = relationship("CommentFlag", lazy="dynamic", viewonly=True)
author = relationship("User", primaryjoin="User.id==Comment.author_id") author = relationship("User", primaryjoin="User.id==Comment.author_id")
upvotes = Column(Integer, default=1)
downvotes = Column(Integer, default=0)
parent_comment = relationship("Comment", remote_side=[id], viewonly=True) parent_comment = relationship("Comment", remote_side=[id], viewonly=True)
child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True) child_comments = relationship("Comment", remote_side=[parent_comment_id], viewonly=True)
awards = relationship("AwardRelationship", viewonly=True) awards = relationship("AwardRelationship", viewonly=True)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -291,25 +278,6 @@ class Comment(Base):
return data return data
@property
def body(self):
if self.comment_aux: return self.comment_aux.body
else: return ""
@body.setter
def body(self, x):
self.comment_aux.body = x
g.db.add(self.comment_aux)
@property
def body_html(self):
return self.comment_aux.body_html
@body_html.setter
def body_html(self, x):
self.comment_aux.body_html = x
g.db.add(self.comment_aux)
def realbody(self, v): def realbody(self, v):
if self.post and self.post.club and not (v and v.paid_dues): return "<p>COUNTRY CLUB ONLY</p>" if self.post and self.post.club and not (v and v.paid_dues): return "<p>COUNTRY CLUB ONLY</p>"
body = self.body_html body = self.body_html
@ -335,15 +303,6 @@ class Comment(Base):
return body return body
@property
def ban_reason(self):
return self.comment_aux.ban_reason
@ban_reason.setter
def ban_reason(self, x):
self.comment_aux.ban_reason = x
g.db.add(self.comment_aux)
@lazy @lazy
def collapse_for_user(self, v): def collapse_for_user(self, v):

View File

@ -21,19 +21,15 @@ def send_notification(vid, user, text):
text_html = sanitize(text_html) text_html = sanitize(text_html)
new_comment = Comment(author_id=vid, new_comment = Comment(author_id=vid,
parent_submission=None, parent_submission=None,
distinguish_level=6, distinguish_level=6,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id,
body=text,
body_html=text_html,
)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, notif = Notification(comment_id=new_comment.id,
user_id=uid) user_id=uid)
g.db.add(notif) g.db.add(notif)
@ -45,18 +41,14 @@ def send_follow_notif(vid, user, text):
text_html = sanitize(text_html) text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT, new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT,
parent_submission=None, parent_submission=None,
distinguish_level=6, distinguish_level=6,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id,
body=text,
body_html=text_html,
)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, notif = Notification(comment_id=new_comment.id,
user_id=user, user_id=user,
followsender=vid) followsender=vid)
@ -68,18 +60,14 @@ def send_unfollow_notif(vid, user, text):
text_html = sanitize(text_html) text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT, new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT,
parent_submission=None, parent_submission=None,
distinguish_level=6, distinguish_level=6,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id,
body=text,
body_html=text_html,
)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, notif = Notification(comment_id=new_comment.id,
user_id=user, user_id=user,
unfollowsender=vid) unfollowsender=vid)
@ -91,18 +79,14 @@ def send_block_notif(vid, user, text):
text_html = sanitize(text_html) text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT, new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT,
parent_submission=None, parent_submission=None,
distinguish_level=6, distinguish_level=6,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id,
body=text,
body_html=text_html,
)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, notif = Notification(comment_id=new_comment.id,
user_id=user, user_id=user,
blocksender=vid) blocksender=vid)
@ -114,18 +98,14 @@ def send_unblock_notif(vid, user, text):
text_html = sanitize(text_html) text_html = sanitize(text_html)
new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT, new_comment = Comment(author_id=NOTIFICATIONS_ACCOUNT,
parent_submission=None, parent_submission=None,
distinguish_level=6, distinguish_level=6,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id,
body=text,
body_html=text_html,
)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, notif = Notification(comment_id=new_comment.id,
user_id=user, user_id=user,
unblocksender=vid) unblocksender=vid)
@ -144,12 +124,12 @@ def send_admin(vid, text):
new_comment = Comment(author_id=vid, new_comment = Comment(author_id=vid,
parent_submission=None, parent_submission=None,
level=1, level=1,
sentto=0 sentto=0,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html)
g.db.add(new_aux)
admins = g.db.query(User).options(lazyload('*')).filter(User.admin_level > 0).all() admins = g.db.query(User).options(lazyload('*')).filter(User.admin_level > 0).all()
for admin in admins: for admin in admins:

View File

@ -178,11 +178,11 @@ def api_comment(v):
return {"error": reason}, 401 return {"error": reason}, 401
# check existing # check existing
existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id, existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == v.id,
Comment.deleted_utc == 0, Comment.deleted_utc == 0,
Comment.parent_comment_id == parent_comment_id, Comment.parent_comment_id == parent_comment_id,
Comment.parent_submission == parent_submission, Comment.parent_submission == parent_submission,
CommentAux.body == body Comment.body == body
).first() ).first()
if existing: if existing:
return {"error": f"You already made that comment: {existing.permalink}"}, 409 return {"error": f"You already made that comment: {existing.permalink}"}, 409
@ -201,10 +201,9 @@ def api_comment(v):
similar_comments = g.db.query(Comment similar_comments = g.db.query(Comment
).options( ).options(
lazyload('*') lazyload('*')
).join(Comment.comment_aux ).filter(
).filter(
Comment.author_id == v.id, Comment.author_id == v.id,
CommentAux.body.op( Comment.body.op(
'<->')(body) < app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"], '<->')(body) < app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"],
Comment.created_utc > cutoff Comment.created_utc > cutoff
).all() ).all()
@ -261,17 +260,6 @@ def api_comment(v):
if badlink: return {"error": f"Remove the following link and try again: `{check_url}`. Reason: {badlink.reason}"}, 403 if badlink: return {"error": f"Remove the following link and try again: `{check_url}`. Reason: {badlink.reason}"}, 403
# create comment # create comment
parent_id = parent_fullname.split("_")[1] parent_id = parent_fullname.split("_")[1]
c = Comment(author_id=v.id,
parent_submission=parent_submission,
parent_comment_id=parent_comment_id,
level=level,
over_18=parent_post.over_18 or request.values.get("over_18","")=="true",
is_bot=is_bot,
app_id=v.client.application.id if v.client else None
)
g.db.add(c)
g.db.flush()
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"] file=request.files["file"]
@ -285,29 +273,24 @@ def api_comment(v):
body_html = sanitize(body_md) body_html = sanitize(body_md)
if len(body_html) > 20000: abort(400) if len(body_html) > 20000: abort(400)
c_aux = CommentAux(
id=c.id,
body_html=body_html,
body=body[:10000]
)
g.db.add(c_aux) c = Comment(author_id=v.id,
parent_submission=parent_submission,
parent_comment_id=parent_comment_id,
level=level,
over_18=parent_post.over_18 or request.values.get("over_18","")=="true",
is_bot=is_bot,
app_id=v.client.application.id if v.client else None,
body_html=body_html,
body=body[:10000]
)
g.db.add(c)
g.db.flush() g.db.flush()
if 'pcmemes.net' in request.host and c_aux.body.lower().startswith("based"): if 'pcmemes.net' in request.host and c.body.lower().startswith("based"):
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE) pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)
c_based = Comment(author_id=BASEDBOT_ACCOUNT,
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
)
g.db.add(c_based)
g.db.flush()
if level == 1: basedguy = get_account(c.post.author_id) if level == 1: basedguy = get_account(c.post.author_id)
else: basedguy = get_account(c.parent_comment.author_id) else: basedguy = get_account(c.parent_comment.author_id)
basedguy.basedcount += 1 basedguy.basedcount += 1
@ -319,57 +302,38 @@ def api_comment(v):
body_md = CustomRenderer().render(mistletoe.Document(body2)) body_md = CustomRenderer().render(mistletoe.Document(body2))
body_based_html = sanitize(body_md) body_based_html = sanitize(body_md)
c_aux = CommentAux(
id=c_based.id, c_based = Comment(author_id=BASEDBOT_ACCOUNT,
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_based_html, body_html=body_based_html,
body=body2 body=body2
) )
g.db.add(c_aux)
g.db.add(c_based)
g.db.flush() g.db.flush()
n = Notification(comment_id=c_based.id, user_id=v.id) n = Notification(comment_id=c_based.id, user_id=v.id)
g.db.add(n) g.db.add(n)
if "rdrama" in request.host and "ivermectin" in c_aux.body.lower(): if "rdrama" in request.host and "ivermectin" in c.body.lower():
c.is_banned = True c.is_banned = True
c.ban_reason = "ToS Violation" c.ban_reason = "ToS Violation"
g.db.add(c) g.db.add(c)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
)
g.db.add(c_jannied)
g.db.flush()
body2 = VAXX_MSG.format(username=v.username) body2 = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body2)) body_md = CustomRenderer().render(mistletoe.Document(body2))
body_jannied_html = sanitize(body_md) body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
body_html=body_jannied_html,
body=body2
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n)
if v.agendaposter and "trans lives matter" not in c_aux.body_html.lower():
c.is_banned = True
c.ban_reason = "ToS Violation"
g.db.add(c)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT, c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=parent_submission, parent_submission=parent_submission,
@ -377,23 +341,50 @@ def api_comment(v):
parent_comment_id=c.id, parent_comment_id=c.id,
level=level+1, level=level+1,
is_bot=True, is_bot=True,
body_html=body_jannied_html,
body=body2
) )
g.db.add(c_jannied) g.db.add(c_jannied)
g.db.flush() g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n)
if v.agendaposter and "trans lives matter" not in c.body_html.lower():
c.is_banned = True
c.ban_reason = "ToS Violation"
g.db.add(c)
body = AGENDAPOSTER_MSG.format(username=v.username) body = AGENDAPOSTER_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body)) body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md) body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_jannied_html, body_html=body_jannied_html,
body=body body=body
) )
g.db.add(c_aux)
g.db.add(c_jannied)
g.db.flush() g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)
@ -407,27 +398,28 @@ def api_comment(v):
g.db.add(c) g.db.add(c)
if "rdrama" in request.host and len(body) >= 1000 and v.username != "Snappy" and "</blockquote>" not in body_html: if "rdrama" in request.host and len(body) >= 1000 and v.username != "Snappy" and "</blockquote>" not in body_html:
c2 = Comment(author_id=LONGPOSTBOT_ACCOUNT,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
)
g.db.add(c2)
g.db.flush()
body = random.choice(LONGPOST_REPLIES) body = random.choice(LONGPOST_REPLIES)
body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body) body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body)
body_md = CustomRenderer().render(mistletoe.Document(body)) body_md = CustomRenderer().render(mistletoe.Document(body))
body_html2 = sanitize(body_md) body_html2 = sanitize(body_md)
c_aux = CommentAux(
id=c2.id,
c2 = Comment(author_id=LONGPOSTBOT_ACCOUNT,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_html2, body_html=body_html2,
body=body body=body
) )
g.db.add(c_aux)
g.db.add(c2)
g.db.flush() g.db.flush()
n = Notification(comment_id=c2.id, user_id=v.id) n = Notification(comment_id=c2.id, user_id=v.id)
g.db.add(n) g.db.add(n)
@ -438,80 +430,75 @@ def api_comment(v):
if "rdrama" in request.host and random.random() < 0.001 and v.username != "Snappy" and v.username != "zozbot": if "rdrama" in request.host and random.random() < 0.001 and v.username != "Snappy" and v.username != "zozbot":
body = "zoz"
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html2 = sanitize(body_md)
c2 = Comment(author_id=1833, c2 = Comment(author_id=1833,
parent_submission=parent_submission, parent_submission=parent_submission,
parent_comment_id=c.id, parent_comment_id=c.id,
level=level+1, level=level+1,
is_bot=True, is_bot=True,
body_html=body_html2,
body=body
) )
g.db.add(c2) g.db.add(c2)
g.db.flush() g.db.flush()
body = "zoz"
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html2 = sanitize(body_md)
c_aux = CommentAux(
id=c2.id,
body_html=body_html2,
body=body
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c2.id, user_id=v.id) n = Notification(comment_id=c2.id, user_id=v.id)
g.db.add(n) g.db.add(n)
body = "zle"
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html2 = sanitize(body_md)
c3 = Comment(author_id=1833, c3 = Comment(author_id=1833,
parent_submission=parent_submission, parent_submission=parent_submission,
parent_comment_id=c2.id, parent_comment_id=c2.id,
level=level+2, level=level+2,
is_bot=True, is_bot=True,
body_html=body_html2,
body=body,
) )
g.db.add(c3) g.db.add(c3)
g.db.flush() g.db.flush()
body = "zle" body = "zozzle"
body_md = CustomRenderer().render(mistletoe.Document(body)) body_md = CustomRenderer().render(mistletoe.Document(body))
body_html2 = sanitize(body_md) body_html2 = sanitize(body_md)
c_aux = CommentAux(
id=c3.id,
body_html=body_html2,
body=body
)
g.db.add(c_aux)
g.db.flush()
c4 = Comment(author_id=1833, c4 = Comment(author_id=1833,
parent_submission=parent_submission, parent_submission=parent_submission,
parent_comment_id=c3.id, parent_comment_id=c3.id,
level=level+3, level=level+3,
is_bot=True, is_bot=True,
body_html=body_html2,
body=body
) )
g.db.add(c4) g.db.add(c4)
g.db.flush() g.db.flush()
body = "zozzle"
body_md = CustomRenderer().render(mistletoe.Document(body))
body_html2 = sanitize(body_md)
c_aux = CommentAux(
id=c4.id,
body_html=body_html2,
body=body
)
g.db.add(c_aux)
g.db.flush()
@ -665,10 +652,9 @@ def edit_comment(cid, v):
similar_comments = g.db.query(Comment similar_comments = g.db.query(Comment
).options( ).options(
lazyload('*') lazyload('*')
).join(Comment.comment_aux ).filter(
).filter(
Comment.author_id == v.id, Comment.author_id == v.id,
CommentAux.body.op( Comment.body.op(
'<->')(body) < app.config["SPAM_SIMILARITY_THRESHOLD"], '<->')(body) < app.config["SPAM_SIMILARITY_THRESHOLD"],
Comment.created_utc > cutoff Comment.created_utc > cutoff
).all() ).all()
@ -717,29 +703,29 @@ def edit_comment(cid, v):
g.db.add(c) g.db.add(c)
body = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT, c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=c.parent_submission, parent_submission=c.parent_submission,
distinguish_level=6, distinguish_level=6,
parent_comment_id=c.id, parent_comment_id=c.id,
level=c.level+1, level=c.level+1,
is_bot=True, is_bot=True,
body_html=body_jannied_html,
body=body
) )
g.db.add(c_jannied) g.db.add(c_jannied)
g.db.flush() g.db.flush()
body = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
body_html=body_jannied_html,
body=body
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)
@ -751,29 +737,30 @@ def edit_comment(cid, v):
g.db.add(c) g.db.add(c)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=c.parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=c.level+1,
is_bot=True,
)
g.db.add(c_jannied)
g.db.flush()
body = AGENDAPOSTER_MSG.format(username=v.username) body = AGENDAPOSTER_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body)) body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md) body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=c.parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=c.level+1,
is_bot=True,
body_html=body_jannied_html, body_html=body_jannied_html,
body=body body=body,
) )
g.db.add(c_aux)
g.db.add(c_jannied)
g.db.flush() g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)

View File

@ -287,6 +287,13 @@ def edit_post(pid, v):
g.db.add(p) g.db.add(p)
body = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT, c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=p.id, parent_submission=p.id,
level=1, level=1,
@ -294,24 +301,15 @@ def edit_post(pid, v):
is_bot=True, is_bot=True,
app_id=None, app_id=None,
is_pinned=True, is_pinned=True,
distinguish_level=6 distinguish_level=6,
body_html=body_jannied_html,
body=body
) )
g.db.add(c_jannied) g.db.add(c_jannied)
g.db.flush() g.db.flush()
body = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
body_html=body_jannied_html,
body=body
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)
@ -323,6 +321,12 @@ def edit_post(pid, v):
g.db.add(p) g.db.add(p)
body = AGENDAPOSTER_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT, c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=p.id, parent_submission=p.id,
level=1, level=1,
@ -330,24 +334,14 @@ def edit_post(pid, v):
is_bot=True, is_bot=True,
app_id=None, app_id=None,
is_pinned=True, is_pinned=True,
distinguish_level=6 distinguish_level=6,
body_html=body_jannied_html,
body=body
) )
g.db.add(c_jannied) g.db.add(c_jannied)
g.db.flush() g.db.flush()
body = AGENDAPOSTER_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
body_html=body_jannied_html,
body=body
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)
@ -466,6 +460,10 @@ def thumbnail_thread(pid):
db = db_session() db = db_session()
post = db.query(Submission).filter_by(id=pid).first() post = db.query(Submission).filter_by(id=pid).first()
if not post:
time.sleep(5)
post = db.query(Submission).filter_by(id=pid).first()
fetch_url=post.url fetch_url=post.url
@ -948,6 +946,14 @@ def submit_post(v):
g.db.add(new_post) g.db.add(new_post)
body = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT, c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=new_post.id, parent_submission=new_post.id,
level=1, level=1,
@ -955,24 +961,15 @@ def submit_post(v):
is_bot=True, is_bot=True,
app_id=None, app_id=None,
is_pinned=True, is_pinned=True,
distinguish_level=6 distinguish_level=6,
body_html=body_jannied_html,
body=body,
) )
g.db.add(c_jannied) g.db.add(c_jannied)
g.db.flush() g.db.flush()
body = VAXX_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
body_html=body_jannied_html,
body=body
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)
@ -984,6 +981,14 @@ def submit_post(v):
g.db.add(new_post) g.db.add(new_post)
body = AGENDAPOSTER_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT, c_jannied = Comment(author_id=AUTOJANNY_ACCOUNT,
parent_submission=new_post.id, parent_submission=new_post.id,
level=1, level=1,
@ -991,40 +996,20 @@ def submit_post(v):
is_bot=True, is_bot=True,
app_id=None, app_id=None,
is_pinned=True, is_pinned=True,
distinguish_level=6 distinguish_level=6,
body_html=body_jannied_html,
body=body,
) )
g.db.add(c_jannied) g.db.add(c_jannied)
g.db.flush() g.db.flush()
body = AGENDAPOSTER_MSG.format(username=v.username)
body_md = CustomRenderer().render(mistletoe.Document(body))
body_jannied_html = sanitize(body_md)
c_aux = CommentAux(
id=c_jannied.id,
body_html=body_jannied_html,
body=body
)
g.db.add(c_aux)
g.db.flush()
n = Notification(comment_id=c_jannied.id, user_id=v.id) n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n) g.db.add(n)
if "rdrama" in request.host or (new_post.url and not "weebzone" in request.host and not "marsey.tech" in request.host): if "rdrama" in request.host or (new_post.url and not "weebzone" in request.host and not "marsey.tech" in request.host):
c = Comment(author_id=261,
distinguish_level=6,
parent_submission=new_post.id,
level=1,
over_18=False,
is_bot=True,
app_id=None,
)
g.db.add(c)
g.db.flush()
new_post.comment_count = 1 new_post.comment_count = 1
g.db.add(new_post) g.db.add(new_post)
@ -1043,13 +1028,23 @@ def submit_post(v):
gevent.spawn(archiveorg, new_post.url) gevent.spawn(archiveorg, new_post.url)
body_md = CustomRenderer().render(mistletoe.Document(body)) body_md = CustomRenderer().render(mistletoe.Document(body))
body_html = sanitize(body_md) body_html = sanitize(body_md)
c_aux = CommentAux(
id=c.id,
c = Comment(author_id=261,
distinguish_level=6,
parent_submission=new_post.id,
level=1,
over_18=False,
is_bot=True,
app_id=None,
body_html=body_html, body_html=body_html,
body=body body=body,
) )
g.db.add(c_aux)
g.db.add(c)
g.db.flush() g.db.flush()
n = Notification(comment_id=c.id, user_id=v.id) n = Notification(comment_id=c.id, user_id=v.id)
g.db.add(n) g.db.add(n)
g.db.flush() g.db.flush()

View File

@ -208,11 +208,11 @@ def searchcomments(v):
comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.parent_submission != None).join(Comment.comment_aux) comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.parent_submission != None)
if 'q' in criteria: if 'q' in criteria:
words=criteria['q'].split() words=criteria['q'].split()
words=[CommentAux.body.ilike('%'+x+'%') for x in words] words=[Comment.body.ilike('%'+x+'%') for x in words]
words=tuple(words) words=tuple(words)
comments=comments.filter(*words) comments=comments.filter(*words)

View File

@ -224,9 +224,9 @@ def message2(v, username):
message = request.values.get("message", "")[:1000].strip() message = request.values.get("message", "")[:1000].strip()
# check existing # check existing
existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id, existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == v.id,
Comment.sentto == user.id, Comment.sentto == user.id,
CommentAux.body == message, Comment.body == message,
).first() ).first()
if existing: return redirect('/notifications?messages=true') if existing: return redirect('/notifications?messages=true')
@ -239,14 +239,14 @@ def message2(v, username):
new_comment = Comment(author_id=v.id, new_comment = Comment(author_id=v.id,
parent_submission=None, parent_submission=None,
level=1, level=1,
sentto=user.id sentto=user.id,
body=text,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=text, body_html=text_html)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, user_id=user.id) notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif) g.db.add(notif)
@ -284,9 +284,9 @@ def messagereply(v):
message = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', message) message = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', message)
# check existing # check existing
existing = g.db.query(Comment).join(CommentAux).options(lazyload('*')).filter(Comment.author_id == v.id, existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == v.id,
Comment.sentto == user.id, Comment.sentto == user.id,
CommentAux.body == message, Comment.body == message,
).first() ).first()
if existing: if existing:
if existing.parent_comment_id: return redirect(f'/notifications?messages=true#comment-{existing.parent_comment_id}') if existing.parent_comment_id: return redirect(f'/notifications?messages=true#comment-{existing.parent_comment_id}')
@ -298,12 +298,13 @@ def messagereply(v):
parent_submission=None, parent_submission=None,
parent_comment_id=id, parent_comment_id=id,
level=parent.level + 1, level=parent.level + 1,
sentto=user.id sentto=user.id,
body=message,
body_html=text_html,
) )
g.db.add(new_comment) g.db.add(new_comment)
g.db.flush() g.db.flush()
new_aux = CommentAux(id=new_comment.id, body=message, body_html=text_html)
g.db.add(new_aux)
notif = Notification(comment_id=new_comment.id, user_id=user.id) notif = Notification(comment_id=new_comment.id, user_id=user.id)
g.db.add(notif) g.db.add(notif)