dsffds
This commit is contained in:
parent
ea91371c04
commit
f74123ad39
1 changed files with 29 additions and 34 deletions
|
@ -6,31 +6,37 @@ from .markdown import *
|
||||||
from .sanitize import *
|
from .sanitize import *
|
||||||
from .const import *
|
from .const import *
|
||||||
|
|
||||||
def send_repeatable_notification(uid, text, autojanny=False):
|
def create_comment(text, autojanny=False):
|
||||||
|
|
||||||
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
|
||||||
|
|
||||||
if autojanny: author_id = AUTOJANNY_ID
|
if autojanny: author_id = AUTOJANNY_ID
|
||||||
else: author_id = NOTIFICATIONS_ID
|
else: author_id = NOTIFICATIONS_ID
|
||||||
|
|
||||||
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
|
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
||||||
if existing:
|
|
||||||
existing2 = g.db.query(Notification.id).filter_by(user_id=uid, comment_id=existing[0]).first()
|
|
||||||
if existing2:
|
|
||||||
text_html = sanitize(CustomRenderer().render(mistletoe.Document(text)))
|
text_html = sanitize(CustomRenderer().render(mistletoe.Document(text)))
|
||||||
new_comment = Comment(author_id=author_id,
|
new_comment = Comment(author_id=author_id,
|
||||||
parent_submission=None,
|
parent_submission=None,
|
||||||
distinguish_level=6,
|
distinguish_level=6,
|
||||||
body=text,
|
body=text,
|
||||||
body_html=text_html,
|
created_utc=0,
|
||||||
created_utc=0)
|
body_html=text_html)
|
||||||
g.db.add(new_comment)
|
g.db.add(new_comment)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
notif = Notification(comment_id=new_comment.id, user_id=uid)
|
return new_comment.id
|
||||||
g.db.add(notif)
|
|
||||||
return
|
|
||||||
|
|
||||||
send_notification(uid, text, autojanny)
|
def send_repeatable_notification(uid, text, autojanny=False):
|
||||||
|
|
||||||
|
if autojanny: author_id = AUTOJANNY_ID
|
||||||
|
else: author_id = NOTIFICATIONS_ID
|
||||||
|
|
||||||
|
existing_comment = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
|
||||||
|
|
||||||
|
if existing_comment:
|
||||||
|
cid = existing_comment[0]
|
||||||
|
existing_notif = g.db.query(Notification.id).filter_by(user_id=uid, comment_id=cid).first()
|
||||||
|
if existing_notif: cid = create_comment(text, autojanny)
|
||||||
|
else: cid = create_comment(text, autojanny)
|
||||||
|
|
||||||
|
notif = Notification(comment_id=cid, user_id=uid)
|
||||||
|
g.db.add(notif)
|
||||||
|
|
||||||
|
|
||||||
def send_notification(uid, text, autojanny=False):
|
def send_notification(uid, text, autojanny=False):
|
||||||
|
@ -41,27 +47,14 @@ def send_notification(uid, text, autojanny=False):
|
||||||
|
|
||||||
def notif_comment(text, autojanny=False):
|
def notif_comment(text, autojanny=False):
|
||||||
|
|
||||||
text = text.replace('r/', 'r\/').replace('u/', 'u\/')
|
|
||||||
|
|
||||||
if autojanny: author_id = AUTOJANNY_ID
|
if autojanny: author_id = AUTOJANNY_ID
|
||||||
else: author_id = NOTIFICATIONS_ID
|
else: author_id = NOTIFICATIONS_ID
|
||||||
|
|
||||||
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
|
existing = g.db.query(Comment.id).filter_by(author_id=author_id, parent_submission=None, distinguish_level=6, body=text, created_utc=0).first()
|
||||||
|
|
||||||
if existing: cid = existing[0]
|
if existing: return existing[0]
|
||||||
else:
|
else: return create_comment(text, autojanny)
|
||||||
text_html = sanitize(CustomRenderer().render(mistletoe.Document(text)))
|
|
||||||
new_comment = Comment(author_id=author_id,
|
|
||||||
parent_submission=None,
|
|
||||||
distinguish_level=6,
|
|
||||||
body=text,
|
|
||||||
body_html=text_html,
|
|
||||||
created_utc=0)
|
|
||||||
g.db.add(new_comment)
|
|
||||||
g.db.flush()
|
|
||||||
cid = new_comment.id
|
|
||||||
|
|
||||||
return cid
|
|
||||||
|
|
||||||
def add_notif(cid, uid):
|
def add_notif(cid, uid):
|
||||||
existing = g.db.query(Notification.id).filter_by(comment_id=cid, user_id=uid).first()
|
existing = g.db.query(Notification.id).filter_by(comment_id=cid, user_id=uid).first()
|
||||||
|
@ -69,6 +62,7 @@ def add_notif(cid, uid):
|
||||||
notif = Notification(comment_id=cid, user_id=uid)
|
notif = Notification(comment_id=cid, user_id=uid)
|
||||||
g.db.add(notif)
|
g.db.add(notif)
|
||||||
|
|
||||||
|
|
||||||
def send_admin(vid, text):
|
def send_admin(vid, text):
|
||||||
|
|
||||||
text_html = Renderer().render(mistletoe.Document(text))
|
text_html = Renderer().render(mistletoe.Document(text))
|
||||||
|
@ -89,6 +83,7 @@ def send_admin(vid, text):
|
||||||
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
|
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
|
||||||
g.db.add(notif)
|
g.db.add(notif)
|
||||||
|
|
||||||
|
|
||||||
def NOTIFY_USERS(text, vid):
|
def NOTIFY_USERS(text, vid):
|
||||||
text = text.lower()
|
text = text.lower()
|
||||||
notify_users = set()
|
notify_users = set()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue