2022-11-15 09:19:08 +00:00
|
|
|
import os
|
|
|
|
from collections import Counter
|
|
|
|
from shutil import copyfile
|
2023-09-20 15:01:03 +00:00
|
|
|
import random
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
import gevent
|
|
|
|
|
|
|
|
from files.classes import *
|
|
|
|
from files.helpers.actions import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.alerts import *
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.const import *
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.get import *
|
|
|
|
from files.helpers.media import *
|
2022-06-24 14:30:59 +00:00
|
|
|
from files.helpers.regex import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.helpers.slots import *
|
|
|
|
from files.helpers.treasure import *
|
2023-10-05 10:09:58 +00:00
|
|
|
from files.helpers.can_see import *
|
2022-05-04 23:09:46 +00:00
|
|
|
from files.routes.front import comment_idlist
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.routes.routehelpers import execute_shadowban_viewers_and_voters
|
|
|
|
from files.routes.wrappers import *
|
|
|
|
from files.__main__ import app, cache, limiter
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-07-25 21:26:34 +00:00
|
|
|
def _mark_comment_as_read(cid, vid):
|
|
|
|
db = db_session()
|
|
|
|
|
2023-07-26 12:31:44 +00:00
|
|
|
notif = db.query(Notification).options(load_only(Notification.read)).filter_by(comment_id=cid, user_id=vid, read=False).one_or_none()
|
2023-08-01 07:38:58 +00:00
|
|
|
|
2023-07-26 12:31:44 +00:00
|
|
|
if notif and not notif.read:
|
2023-07-25 21:26:34 +00:00
|
|
|
notif.read = True
|
|
|
|
db.add(notif)
|
|
|
|
|
2023-09-08 21:04:39 +00:00
|
|
|
db.commit()
|
2023-07-25 21:26:34 +00:00
|
|
|
db.close()
|
|
|
|
stdout.flush()
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.get("/comment/<int:cid>")
|
|
|
|
@app.get("/post/<int:pid>/<anything>/<int:cid>")
|
2023-10-07 17:55:50 +00:00
|
|
|
@app.get("/h/<hole>/comment/<int:cid>")
|
|
|
|
@app.get("/h/<hole>/post/<int:pid>/<anything>/<int:cid>")
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
2022-08-05 20:40:48 +00:00
|
|
|
@auth_desired_with_logingate
|
2023-10-07 17:55:50 +00:00
|
|
|
def post_pid_comment_cid(cid, v, pid=None, anything=None, hole=None):
|
2022-12-29 10:39:10 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
comment = get_comment(cid, v=v)
|
2022-12-05 14:38:24 +00:00
|
|
|
|
2024-08-11 20:11:04 +00:00
|
|
|
if not can_see(v, comment): stop(403)
|
2023-08-14 19:57:51 +00:00
|
|
|
|
2023-06-23 13:46:42 +00:00
|
|
|
if comment.parent_post:
|
|
|
|
post = comment.parent_post
|
2023-08-14 19:57:24 +00:00
|
|
|
elif comment.wall_user_id:
|
|
|
|
return redirect(f"/id/{comment.wall_user_id}/wall/comment/{comment.id}")
|
2023-01-01 15:44:37 +00:00
|
|
|
else:
|
2023-08-23 10:42:25 +00:00
|
|
|
return redirect(f"/notification/{comment.id}")
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-08-14 19:57:24 +00:00
|
|
|
if v and request.values.get("read"):
|
2023-08-20 16:24:26 +00:00
|
|
|
gevent.spawn(_mark_comment_as_read, comment.id, v.id)
|
2023-08-14 19:57:24 +00:00
|
|
|
|
2023-01-23 02:14:56 +00:00
|
|
|
post = get_post(post, v=v)
|
2023-02-22 17:27:33 +00:00
|
|
|
|
2023-10-05 10:19:50 +00:00
|
|
|
if not (v and v.client) and post.nsfw and not g.show_nsfw:
|
2023-07-27 00:15:50 +00:00
|
|
|
return render_template("errors/nsfw.html", v=v), 403
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-12-18 14:48:48 +00:00
|
|
|
try: context = min(int(request.values.get("context", 8)), 8)
|
|
|
|
except: context = 8
|
2024-02-18 15:55:56 +00:00
|
|
|
focused_comment = comment
|
2022-05-04 23:09:46 +00:00
|
|
|
c = comment
|
|
|
|
|
2022-12-10 17:06:28 +00:00
|
|
|
if post.new: defaultsortingcomments = 'new'
|
|
|
|
elif v: defaultsortingcomments = v.defaultsortingcomments
|
2022-10-11 16:41:09 +00:00
|
|
|
else: defaultsortingcomments = "hot"
|
2023-08-23 21:57:39 +00:00
|
|
|
sort = request.values.get("sort", defaultsortingcomments)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-08-12 19:32:30 +00:00
|
|
|
while context and c.level > 1:
|
|
|
|
parent = c.parent_comment
|
|
|
|
replies = parent.replies(sort)
|
|
|
|
replies.remove(c)
|
|
|
|
parent.replies2 = [c] + replies
|
|
|
|
c = parent
|
|
|
|
context -= 1
|
|
|
|
top_comment = c
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
if v:
|
2022-10-29 00:13:37 +00:00
|
|
|
# this is required because otherwise the vote and block
|
|
|
|
# props won't save properly unless you put them in a list
|
2023-02-27 16:16:12 +00:00
|
|
|
output = get_comments_v_properties(v, None, Comment.top_comment_id == c.top_comment_id)[1]
|
2022-05-04 23:09:46 +00:00
|
|
|
post.replies=[top_comment]
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
execute_shadowban_viewers_and_voters(v, post)
|
|
|
|
execute_shadowban_viewers_and_voters(v, comment)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2023-07-07 18:53:14 +00:00
|
|
|
if v and v.client: return comment.json
|
2023-01-01 11:36:20 +00:00
|
|
|
else:
|
2024-08-06 16:57:52 +00:00
|
|
|
if post.is_banned and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.author_id == v.id)):
|
|
|
|
template = "post_banned.html"
|
|
|
|
else:
|
|
|
|
template = "post.html"
|
2024-02-18 15:55:56 +00:00
|
|
|
return render_template(template, v=v, p=post, sort=sort, focused_comment=focused_comment, render_replies=True, hole=post.hole_obj)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
@app.post("/comment")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2024-07-10 07:36:21 +00:00
|
|
|
@limiter.limit("20/minute;400/hour;1000/day", deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit("20/minute;400/hour;1000/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2024-08-24 23:27:10 +00:00
|
|
|
@auth_required
|
2023-07-30 00:42:06 +00:00
|
|
|
def comment(v):
|
2022-05-04 23:09:46 +00:00
|
|
|
parent_fullname = request.values.get("parent_fullname").strip()
|
2024-08-11 20:11:04 +00:00
|
|
|
if len(parent_fullname) < 3: stop(400)
|
2022-10-30 20:08:20 +00:00
|
|
|
id = parent_fullname[2:]
|
|
|
|
parent_comment_id = None
|
|
|
|
rts = False
|
2022-11-25 20:36:29 +00:00
|
|
|
|
2022-12-09 03:35:28 +00:00
|
|
|
post_target = None
|
|
|
|
parent = None
|
|
|
|
|
2023-05-12 16:54:19 +00:00
|
|
|
notify_op = True
|
|
|
|
|
2022-12-09 03:35:28 +00:00
|
|
|
if parent_fullname.startswith("u_"):
|
|
|
|
parent = get_account(id, v=v)
|
|
|
|
post_target = parent
|
2022-12-19 16:19:33 +00:00
|
|
|
ghost = False
|
2022-12-09 03:35:28 +00:00
|
|
|
elif parent_fullname.startswith("p_"):
|
2022-10-30 20:08:20 +00:00
|
|
|
parent = get_post(id, v=v)
|
2022-12-09 03:35:28 +00:00
|
|
|
post_target = parent
|
2023-03-05 16:44:14 +00:00
|
|
|
if parent.id in ADMIGGER_THREADS and v.admin_level < PERMS['USE_ADMIGGER_THREADS']:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can't post top-level comments in this thread!")
|
2023-03-05 16:44:14 +00:00
|
|
|
|
2022-12-19 16:19:33 +00:00
|
|
|
ghost = parent.ghost
|
2022-10-30 20:08:20 +00:00
|
|
|
elif parent_fullname.startswith("c_"):
|
|
|
|
parent = get_comment(id, v=v)
|
2023-06-23 13:46:42 +00:00
|
|
|
post_target = get_post(parent.parent_post, v=v, graceful=True) or get_account(parent.wall_user_id, v=v, include_blocks=True)
|
2022-10-30 20:08:20 +00:00
|
|
|
parent_comment_id = parent.id
|
|
|
|
if parent.author_id == v.id: rts = True
|
2023-06-07 23:26:32 +00:00
|
|
|
if not v.can_post_in_ghost_threads and isinstance(post_target, Post) and post_target.ghost:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, f"You need {TRUESCORE_MINIMUM} truescore to post in ghost threads")
|
2022-12-19 16:19:33 +00:00
|
|
|
ghost = parent.ghost
|
2024-08-11 20:11:04 +00:00
|
|
|
else: stop(404)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
level = 1 if isinstance(parent, (Post, User)) else int(parent.level) + 1
|
2022-12-09 03:35:28 +00:00
|
|
|
parent_user = parent if isinstance(parent, User) else parent.author
|
2023-06-23 13:46:42 +00:00
|
|
|
posting_to_post = isinstance(post_target, Post)
|
2022-08-21 15:24:16 +00:00
|
|
|
|
2023-10-05 10:09:58 +00:00
|
|
|
if posting_to_post and not can_see(v, parent):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403)
|
2023-08-16 23:23:13 +00:00
|
|
|
|
2023-09-05 18:24:10 +00:00
|
|
|
if posting_to_post:
|
|
|
|
commenters_ping_post_id = post_target.id
|
|
|
|
else:
|
|
|
|
commenters_ping_post_id = None
|
|
|
|
|
2024-08-06 17:33:35 +00:00
|
|
|
if not isinstance(parent, User) and parent.deleted_utc != 0 and v.admin_level < PERMS['POST_COMMENT_MODERATION']:
|
2023-06-07 23:26:32 +00:00
|
|
|
if isinstance(parent, Post):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can't reply to deleted posts!")
|
2022-12-27 03:52:41 +00:00
|
|
|
else:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can't reply to deleted comments!")
|
2022-12-09 03:35:28 +00:00
|
|
|
|
2023-06-23 13:46:42 +00:00
|
|
|
if posting_to_post:
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = post_target.hole
|
2024-08-11 20:11:04 +00:00
|
|
|
if hole and v.exiler_username(hole): stop(403, f"You're exiled from /h/{hole}")
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole in {'furry','vampire','racist','femboy','edgy'} and not v.client and not v.house.lower().startswith(hole):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, f"You need to be a member of House {hole.capitalize()} to comment in /h/{hole}")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-11-10 18:37:01 +00:00
|
|
|
distinguished = request.values.get('distinguished') == 'true' and v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH']
|
|
|
|
|
|
|
|
if v.is_suspended and not (posting_to_post and hole == 'chudrama') and not distinguished:
|
2024-08-24 23:27:10 +00:00
|
|
|
if SITE_NAME == 'rDrama':
|
|
|
|
stop(403, "You can only comment in /h/chudrama when you're tempbanned!")
|
|
|
|
stop(403, "You can't perform this action while banned!")
|
|
|
|
|
2024-08-24 23:12:43 +00:00
|
|
|
if level > COMMENT_MAX_DEPTH:
|
|
|
|
stop(400, f"Max comment level is {COMMENT_MAX_DEPTH}")
|
2022-06-29 01:13:11 +00:00
|
|
|
|
2024-02-14 09:27:00 +00:00
|
|
|
body = request.values.get("body", "").strip()
|
|
|
|
if len(body) > COMMENT_BODY_LENGTH_LIMIT:
|
2024-10-23 15:07:29 +00:00
|
|
|
stop(400, f'Comment body is too long (max {COMMENT_BODY_LENGTH_LIMIT} characters)')
|
2024-02-14 09:27:00 +00:00
|
|
|
|
2024-02-24 23:19:37 +00:00
|
|
|
body = body.replace('@jannies', '!jannies')
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-10-19 05:13:41 +00:00
|
|
|
if not distinguished and not (posting_to_post and post_target.id in ADMIGGER_THREADS):
|
2022-05-04 23:09:46 +00:00
|
|
|
if v.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You have to type more than 280 characters!")
|
2022-05-04 23:09:46 +00:00
|
|
|
elif v.bird and len(body) > 140:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You have to type less than 140 characters!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-09-01 07:51:20 +00:00
|
|
|
if not body and not request.files.get('file'):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(400, "You need to actually write something!")
|
2023-09-01 07:51:20 +00:00
|
|
|
|
2023-09-06 18:02:47 +00:00
|
|
|
if parent_user.has_blocked(v) or parent_user.has_muted(v):
|
2023-09-01 07:51:20 +00:00
|
|
|
notify_op = False
|
2022-11-07 05:24:09 +00:00
|
|
|
|
2024-03-04 23:54:15 +00:00
|
|
|
if posting_to_post and v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and post_target.id == BADGE_THREAD:
|
|
|
|
is_badge_thread = True
|
2024-02-21 21:09:23 +00:00
|
|
|
comment_body = body
|
|
|
|
else:
|
2024-03-04 23:54:15 +00:00
|
|
|
is_badge_thread = False
|
2024-02-21 21:09:23 +00:00
|
|
|
comment_body = None
|
|
|
|
|
2024-03-04 23:54:15 +00:00
|
|
|
body = process_files(request.files, v, body, is_badge_thread=is_badge_thread, comment_body=comment_body)
|
2024-02-14 09:27:00 +00:00
|
|
|
if len(body) > COMMENT_BODY_LENGTH_LIMIT:
|
2024-10-23 15:07:29 +00:00
|
|
|
stop(400, f'Comment body is too long (max {COMMENT_BODY_LENGTH_LIMIT} characters)')
|
2023-07-30 06:16:01 +00:00
|
|
|
|
|
|
|
if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and posting_to_post and post_target.id == SNAPPY_THREAD and level == 1:
|
2024-08-12 17:27:00 +00:00
|
|
|
body = remove_cuniform(body)
|
2024-04-11 07:13:36 +00:00
|
|
|
while '\n\n' in body:
|
|
|
|
body = body.replace('\n\n', '\n')
|
2023-09-14 23:19:44 +00:00
|
|
|
with open(f"snappy_{SITE_NAME}.txt", "r+") as f:
|
2024-02-11 10:17:02 +00:00
|
|
|
body_for_checking = '\n[para]\n' + body.lower() + '\n[para]\n'
|
2024-02-12 18:17:01 +00:00
|
|
|
if body_for_checking in f.read().lower() + '[para]\n':
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(400, "Snappy quote already exists!")
|
2024-02-11 10:17:02 +00:00
|
|
|
f.write('[para]\n' + body + '\n')
|
2023-09-29 06:26:46 +00:00
|
|
|
SNAPPY_QUOTES.append(body)
|
2022-05-22 10:23:02 +00:00
|
|
|
|
2023-09-29 07:15:29 +00:00
|
|
|
is_bot = v.client is not None and v.id not in BOT_SYMBOL_HIDDEN
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
chudded = v.chud and not (posting_to_post and post_target.hole == 'chudrama')
|
2023-09-29 07:15:29 +00:00
|
|
|
|
|
|
|
c = Comment(author_id=v.id,
|
|
|
|
parent_post=post_target.id if posting_to_post else None,
|
|
|
|
wall_user_id=post_target.id if not posting_to_post else None,
|
|
|
|
parent_comment_id=parent_comment_id,
|
|
|
|
level=level,
|
2023-10-05 10:19:50 +00:00
|
|
|
nsfw=post_target.nsfw if posting_to_post else False,
|
2023-09-29 07:15:29 +00:00
|
|
|
is_bot=is_bot,
|
|
|
|
app_id=v.client.application.id if v.client else None,
|
|
|
|
body=body,
|
|
|
|
ghost=ghost,
|
|
|
|
chudded=chudded,
|
|
|
|
rainbowed=bool(v.rainbow),
|
|
|
|
queened=bool(v.queen),
|
|
|
|
sharpened=bool(v.sharpen),
|
2024-10-19 04:32:09 +00:00
|
|
|
distinguished=distinguished,
|
2023-09-29 07:15:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
c.upvotes = 1
|
|
|
|
|
2024-10-22 17:57:23 +00:00
|
|
|
g.db.add(c)
|
2023-10-13 19:04:45 +00:00
|
|
|
body_html = sanitize(body, limit_pings=5, showmore=(not v.hieroglyphs), count_emojis=not v.marsify, commenters_ping_post_id=commenters_ping_post_id, obj=c, author=v)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-07-21 18:53:47 +00:00
|
|
|
if post_target.id not in ADMIGGER_THREADS and not (v.chud and v.chud_phrase.lower() in body.lower()):
|
2023-03-16 06:27:58 +00:00
|
|
|
existing = g.db.query(Comment.id).filter(
|
2022-12-05 01:04:44 +00:00
|
|
|
Comment.author_id == v.id,
|
|
|
|
Comment.deleted_utc == 0,
|
|
|
|
Comment.parent_comment_id == parent_comment_id,
|
2023-06-23 13:46:42 +00:00
|
|
|
Comment.parent_post == post_target.id if posting_to_post else None,
|
|
|
|
Comment.wall_user_id == post_target.id if not posting_to_post else None,
|
2022-12-05 01:04:44 +00:00
|
|
|
Comment.body_html == body_html
|
|
|
|
).first()
|
2024-08-11 20:11:04 +00:00
|
|
|
if existing: stop(409, f"You already made that comment: /comment/{existing.id}#context")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-10-12 05:11:20 +00:00
|
|
|
execute_antispam_comment_check(body, v)
|
2022-11-14 03:48:52 +00:00
|
|
|
execute_antispam_duplicate_comment_check(v, body_html)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-10-19 04:40:55 +00:00
|
|
|
if v.hieroglyphs and not c.distinguished and marseyaward_body_regex.search(body_html) and not (posting_to_post and post_target.id in ADMIGGER_THREADS):
|
2024-08-17 17:51:02 +00:00
|
|
|
stop(403, "You can only type emojis!")
|
2022-12-09 03:35:28 +00:00
|
|
|
|
2023-04-29 13:33:29 +00:00
|
|
|
if len(body_html) > COMMENT_BODY_HTML_LENGTH_LIMIT:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(400, "Rendered comment is too long!")
|
2022-08-15 18:11:41 +00:00
|
|
|
|
2023-09-29 07:15:29 +00:00
|
|
|
c.body_html = body_html
|
2023-06-23 13:14:23 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.flush()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-03-10 18:27:31 +00:00
|
|
|
if not posting_to_post and v.admin_level >= PERMS['ADMIN_NOTES'] and request.values.get('admin_note') == 'true' :
|
2024-03-05 01:16:47 +00:00
|
|
|
c.pinned = "Admin Note"
|
|
|
|
|
|
|
|
if c.parent_comment_id and c.parent_comment.pinned == "Admin Note":
|
|
|
|
c.pinned = "Admin Note"
|
|
|
|
|
2023-10-17 09:02:46 +00:00
|
|
|
process_options(v, c)
|
2023-02-28 22:09:16 +00:00
|
|
|
|
2022-10-21 00:28:05 +00:00
|
|
|
execute_blackjack(v, c, c.body, "comment")
|
2024-01-19 05:54:37 +00:00
|
|
|
|
2024-01-31 23:28:39 +00:00
|
|
|
kind = "normal comment" if posting_to_post else "wall comment"
|
2024-08-12 18:02:50 +00:00
|
|
|
execute_under_siege(v, c, kind)
|
2022-09-27 02:44:06 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
if c.level == 1: c.top_comment_id = c.id
|
|
|
|
else: c.top_comment_id = parent.top_comment_id
|
|
|
|
|
2024-10-19 09:04:39 +00:00
|
|
|
if not complies_with_chud(c):
|
2022-07-13 19:21:13 +00:00
|
|
|
c.is_banned = True
|
2024-10-22 17:57:23 +00:00
|
|
|
|
|
|
|
for media_usage in c.media_usages:
|
|
|
|
media_usage.removed_utc = time.time()
|
|
|
|
g.db.add(media_usage)
|
|
|
|
|
2024-07-22 18:08:58 +00:00
|
|
|
c.ban_reason = "AutoJanny for lack of chud phrase"
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(c)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-07-21 18:47:01 +00:00
|
|
|
body = random.choice(CHUD_MSGS).format(username=v.username, type='comment', CHUD_PHRASE=v.chud_phrase)
|
2023-03-25 16:46:50 +00:00
|
|
|
body_jannied_html = sanitize(body)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-07-13 19:21:13 +00:00
|
|
|
c_jannied = Comment(author_id=AUTOJANNY_ID,
|
2023-06-23 13:46:42 +00:00
|
|
|
parent_post=post_target.id if posting_to_post else None,
|
|
|
|
wall_user_id=post_target.id if not posting_to_post else None,
|
2024-02-16 12:11:08 +00:00
|
|
|
distinguished=True,
|
2022-07-13 19:21:13 +00:00
|
|
|
parent_comment_id=c.id,
|
|
|
|
level=level+1,
|
|
|
|
is_bot=True,
|
|
|
|
body=body,
|
|
|
|
body_html=body_jannied_html,
|
|
|
|
top_comment_id=c.top_comment_id,
|
|
|
|
ghost=c.ghost
|
|
|
|
)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(c_jannied)
|
|
|
|
g.db.flush()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-06-23 13:46:42 +00:00
|
|
|
if posting_to_post:
|
2023-02-18 21:59:17 +00:00
|
|
|
post_target.comment_count += 1
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(post_target)
|
2023-02-18 21:59:17 +00:00
|
|
|
|
2022-07-13 19:21:13 +00:00
|
|
|
n = Notification(comment_id=c_jannied.id, user_id=v.id)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(n)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-06-23 17:47:08 +00:00
|
|
|
autojanny = g.db.get(User, AUTOJANNY_ID)
|
|
|
|
autojanny.comment_count += 1
|
|
|
|
g.db.add(autojanny)
|
|
|
|
|
2022-12-09 03:35:28 +00:00
|
|
|
execute_longpostbot(c, level, body, body_html, post_target, v)
|
|
|
|
execute_zozbot(c, level, post_target, v)
|
2022-07-13 19:17:17 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
notify_users = NOTIFY_USERS(body, v, ghost=c.ghost, obj=c, commenters_ping_post_id=commenters_ping_post_id)
|
2022-06-27 19:13:19 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
if notify_users == 'everyone':
|
|
|
|
alert_everyone(c.id)
|
|
|
|
else:
|
|
|
|
push_notif(notify_users, f'New mention of you by @{c.author_name}', c.body, c)
|
2023-02-24 02:50:46 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
if c.level == 1 and posting_to_post:
|
|
|
|
subscriber_ids = [x[0] for x in g.db.query(Subscription.user_id).filter(Subscription.post_id == post_target.id, Subscription.user_id != v.id)]
|
2023-02-24 02:50:46 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
notify_users.update(subscriber_ids)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
push_notif(subscriber_ids, f'New comment in subscribed thread by @{c.author_name}', c.body, c)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2024-05-23 00:40:54 +00:00
|
|
|
if parent_user.id != v.id and notify_op and parent_user.id not in notify_users:
|
2024-03-05 22:32:39 +00:00
|
|
|
notify_users.add(parent_user.id)
|
2024-05-23 00:40:54 +00:00
|
|
|
if isinstance(parent, User):
|
|
|
|
title = f"New comment on your wall by @{c.author_name}"
|
|
|
|
else:
|
|
|
|
title = f'New reply by @{c.author_name}'
|
|
|
|
push_notif({parent_user.id}, title, c.body, c)
|
2022-07-13 19:17:17 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
notify_users -= BOT_IDs
|
2023-10-05 12:23:58 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
if v.shadowbanned or c.is_banned:
|
|
|
|
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['USER_SHADOWBAN']).all()]
|
2023-10-05 08:48:49 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
if c.pinned == "Admin Note":
|
|
|
|
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['ADMIN_NOTES']).all()]
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
for x in notify_users:
|
|
|
|
n = Notification(comment_id=c.id, user_id=x)
|
|
|
|
g.db.add(n)
|
2022-06-27 19:02:24 +00:00
|
|
|
|
2024-06-06 18:34:27 +00:00
|
|
|
if c.level >= 3 and c.parent_comment.author_id in notify_users:
|
|
|
|
n = g.db.query(Notification).filter_by(
|
|
|
|
comment_id=c.parent_comment.parent_comment_id,
|
|
|
|
user_id=c.parent_comment.author_id,
|
|
|
|
read=True,
|
|
|
|
).one_or_none()
|
|
|
|
if n: g.db.delete(n)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
vote = CommentVote(user_id=v.id,
|
|
|
|
comment_id=c.id,
|
|
|
|
vote_type=1,
|
2023-03-12 09:40:30 +00:00
|
|
|
coins=0
|
2022-05-04 23:09:46 +00:00
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(vote)
|
2024-10-19 05:48:14 +00:00
|
|
|
|
|
|
|
if c.distinguished:
|
|
|
|
ma = ModAction(
|
|
|
|
kind='distinguish_comment',
|
|
|
|
user_id=v.id,
|
2024-10-19 06:06:37 +00:00
|
|
|
target_comment_id=c.id
|
2024-10-19 05:48:14 +00:00
|
|
|
)
|
|
|
|
g.db.add(ma)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
cache.delete_memoized(comment_idlist)
|
|
|
|
|
2023-08-01 22:03:41 +00:00
|
|
|
if not (c.parent_post in ADMIGGER_THREADS and c.level == 1):
|
|
|
|
v.comment_count += 1
|
|
|
|
g.db.add(v)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
c.voted = 1
|
|
|
|
|
2022-12-09 05:55:18 +00:00
|
|
|
check_for_treasure(c, body)
|
|
|
|
check_slots_command(c, v, v)
|
|
|
|
|
2023-07-23 14:41:39 +00:00
|
|
|
# Increment post count if not self-reply and not a spammy comment game
|
2022-12-09 05:55:18 +00:00
|
|
|
# Essentially a measure to make comment counts reflect "real" content
|
2023-06-23 13:46:42 +00:00
|
|
|
if (posting_to_post and not rts and not c.slots_result):
|
2022-12-09 05:55:18 +00:00
|
|
|
post_target.comment_count += 1
|
2023-07-25 22:37:54 +00:00
|
|
|
post_target.bump_utc = c.created_utc
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(post_target)
|
2022-10-30 00:36:23 +00:00
|
|
|
|
2024-11-12 11:09:12 +00:00
|
|
|
g.db.commit()
|
|
|
|
gevent.spawn(postprocess_comment, c.body, c.body_html, c.id)
|
2023-08-21 15:51:37 +00:00
|
|
|
|
2023-06-27 20:08:52 +00:00
|
|
|
if c.parent_post:
|
2023-09-05 14:32:36 +00:00
|
|
|
for sort in COMMENT_SORTS.keys():
|
2023-06-27 20:08:52 +00:00
|
|
|
cache.delete(f'post_{c.parent_post}_{sort}')
|
2023-05-04 19:55:08 +00:00
|
|
|
|
2023-06-08 00:49:37 +00:00
|
|
|
if v.client: return c.json
|
2023-10-15 15:51:59 +00:00
|
|
|
return {"id": c.id, "comment": render_template("comments.html", v=v, comments=[c])}
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/delete/comment/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-11-11 12:29:22 +00:00
|
|
|
@limiter.limit(DELETE_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DELETE_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
|
|
|
def delete_comment(cid, v):
|
|
|
|
c = get_comment(cid, v=v)
|
|
|
|
if not c.deleted_utc:
|
2024-08-11 20:11:04 +00:00
|
|
|
if c.author_id != v.id: stop(403)
|
2023-09-29 01:25:14 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
c.deleted_utc = int(time.time())
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(c)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-04-21 20:07:16 +00:00
|
|
|
c.author.truescore -= c.upvotes + c.downvotes - 1
|
2024-04-20 20:55:52 +00:00
|
|
|
g.db.add(c.author)
|
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if c.pinned:
|
|
|
|
c.pinned = None
|
|
|
|
c.pinned_utc = None
|
2023-12-03 22:41:16 +00:00
|
|
|
c.unpin_parents()
|
|
|
|
|
2023-08-01 22:03:41 +00:00
|
|
|
if not (c.parent_post in ADMIGGER_THREADS and c.level == 1):
|
|
|
|
v.comment_count -= 1
|
|
|
|
g.db.add(v)
|
|
|
|
|
2024-10-22 17:57:23 +00:00
|
|
|
for media_usage in c.media_usages:
|
|
|
|
media_usage.deleted_utc = c.deleted_utc
|
|
|
|
g.db.add(media_usage)
|
|
|
|
|
2023-08-01 22:03:41 +00:00
|
|
|
cache.delete_memoized(comment_idlist)
|
2023-08-15 22:02:02 +00:00
|
|
|
|
|
|
|
if c.parent_post:
|
2023-09-05 14:32:36 +00:00
|
|
|
for sort in COMMENT_SORTS.keys():
|
2023-08-15 22:02:02 +00:00
|
|
|
cache.delete(f'post_{c.parent_post}_{sort}')
|
|
|
|
|
2023-09-29 06:26:46 +00:00
|
|
|
if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and c.parent_post == SNAPPY_THREAD and c.level == 1 and c.body in SNAPPY_QUOTES:
|
|
|
|
SNAPPY_QUOTES.remove(c.body)
|
2024-02-11 10:17:02 +00:00
|
|
|
new_text = "\n[para]\n".join(SNAPPY_QUOTES)
|
2023-09-29 06:26:46 +00:00
|
|
|
with open(f"snappy_{SITE_NAME}.txt", "w") as f:
|
|
|
|
f.write(new_text + "\n")
|
2023-09-14 23:17:47 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
return {"message": "Comment deleted!"}
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/undelete/comment/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
|
|
|
def undelete_comment(cid, v):
|
|
|
|
c = get_comment(cid, v=v)
|
|
|
|
if c.deleted_utc:
|
2024-08-11 20:11:04 +00:00
|
|
|
if c.author_id != v.id: stop(403)
|
2022-05-04 23:09:46 +00:00
|
|
|
c.deleted_utc = 0
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(c)
|
2023-08-01 22:03:41 +00:00
|
|
|
|
2024-04-21 20:07:16 +00:00
|
|
|
c.author.truescore += c.upvotes + c.downvotes - 1
|
2024-04-20 20:55:52 +00:00
|
|
|
g.db.add(c.author)
|
|
|
|
|
2023-08-01 22:03:41 +00:00
|
|
|
if not (c.parent_post in ADMIGGER_THREADS and c.level == 1):
|
|
|
|
v.comment_count += 1
|
|
|
|
g.db.add(v)
|
|
|
|
|
2024-10-22 17:57:23 +00:00
|
|
|
for media_usage in c.media_usages:
|
|
|
|
media_usage.deleted_utc = None
|
|
|
|
g.db.add(media_usage)
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
cache.delete_memoized(comment_idlist)
|
2023-08-15 22:02:02 +00:00
|
|
|
|
|
|
|
if c.parent_post:
|
2023-09-05 14:32:36 +00:00
|
|
|
for sort in COMMENT_SORTS.keys():
|
2023-08-15 22:02:02 +00:00
|
|
|
cache.delete(f'post_{c.parent_post}_{sort}')
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
return {"message": "Comment undeleted!"}
|
|
|
|
|
2024-02-18 15:33:56 +00:00
|
|
|
@app.post("/pin_comment_op/<int:cid>")
|
2022-10-11 07:29:24 +00:00
|
|
|
@feature_required('PINS')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-11-14 15:11:05 +00:00
|
|
|
@auth_required
|
2024-02-18 15:33:56 +00:00
|
|
|
def pin_comment_op(cid, v):
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
comment = get_comment(cid, v=v)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if not comment.pinned:
|
2024-08-11 20:11:04 +00:00
|
|
|
if v.id != comment.post.author_id: stop(403)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if comment.post.ghost: comment.pinned = "(OP)"
|
|
|
|
else: comment.pinned = v.username + " (OP)"
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-12-03 22:41:16 +00:00
|
|
|
comment.pin_parents()
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
if v.id != comment.author_id:
|
2024-02-20 00:00:21 +00:00
|
|
|
if comment.post.ghost: message = f"OP has pinned {comment.textlink}"
|
|
|
|
else: message = f"@{v.username} (OP) has pinned {comment.textlink}"
|
2022-05-04 23:09:46 +00:00
|
|
|
send_repeatable_notification(comment.author_id, message)
|
|
|
|
|
|
|
|
return {"message": "Comment pinned!"}
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-02-18 15:33:56 +00:00
|
|
|
@app.post("/unpin_comment_op/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
2024-02-18 15:33:56 +00:00
|
|
|
def unpin_comment_op(cid, v):
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
comment = get_comment(cid, v=v)
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if comment.pinned:
|
2024-08-11 20:11:04 +00:00
|
|
|
if v.id != comment.post.author_id: stop(403)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
if not comment.pinned.endswith(" (OP)"):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can only unpin comments you have pinned!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2024-02-18 15:29:53 +00:00
|
|
|
comment.pinned = None
|
|
|
|
comment.pinned_utc = None
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-12-03 22:41:16 +00:00
|
|
|
comment.unpin_parents()
|
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
if v.id != comment.author_id:
|
2024-02-20 00:00:21 +00:00
|
|
|
message = f"@{v.username} (OP) has unpinned {comment.textlink}"
|
2022-05-04 23:09:46 +00:00
|
|
|
send_repeatable_notification(comment.author_id, message)
|
|
|
|
return {"message": "Comment unpinned!"}
|
|
|
|
|
|
|
|
|
2024-08-17 17:48:52 +00:00
|
|
|
@app.post("/pin_comment_wall_owner/<int:cid>")
|
|
|
|
@feature_required('PINS')
|
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
|
|
|
@auth_required
|
|
|
|
def pin_comment_wall_owner(cid, v):
|
|
|
|
comment = get_comment(cid, v=v)
|
|
|
|
|
|
|
|
if not comment.pinned:
|
|
|
|
if v.id != comment.wall_user_id:
|
|
|
|
stop(403, "You can't pin comments on the walls of other users!")
|
|
|
|
|
2024-11-12 22:42:55 +00:00
|
|
|
existing = g.db.query(Comment.id).join(Comment.author).filter(
|
2024-08-17 17:48:52 +00:00
|
|
|
Comment.wall_user_id == v.id,
|
|
|
|
Comment.pinned.like('% (Wall Owner)'),
|
2024-11-12 22:42:55 +00:00
|
|
|
User.shadowbanned == None,
|
2024-08-17 17:48:52 +00:00
|
|
|
).one_or_none()
|
|
|
|
|
|
|
|
if existing:
|
|
|
|
abort(403, "You can only pin one comment on your wall!")
|
|
|
|
|
|
|
|
comment.pinned = v.username + " (Wall Owner)"
|
|
|
|
|
|
|
|
g.db.add(comment)
|
|
|
|
|
|
|
|
comment.pin_parents()
|
|
|
|
|
|
|
|
return {"message": "Comment pinned!"}
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/unpin_comment_wall_owner/<int:cid>")
|
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
|
|
|
@auth_required
|
|
|
|
def unpin_comment_wall_owner(cid, v):
|
|
|
|
comment = get_comment(cid, v=v)
|
|
|
|
|
|
|
|
if comment.pinned:
|
|
|
|
if v.id != comment.wall_user_id:
|
|
|
|
stop(403, "You can't unpin comments on the walls of other users!")
|
|
|
|
|
|
|
|
if not comment.pinned.endswith(" (Wall Owner)"):
|
|
|
|
stop(403, "You can only unpin comments you have pinned!")
|
|
|
|
|
|
|
|
comment.pinned = None
|
|
|
|
comment.pinned_utc = None
|
|
|
|
g.db.add(comment)
|
|
|
|
|
|
|
|
comment.unpin_parents()
|
|
|
|
|
|
|
|
return {"message": "Comment unpinned!"}
|
|
|
|
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/save_comment/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
|
|
|
def save_comment(cid, v):
|
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
comment = get_comment(cid)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
save = g.db.query(CommentSaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
if not save:
|
|
|
|
new_save=CommentSaveRelationship(user_id=v.id, comment_id=comment.id)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(new_save)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
return {"message": "Comment saved!"}
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/unsave_comment/<int:cid>")
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-05-04 23:09:46 +00:00
|
|
|
@auth_required
|
|
|
|
def unsave_comment(cid, v):
|
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
comment = get_comment(cid)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
save = g.db.query(CommentSaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
if save:
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.delete(save)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
return {"message": "Comment unsaved!"}
|
|
|
|
|
|
|
|
|
|
|
|
def diff_words(answer, guess):
|
|
|
|
"""
|
|
|
|
Return a list of numbers corresponding to the char's relevance.
|
|
|
|
-1 means char is not in solution or the character appears too many times in the guess
|
|
|
|
0 means char is in solution but in the wrong spot
|
|
|
|
1 means char is in the correct spot
|
|
|
|
"""
|
|
|
|
diffs = [
|
|
|
|
1 if cs == cg else -1 for cs, cg in zip(answer, guess)
|
|
|
|
]
|
|
|
|
char_freq = Counter(
|
|
|
|
c_guess for c_guess, diff, in zip(answer, diffs) if diff == -1
|
|
|
|
)
|
|
|
|
for i, cg in enumerate(guess):
|
|
|
|
if diffs[i] == -1 and cg in char_freq and char_freq[cg] > 0:
|
|
|
|
char_freq[cg] -= 1
|
|
|
|
diffs[i] = 0
|
|
|
|
return diffs
|
|
|
|
|
|
|
|
|
2022-12-29 10:39:10 +00:00
|
|
|
@app.post("/toggle_comment_nsfw/<int:cid>")
|
2023-02-01 18:52:34 +00:00
|
|
|
@feature_required('NSFW_MARKING')
|
2023-02-27 05:33:45 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
2023-04-02 06:52:26 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
2023-07-13 13:50:46 +00:00
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2022-10-05 23:24:54 +00:00
|
|
|
@auth_required
|
|
|
|
def toggle_comment_nsfw(cid, v):
|
|
|
|
comment = get_comment(cid)
|
|
|
|
|
2024-02-16 12:36:45 +00:00
|
|
|
if comment.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_MODERATION'] and not (comment.post and v.mods_hole(comment.post.hole)) and comment.wall_user_id != v.id:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403)
|
2022-10-05 23:24:54 +00:00
|
|
|
|
2023-10-05 10:19:50 +00:00
|
|
|
comment.nsfw = not comment.nsfw
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(comment)
|
2022-10-05 23:24:54 +00:00
|
|
|
|
|
|
|
if comment.author_id != v.id:
|
2022-10-06 00:57:08 +00:00
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_MODERATION']:
|
2022-10-05 23:24:54 +00:00
|
|
|
ma = ModAction(
|
2023-10-05 10:19:50 +00:00
|
|
|
kind = "set_nsfw_comment" if comment.nsfw else "unset_nsfw_comment",
|
2022-10-05 23:24:54 +00:00
|
|
|
user_id = v.id,
|
|
|
|
target_comment_id = comment.id,
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2024-02-16 12:36:45 +00:00
|
|
|
elif comment.post and v.mods_hole(comment.post.hole):
|
2023-10-07 17:55:50 +00:00
|
|
|
ma = HoleAction(
|
|
|
|
hole = comment.post.hole,
|
2023-10-05 10:19:50 +00:00
|
|
|
kind = "set_nsfw_comment" if comment.nsfw else "unset_nsfw_comment",
|
2022-10-05 23:24:54 +00:00
|
|
|
user_id = v.id,
|
|
|
|
target_comment_id = comment.id,
|
|
|
|
)
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(ma)
|
2022-10-05 23:24:54 +00:00
|
|
|
|
2023-10-05 10:19:50 +00:00
|
|
|
if comment.nsfw: return {"message": "Comment has been marked as NSFW!"}
|
2023-10-04 14:04:06 +00:00
|
|
|
else: return {"message": "Comment has been unmarked as NSFW!"}
|
2023-02-28 22:22:59 +00:00
|
|
|
|
|
|
|
@app.post("/edit_comment/<int:cid>")
|
2024-02-07 03:45:47 +00:00
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
2023-09-14 16:49:46 +00:00
|
|
|
@auth_required
|
2024-02-07 03:45:47 +00:00
|
|
|
def edit_comment(cid, v):
|
2023-02-28 22:22:59 +00:00
|
|
|
c = get_comment(cid, v=v)
|
|
|
|
|
2024-02-28 21:12:04 +00:00
|
|
|
if time.time() - c.created_utc > 3*24*60*60 and not (c.post and c.post.draft) and v.admin_level < PERMS["IGNORE_EDITING_LIMIT"] and v.id not in EXEMPT_FROM_EDITING_LIMIT:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can't edit comments older than 3 days!")
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2024-10-21 20:02:16 +00:00
|
|
|
if c.is_banned:
|
|
|
|
stop(403, "You can't edit comments that were removed by admins!")
|
|
|
|
|
2023-08-15 20:22:46 +00:00
|
|
|
if c.author_id != v.id and v.admin_level < PERMS['POST_COMMENT_EDITING']:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403)
|
2023-08-15 20:22:46 +00:00
|
|
|
|
2023-06-23 13:46:42 +00:00
|
|
|
if not c.parent_post and not c.wall_user_id:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403)
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2024-02-14 09:27:00 +00:00
|
|
|
body = request.values.get("body", "").strip()
|
|
|
|
if len(body) > COMMENT_BODY_LENGTH_LIMIT:
|
2024-10-23 15:07:29 +00:00
|
|
|
stop(400, f'Comment body is too long (max {COMMENT_BODY_LENGTH_LIMIT} characters)')
|
2023-02-28 22:22:59 +00:00
|
|
|
|
|
|
|
if len(body) < 1 and not (request.files.get("file") and not g.is_tor):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(400, "You have to actually type something!")
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2024-02-24 23:19:37 +00:00
|
|
|
body = body.replace('@jannies', '!jannies')
|
|
|
|
|
2024-02-07 03:45:47 +00:00
|
|
|
if body != c.body or request.files.get("file") and not g.is_tor:
|
2024-10-19 05:52:45 +00:00
|
|
|
if not c.distinguished:
|
|
|
|
if c.author.longpost and (len(body) < 280 or ' [](' in body or body.startswith('[](')):
|
|
|
|
stop(403, "You have to type more than 280 characters!")
|
|
|
|
elif c.author.bird and len(body) > 140:
|
|
|
|
stop(403, "You have to type less than 140 characters!")
|
2023-02-28 22:22:59 +00:00
|
|
|
|
|
|
|
execute_antispam_comment_check(body, v)
|
|
|
|
|
|
|
|
body = process_files(request.files, v, body)
|
2024-02-14 09:27:00 +00:00
|
|
|
if len(body) > COMMENT_BODY_LENGTH_LIMIT:
|
2024-10-23 15:07:29 +00:00
|
|
|
stop(400, f'Comment body is too long (max {COMMENT_BODY_LENGTH_LIMIT} characters)')
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-10-13 19:04:45 +00:00
|
|
|
body_html = sanitize(body, golden=False, limit_pings=5, showmore=(not v.hieroglyphs), commenters_ping_post_id=c.parent_post, obj=c, author=c.author)
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-12-20 15:53:33 +00:00
|
|
|
if len(body_html) > COMMENT_BODY_HTML_LENGTH_LIMIT:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(400, "Rendered comment is too long!")
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2024-10-19 04:40:55 +00:00
|
|
|
if c.author.hieroglyphs and not c.distinguished and c.parent_post not in ADMIGGER_THREADS and marseyaward_body_regex.search(body_html):
|
2024-08-17 17:51:02 +00:00
|
|
|
stop(403, "You can only type emojis!")
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2024-03-07 22:59:07 +00:00
|
|
|
if int(time.time()) - c.created_utc > 60 * 3:
|
|
|
|
edit_log = CommentEdit(
|
|
|
|
comment_id=c.id,
|
|
|
|
old_body=c.body,
|
|
|
|
old_body_html=c.body_html,
|
|
|
|
)
|
|
|
|
g.db.add(edit_log)
|
2024-03-07 22:52:55 +00:00
|
|
|
|
2023-07-16 11:56:24 +00:00
|
|
|
oldtext = c.body
|
|
|
|
|
2023-02-28 22:22:59 +00:00
|
|
|
c.body = body
|
|
|
|
|
|
|
|
c.body_html = body_html
|
|
|
|
|
|
|
|
execute_blackjack(v, c, c.body, "comment")
|
|
|
|
|
2023-03-23 12:50:01 +00:00
|
|
|
if not complies_with_chud(c):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, f'You have to include "{c.author.chud_phrase}" in your comment!')
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-10-17 09:02:46 +00:00
|
|
|
process_options(v, c)
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-08-15 20:34:06 +00:00
|
|
|
if v.id == c.author_id:
|
|
|
|
if int(time.time()) - c.created_utc > 60 * 3:
|
|
|
|
c.edited_utc = int(time.time())
|
|
|
|
else:
|
2024-01-31 21:56:32 +00:00
|
|
|
ma = ModAction(
|
2023-08-15 20:34:06 +00:00
|
|
|
kind="edit_comment",
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=c.id
|
|
|
|
)
|
|
|
|
g.db.add(ma)
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
g.db.add(c)
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-10-29 12:03:00 +00:00
|
|
|
notify_users = NOTIFY_USERS(body, v, oldtext=oldtext, ghost=c.ghost, obj=c, commenters_ping_post_id=c.parent_post)
|
2023-06-29 19:22:12 +00:00
|
|
|
|
|
|
|
if notify_users == 'everyone':
|
|
|
|
alert_everyone(c.id)
|
|
|
|
else:
|
2023-10-05 12:23:58 +00:00
|
|
|
notify_users -= BOT_IDs
|
|
|
|
|
2024-03-05 22:32:39 +00:00
|
|
|
if c.pinned == "Admin Note":
|
|
|
|
notify_users = [x[0] for x in g.db.query(User.id).filter(User.id.in_(notify_users), User.admin_level >= PERMS['ADMIN_NOTES']).all()]
|
|
|
|
|
2023-10-05 12:23:58 +00:00
|
|
|
for x in notify_users:
|
2023-06-29 19:22:12 +00:00
|
|
|
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
|
|
|
if not notif:
|
|
|
|
n = Notification(comment_id=c.id, user_id=x)
|
|
|
|
g.db.add(n)
|
2023-08-20 02:36:43 +00:00
|
|
|
push_notif({x}, f'New mention of you by @{c.author_name}', c.body, c)
|
2023-06-29 19:22:12 +00:00
|
|
|
|
2024-11-12 11:09:12 +00:00
|
|
|
g.db.commit()
|
2023-10-06 19:22:11 +00:00
|
|
|
gevent.spawn(postprocess_comment, c.body, c.body_html, c.id)
|
2024-03-07 22:02:25 +00:00
|
|
|
else:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(400, "You need to change something!")
|
2023-10-06 19:22:11 +00:00
|
|
|
|
2023-02-28 22:22:59 +00:00
|
|
|
|
2023-08-14 07:04:48 +00:00
|
|
|
return {
|
|
|
|
"body": c.body,
|
|
|
|
"comment": c.realbody(v),
|
|
|
|
"ping_cost": c.ping_cost,
|
|
|
|
"edited_string": c.edited_string,
|
|
|
|
}
|
2023-09-05 18:24:10 +00:00
|
|
|
|
|
|
|
@app.get("/!commenters/<int:pid>/<int:time>")
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
|
|
|
@auth_required
|
|
|
|
def commenters(v, pid, time):
|
2023-11-16 12:50:33 +00:00
|
|
|
p = get_post(pid)
|
|
|
|
|
|
|
|
if p.ghost:
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can't see commenters on ghost threads!")
|
2023-11-16 12:50:33 +00:00
|
|
|
|
2023-09-05 18:24:10 +00:00
|
|
|
users = g.db.query(User, Comment.id, Comment.created_utc).distinct(User.id).join(
|
|
|
|
Comment, Comment.author_id == User.id
|
|
|
|
).filter(
|
|
|
|
Comment.parent_post == pid,
|
|
|
|
Comment.created_utc < time-1,
|
|
|
|
User.id.notin_(BOT_IDs),
|
2023-09-05 18:31:55 +00:00
|
|
|
).order_by(User.id, Comment.created_utc).all()
|
2023-09-05 18:24:10 +00:00
|
|
|
|
|
|
|
users = sorted(users, key=lambda x: x[1])
|
|
|
|
|
|
|
|
return render_template('commenters.html', v=v, users=users)
|
2023-10-06 19:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def postprocess_comment(comment_body, comment_body_html, cid):
|
|
|
|
with app.app_context():
|
|
|
|
li = list(reddit_s_url_regex.finditer(comment_body)) + list(tiktok_t_url_regex.finditer(comment_body))
|
2023-10-06 19:28:32 +00:00
|
|
|
|
|
|
|
if not li: return
|
|
|
|
|
2023-10-06 19:22:11 +00:00
|
|
|
for i in li:
|
|
|
|
old = i.group(0)
|
|
|
|
new = normalize_url_gevent(old)
|
|
|
|
comment_body = comment_body.replace(old, new)
|
|
|
|
comment_body_html = comment_body_html.replace(old, new)
|
|
|
|
|
|
|
|
g.db = db_session()
|
|
|
|
|
|
|
|
c = g.db.query(Comment).filter_by(id=cid).options(load_only(Comment.id)).one_or_none()
|
|
|
|
c.body = comment_body
|
|
|
|
c.body_html = comment_body_html
|
|
|
|
g.db.add(c)
|
|
|
|
|
|
|
|
g.db.commit()
|
|
|
|
g.db.close()
|
|
|
|
|
|
|
|
stdout.flush()
|
2024-02-16 12:49:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/distinguish_comment/<int:c_id>")
|
|
|
|
@limiter.limit('1/second', scope=rpath)
|
|
|
|
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
|
|
|
|
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
|
|
|
|
@auth_required
|
|
|
|
def admin_distinguish_comment(c_id, v):
|
|
|
|
comment = get_comment(c_id, v=v)
|
|
|
|
|
|
|
|
if v.admin_level < PERMS['POST_COMMENT_DISTINGUISH'] and not (comment.parent_post and v.mods_hole(comment.post.hole)):
|
2024-08-11 20:11:04 +00:00
|
|
|
stop(403, "You can't distinguish this comment")
|
2024-02-16 12:49:26 +00:00
|
|
|
|
|
|
|
if comment.distinguished:
|
|
|
|
comment.distinguished = False
|
|
|
|
kind = 'undistinguish_comment'
|
|
|
|
else:
|
|
|
|
comment.distinguished = True
|
|
|
|
kind = 'distinguish_comment'
|
|
|
|
|
|
|
|
g.db.add(comment)
|
|
|
|
|
2024-08-03 17:11:25 +00:00
|
|
|
if v.admin_level >= PERMS['POST_COMMENT_DISTINGUISH']:
|
2024-04-09 01:38:18 +00:00
|
|
|
cls = ModAction
|
2024-08-03 17:11:25 +00:00
|
|
|
else:
|
|
|
|
cls = HoleAction
|
2024-03-31 00:48:53 +00:00
|
|
|
|
|
|
|
ma = cls(
|
2024-02-16 12:49:26 +00:00
|
|
|
kind=kind,
|
|
|
|
user_id=v.id,
|
|
|
|
target_comment_id=comment.id
|
|
|
|
)
|
2024-03-31 23:16:09 +00:00
|
|
|
if cls == HoleAction:
|
|
|
|
ma.hole = comment.post.hole
|
2024-02-16 12:49:26 +00:00
|
|
|
g.db.add(ma)
|
|
|
|
|
|
|
|
if comment.distinguished: return {"message": "Comment distinguished!"}
|
|
|
|
else: return {"message": "Comment undistinguished!"}
|