rDrama/files/routes/comments.py

1051 lines
32 KiB
Python
Raw Normal View History

2021-10-15 14:08:27 +00:00
from files.helpers.wrappers import *
from files.helpers.filters import *
from files.helpers.alerts import *
from files.helpers.images import *
from files.helpers.const import *
from files.classes import *
from files.routes.front import comment_idlist
2022-01-30 22:57:09 +00:00
from files.routes.static import marsey_list
2021-10-15 14:08:27 +00:00
from pusher_push_notifications import PushNotifications
from flask import *
from files.__main__ import app, limiter
2021-12-07 23:18:06 +00:00
from files.helpers.sanitize import filter_emojis_only
2021-12-18 02:59:40 +00:00
import requests
2022-01-24 23:40:34 +00:00
from shutil import copyfile
2022-01-22 10:41:37 +00:00
from json import loads
2021-10-15 14:08:27 +00:00
2021-12-28 04:47:02 +00:00
IMGUR_KEY = environ.get("IMGUR_KEY").strip()
2021-10-15 14:08:27 +00:00
2022-01-18 11:19:32 +00:00
if PUSHER_ID: beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
2021-10-15 14:08:27 +00:00
2022-01-23 23:06:34 +00:00
CF_KEY = environ.get("CF_KEY", "").strip()
CF_ZONE = environ.get("CF_ZONE", "").strip()
CF_HEADERS = {"Authorization": f"Bearer {CF_KEY}", "Content-Type": "application/json"}
2021-10-15 14:08:27 +00:00
@app.get("/comment/<cid>")
@app.get("/post/<pid>/<anything>/<cid>")
@app.get("/logged_out/comment/<cid>")
@app.get("/logged_out/post/<pid>/<anything>/<cid>")
2022-02-04 18:35:39 +00:00
@app.get("/s/<sub>/comment/<cid>")
@app.get("/s/<sub>/post/<pid>/<anything>/<cid>")
@app.get("/logged_out/s/<sub>/comment/<cid>")
@app.get("/logged_out/s/<sub>/post/<pid>/<anything>/<cid>")
2022-01-11 22:57:05 +00:00
@auth_desired
2022-02-04 18:35:39 +00:00
def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
2021-10-15 14:08:27 +00:00
2022-01-24 19:40:58 +00:00
if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}")
2021-10-15 14:08:27 +00:00
2022-02-11 18:44:12 +00:00
if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out',''))
2021-10-15 14:08:27 +00:00
try: cid = int(cid)
2022-02-04 08:59:12 +00:00
except: abort(404)
2021-10-15 14:08:27 +00:00
comment = get_comment(cid, v=v)
2021-10-20 14:37:46 +00:00
if v and request.values.get("read"):
2022-01-02 00:06:46 +00:00
notif = g.db.query(Notification).filter_by(comment_id=cid, user_id=v.id, read=False).one_or_none()
2021-10-20 14:37:46 +00:00
if notif:
notif.read = True
g.db.add(notif)
g.db.commit()
2021-12-03 17:02:34 +00:00
if comment.post and comment.post.club and not (v and (v.paid_dues or v.id in [comment.author_id, comment.post.author_id])): abort(403)
2021-10-15 14:08:27 +00:00
2022-01-28 06:34:09 +00:00
if comment.post and comment.post.private and not (v and (v.admin_level > 1 or v.id == comment.post.author.id)): abort(403)
2022-01-11 17:42:56 +00:00
if not comment.parent_submission and not (v and (comment.author.id == v.id or comment.sentto == v.id)) and not (v and v.admin_level > 1) : abort(403)
2021-10-15 14:08:27 +00:00
if not pid:
if comment.parent_submission: pid = comment.parent_submission
2022-02-07 15:07:46 +00:00
elif SITE_NAME == 'Drama': pid = 6489
2022-01-03 04:08:46 +00:00
elif request.host == 'pcmemes.net': pid = 2487
2021-10-15 14:08:27 +00:00
else: pid = 1
try: pid = int(pid)
except: abort(404)
post = get_post(pid, v=v)
if post.over_18 and not (v and v.over_18) and not session.get('over_18', 0) >= int(time.time()):
2022-01-07 21:03:14 +00:00
if request.headers.get("Authorization"): return {'error': 'This content is not suitable for some users and situations.'}
2022-01-14 12:09:05 +00:00
else: render_template("errors/nsfw.html", v=v)
2021-10-15 14:08:27 +00:00
2022-01-30 13:45:06 +00:00
try: context = min(int(request.values.get("context", 0)), 8)
2021-10-15 14:08:27 +00:00
except: context = 0
comment_info = comment
c = comment
2022-01-12 01:19:13 +00:00
while context and c.level > 1:
2021-10-15 14:08:27 +00:00
c = c.parent_comment
context -= 1
top_comment = c
if v: defaultsortingcomments = v.defaultsortingcomments
else: defaultsortingcomments = "top"
sort=request.values.get("sort", defaultsortingcomments)
if v:
2021-11-06 15:52:48 +00:00
votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery()
2021-10-15 14:08:27 +00:00
blocking = v.blocking.subquery()
blocked = v.blocked.subquery()
comments = g.db.query(
Comment,
votes.c.vote_type,
blocking.c.id,
blocked.c.id,
2021-11-06 15:52:48 +00:00
)
2021-10-15 14:08:27 +00:00
2021-11-15 22:13:29 +00:00
if not (v and v.shadowbanned) and not (v and v.admin_level > 1):
2021-11-06 00:33:32 +00:00
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
2021-10-15 14:08:27 +00:00
comments=comments.filter(
Comment.parent_submission == post.id,
2022-02-07 11:39:26 +00:00
Comment.author_id.notin_((AUTOPOLLER_ID, AUTOBETTER_ID, AUTOCHOICE_ID))
2021-10-15 14:08:27 +00:00
).join(
votes,
votes.c.comment_id == Comment.id,
isouter=True
).join(
blocking,
blocking.c.target_id == Comment.author_id,
isouter=True
).join(
blocked,
blocked.c.user_id == Comment.author_id,
isouter=True
)
output = []
for c in comments:
comment = c[0]
comment.voted = c[1] or 0
comment.is_blocking = c[2] or 0
comment.is_blocked = c[3] or 0
output.append(comment)
2021-10-22 00:21:51 +00:00
post.replies=[top_comment]
2021-10-15 14:08:27 +00:00
if request.headers.get("Authorization"): return top_comment.json
2021-10-22 00:19:23 +00:00
else:
2021-11-15 22:19:59 +00:00
if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html"
2021-10-22 00:19:23 +00:00
else: template = "submission.html"
2022-02-05 21:09:17 +00:00
return render_template(template, v=v, p=post, sort=sort, comment_info=comment_info, render_replies=True, sub=post.subr)
2021-10-15 14:08:27 +00:00
@app.post("/comment")
2022-01-27 20:15:05 +00:00
@limiter.limit("1/second;20/minute;200/hour;1000/day")
2022-01-06 16:46:09 +00:00
@auth_required
2021-10-15 14:08:27 +00:00
def api_comment(v):
2022-01-06 16:46:09 +00:00
if v.is_suspended: return {"error": "You can't perform this action while banned."}, 403
2021-11-11 19:14:11 +00:00
if v and v.patron:
2022-01-16 05:53:29 +00:00
if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413
elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413
2021-10-15 14:08:27 +00:00
parent_submission = request.values.get("submission").strip()
parent_fullname = request.values.get("parent_fullname").strip()
parent_post = get_post(parent_submission, v=v)
2021-12-02 18:45:03 +00:00
if parent_post.club and not (v and (v.paid_dues or v.id == parent_post.author_id)): abort(403)
2021-10-15 14:08:27 +00:00
if parent_fullname.startswith("t2_"):
parent = parent_post
parent_comment_id = None
2021-12-05 02:21:38 +00:00
top_comment_id = None
2021-10-15 14:08:27 +00:00
level = 1
elif parent_fullname.startswith("t3_"):
parent = get_comment(parent_fullname.split("_")[1], v=v)
parent_comment_id = parent.id
level = parent.level + 1
2021-12-05 02:21:38 +00:00
if level == 2: top_comment_id = parent.id
else: top_comment_id = parent.top_comment_id
2021-10-15 14:08:27 +00:00
else: abort(400)
2021-12-11 16:22:25 +00:00
body = request.values.get("body", "").strip()[:10000]
2022-02-08 13:26:38 +00:00
if v.admin_level > 1 and parent_post.id == 37749 and level == 1:
2022-02-06 10:54:05 +00:00
with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f:
2022-01-23 23:06:34 +00:00
f.write('\n{[para]}\n' + body)
2022-01-22 00:08:55 +00:00
2022-01-29 00:00:05 +00:00
if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838):
2022-02-04 09:15:59 +00:00
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A))
2022-01-14 08:01:19 +00:00
if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403
2021-10-27 00:37:34 +00:00
2022-01-14 08:01:19 +00:00
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
2022-01-29 00:00:05 +00:00
elif v.bird and len(body) > 140 and parent_post.id not in (37696,37697,37749,37833,37838):
return {"error":"You have to type less than 140 characters!"}, 403
2021-11-18 20:50:03 +00:00
2021-10-15 14:08:27 +00:00
if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400
2022-02-04 09:15:59 +00:00
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A):
2021-10-15 14:08:27 +00:00
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})')
options = []
2022-02-04 09:15:59 +00:00
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A):
2021-10-15 14:08:27 +00:00
options.append(i.group(1))
2021-11-04 20:34:08 +00:00
body = body.replace(i.group(0), "")
2021-10-15 14:08:27 +00:00
2022-02-07 11:39:26 +00:00
choices = []
for i in re.finditer('\s*##([^\$\n]+)##\s*', body, re.A):
choices.append(i.group(1))
body = body.replace(i.group(0), "")
2021-10-18 18:41:56 +00:00
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"]
2021-12-18 02:59:40 +00:00
if file.content_type.startswith('image/'):
2022-01-24 23:40:34 +00:00
oldname = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(oldname)
image = process_image(oldname)
2022-01-22 18:51:33 +00:00
if image == "": return {"error":"Image upload failed"}
2022-02-08 13:26:38 +00:00
if v.admin_level > 2 and level == 1:
2022-01-21 20:17:27 +00:00
if parent_post.id == 37696:
filename = 'files/assets/images/Drama/sidebar/' + str(len(listdir('files/assets/images/Drama/sidebar'))+1) + '.webp'
2022-01-24 23:40:34 +00:00
copyfile(oldname, filename)
process_image(filename, 400)
2022-01-21 20:17:27 +00:00
elif parent_post.id == 37697:
2022-02-01 06:15:42 +00:00
filename = 'files/assets/images/Drama/banners_bhm/' + str(len(listdir('files/assets/images/Drama/banners_bhm'))+1) + '.webp'
2022-01-24 23:40:34 +00:00
copyfile(oldname, filename)
process_image(filename)
2022-01-24 00:02:50 +00:00
elif parent_post.id == 37833:
2022-01-24 23:40:34 +00:00
try:
2022-01-31 01:41:04 +00:00
badge_def = loads(body)
2022-01-24 23:40:34 +00:00
name = badge_def["name"]
badge = g.db.query(BadgeDef).filter_by(name=name).first()
if not badge:
badge = BadgeDef(name=name, description=badge_def["description"])
g.db.add(badge)
g.db.flush()
filename = f'files/assets/images/badges/{badge.id}.webp'
copyfile(oldname, filename)
process_image(filename, 200)
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/badges/{badge.id}.webp"]})
except Exception as e:
2022-02-03 06:39:02 +00:00
return {"error": str(e)}, 400
2022-01-27 21:26:20 +00:00
elif v.admin_level > 2 and parent_post.id == 37838:
2022-01-24 23:40:34 +00:00
try:
marsey = loads(body.lower())
name = marsey["name"]
2022-01-30 22:53:17 +00:00
if "author" in marsey: author_id = get_user(marsey["author"]).id
2022-01-30 21:00:48 +00:00
elif "author_id" in marsey: author_id = marsey["author_id"]
else: abort(400)
2022-01-24 23:40:34 +00:00
if not g.db.query(Marsey.name).filter_by(name=name).first():
2022-01-30 21:00:48 +00:00
marsey = Marsey(name=marsey["name"], author_id=author_id, tags=marsey["tags"], count=0)
2022-01-24 23:40:34 +00:00
g.db.add(marsey)
filename = f'files/assets/images/emojis/{name}.webp'
copyfile(oldname, filename)
process_image(filename, 200)
requests.post(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/purge_cache', headers=CF_HEADERS, data={'files': [f"https://{request.host}/static/assets/images/emojis/{name}.webp"]})
2022-01-30 22:57:09 +00:00
cache.delete_memoized(marsey_list)
2022-01-24 23:40:34 +00:00
except Exception as e:
2022-02-03 06:39:02 +00:00
return {"error": str(e)}, 400
2022-01-23 23:06:34 +00:00
body += f"\n\n![]({image})"
2021-12-18 02:59:40 +00:00
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
2022-01-06 14:20:45 +00:00
try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link']
except: return {"error": "Imgur error"}, 400
2022-01-06 17:57:59 +00:00
if url.endswith('.'): url += 'mp4'
2021-12-18 04:48:10 +00:00
body += f"\n\n{url}"
2022-01-07 21:03:14 +00:00
else: return {"error": "Image/Video files only"}, 400
2021-10-18 18:41:56 +00:00
2022-01-29 00:38:00 +00:00
if v.agendaposter and not v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838):
body = torture_ap(body, v.username)
2021-11-24 17:49:17 +00:00
2022-01-28 02:54:50 +00:00
if '#fortune' in body:
body = body.replace('#fortune', '')
body += '\n\n<p>' + random.choice(FORTUNE_REPLIES) + '</p>'
2022-01-13 23:44:55 +00:00
body_html = sanitize(body, comment=True)
2021-10-15 14:08:27 +00:00
2022-02-04 09:15:59 +00:00
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403
2021-10-27 20:12:16 +00:00
2022-01-29 00:00:05 +00:00
if parent_post.id not in (37696,37697,37749,37833,37838):
if v.longpost:
if len(body) < 280 or ' [](' in body or body.startswith('[]('):
return {"error":"You have to type more than 280 characters!"}, 403
elif v.bird:
if len(body) > 140 : return {"error":"You have to type less than 140 characters!"}, 403
2021-11-18 20:50:03 +00:00
2021-10-15 14:08:27 +00:00
bans = filter_comment_html(body_html)
if bans:
ban = bans[0]
reason = f"Remove the {ban.domain} link from your comment and try again."
if ban.reason: reason += f" {ban.reason}"
return {"error": reason}, 401
2022-01-25 18:56:50 +00:00
if parent_post.id not in (37696,37697,37749,37833,37838) and not body.startswith('!slots') and not body.startswith('!casino'):
2022-01-22 20:03:46 +00:00
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
Comment.deleted_utc == 0,
Comment.parent_comment_id == parent_comment_id,
Comment.parent_submission == parent_submission,
Comment.body_html == body_html
).one_or_none()
if existing: return {"error": f"You already made that comment: /comment/{existing.id}"}, 409
2021-10-15 14:08:27 +00:00
2022-01-29 00:00:05 +00:00
if parent.author.any_block_exists(v) and v.admin_level < 2:
return {"error": "You can't reply to users who have blocked you, or users you have blocked."}, 403
2021-10-15 14:08:27 +00:00
2021-12-16 17:59:30 +00:00
is_bot = bool(request.headers.get("Authorization"))
2021-10-15 14:08:27 +00:00
2022-02-04 08:50:57 +00:00
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and parent_post.id not in (37696,37697,37749,37833,37838) and not is_bot and not v.marseyawarded and AGENDAPOSTER_PHRASE not in body.lower() and len(body) > 10:
2021-10-15 14:08:27 +00:00
now = int(time.time())
cutoff = now - 60 * 60 * 24
2021-11-07 13:37:26 +00:00
similar_comments = g.db.query(Comment).filter(
2021-10-15 14:08:27 +00:00
Comment.author_id == v.id,
Comment.body.op(
'<->')(body) < app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"],
Comment.created_utc > cutoff
).all()
threshold = app.config["COMMENT_SPAM_COUNT_THRESHOLD"]
if v.age >= (60 * 60 * 24 * 7):
threshold *= 3
elif v.age >= (60 * 60 * 24):
threshold *= 2
if len(similar_comments) > threshold:
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
2021-12-20 20:03:59 +00:00
send_repeatable_notification(v.id, text)
2021-10-15 14:08:27 +00:00
v.ban(reason="Spamming.",
days=1)
for comment in similar_comments:
comment.is_banned = True
2021-11-05 14:40:14 +00:00
comment.ban_reason = "AutoJanny"
2021-10-15 14:08:27 +00:00
g.db.add(comment)
ma=ModAction(
2021-11-18 14:21:19 +00:00
user_id=AUTOJANNY_ID,
2021-10-15 14:08:27 +00:00
target_comment_id=comment.id,
kind="ban_comment",
2021-10-25 18:08:03 +00:00
_note="spam"
2021-10-15 14:08:27 +00:00
)
g.db.add(ma)
return {"error": "Too much spam!"}, 403
if len(body_html) > 20000: abort(400)
c = Comment(author_id=v.id,
parent_submission=parent_submission,
parent_comment_id=parent_comment_id,
2021-12-05 02:21:38 +00:00
top_comment_id=top_comment_id,
2021-10-15 14:08:27 +00:00
level=level,
2022-01-22 09:58:22 +00:00
over_18=parent_post.over_18 or request.values.get("over_18")=="true",
2021-10-15 14:08:27 +00:00
is_bot=is_bot,
app_id=v.client.application.id if v.client else None,
body_html=body_html,
2022-01-27 22:43:59 +00:00
body=body[:10000],
ghost=parent_post.ghost
2021-10-15 14:08:27 +00:00
)
c.upvotes = 1
g.db.add(c)
g.db.flush()
for option in options:
2021-11-18 14:21:19 +00:00
c_option = Comment(author_id=AUTOPOLLER_ID,
2021-10-15 14:08:27 +00:00
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
2021-12-07 23:18:06 +00:00
body_html=filter_emojis_only(option),
2022-01-22 09:58:22 +00:00
upvotes=0,
is_bot=True
2021-10-15 14:08:27 +00:00
)
g.db.add(c_option)
2022-02-07 11:39:26 +00:00
for choice in choices:
c_choice = Comment(author_id=AUTOCHOICE_ID,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
body_html=filter_emojis_only(choice),
upvotes=0,
is_bot=True
)
g.db.add(c_choice)
2021-10-15 14:08:27 +00:00
2022-01-03 04:08:46 +00:00
if request.host == 'pcmemes.net' and c.body.lower().startswith("based"):
2021-10-15 14:08:27 +00:00
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)
2022-01-27 22:43:59 +00:00
if level == 1: basedguy = get_account(parent_post.author_id)
2021-10-15 14:08:27 +00:00
else: basedguy = get_account(c.parent_comment.author_id)
basedguy.basedcount += 1
2021-11-08 12:39:24 +00:00
if pill:
if basedguy.pills: basedguy.pills += f", {pill.group(1)}"
else: basedguy.pills += f"{pill.group(1)}"
2021-10-15 14:08:27 +00:00
g.db.add(basedguy)
2021-11-08 12:39:24 +00:00
body2 = f"@{basedguy.username}'s Based Count has increased by 1. Their Based Count is now {basedguy.basedcount}."
2021-11-08 12:44:58 +00:00
if basedguy.pills: body2 += f"\n\nPills: {basedguy.pills}"
2021-11-08 12:39:24 +00:00
2022-01-11 19:46:50 +00:00
body_based_html = sanitize(body2)
2021-10-15 14:08:27 +00:00
2021-11-18 14:21:19 +00:00
c_based = Comment(author_id=BASEDBOT_ID,
2021-10-15 14:08:27 +00:00
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_based_html,
2022-01-27 22:43:59 +00:00
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
2021-10-15 14:08:27 +00:00
)
g.db.add(c_based)
g.db.flush()
n = Notification(comment_id=c_based.id, user_id=v.id)
g.db.add(n)
2022-02-03 06:39:02 +00:00
if parent_post.id not in (37696,37697,37749,37833,37838):
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in c.body.lower():
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
c.is_banned = True
c.ban_reason = "AutoJanny"
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
g.db.add(c)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
body = AGENDAPOSTER_MSG.format(username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
body_jannied_html = sanitize(body)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
c_jannied = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_jannied_html,
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
)
2022-02-03 06:39:02 +00:00
g.db.add(c_jannied)
g.db.flush()
2022-02-03 06:39:02 +00:00
n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n)
2022-02-07 15:07:46 +00:00
elif SITE_NAME == 'Drama' and 'nigg' in c.body.lower() and not v.nwordpass:
2022-02-03 06:39:02 +00:00
c.is_banned = True
c.ban_reason = "AutoJanny"
g.db.add(c)
2022-02-03 06:39:02 +00:00
c_jannied = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=no_pass_phrase,
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
g.db.add(c_jannied)
g.db.flush()
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
v.ban(reason="White people nonsense.", days=0.007)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
text = "Your account has been suspended for 10 minutes for the following reason:\n\n> Unsanctioned NWord"
send_repeatable_notification(v.id, text)
2021-10-27 20:38:10 +00:00
2022-02-03 06:39:02 +00:00
n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n)
2022-02-07 15:07:46 +00:00
if SITE_NAME == 'Drama' and len(c.body) >= 1000 and "<" not in body and "</blockquote>" not in body_html:
2021-10-27 20:38:10 +00:00
2022-02-03 06:39:02 +00:00
body = random.choice(LONGPOST_REPLIES)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
body_html2 = sanitize(body)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
c2 = Comment(author_id=LONGPOSTBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_html2,
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
g.db.add(c2)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
longpostbot = g.db.query(User).filter_by(id = LONGPOSTBOT_ID).one_or_none()
longpostbot.comment_count += 1
longpostbot.coins += 1
g.db.add(longpostbot)
g.db.flush()
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
n = Notification(comment_id=c2.id, user_id=v.id)
g.db.add(n)
2021-10-15 14:08:27 +00:00
2022-02-07 15:07:46 +00:00
if SITE_NAME == 'Drama' and random.random() < 0.001:
2022-02-03 06:39:02 +00:00
body = "zoz"
body_html2 = sanitize(body)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
c2 = Comment(author_id=ZOZBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c.id,
level=level+1,
is_bot=True,
body_html=body_html2,
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
g.db.add(c2)
g.db.flush()
n = Notification(comment_id=c2.id, user_id=v.id)
g.db.add(n)
2021-10-15 14:08:27 +00:00
2021-12-27 01:08:06 +00:00
2022-02-03 06:39:02 +00:00
body = "zle"
body_html2 = sanitize(body)
2021-10-15 14:08:27 +00:00
2021-10-27 20:38:10 +00:00
2022-02-03 06:39:02 +00:00
c3 = Comment(author_id=ZOZBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c2.id,
level=level+2,
is_bot=True,
body_html=body_html2,
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
)
2021-10-27 20:38:10 +00:00
2022-02-03 06:39:02 +00:00
g.db.add(c3)
g.db.flush()
body = "zozzle"
body_html2 = sanitize(body)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
c4 = Comment(author_id=ZOZBOT_ID,
parent_submission=parent_submission,
parent_comment_id=c3.id,
level=level+3,
is_bot=True,
body_html=body_html2,
top_comment_id=c.top_comment_id,
ghost=parent_post.ghost
)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
g.db.add(c4)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
zozbot = g.db.query(User).filter_by(id = ZOZBOT_ID).one_or_none()
zozbot.comment_count += 3
zozbot.coins += 3
g.db.add(zozbot)
2021-10-15 14:08:27 +00:00
2022-02-03 06:39:02 +00:00
if not v.shadowbanned:
notify_users = NOTIFY_USERS(body_html, v)
for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
2022-02-07 11:39:26 +00:00
if parent.author.id not in (v.id, BASEDBOT_ID, AUTOJANNY_ID, SNAPPY_ID, LONGPOSTBOT_ID, ZOZBOT_ID, AUTOPOLLER_ID, AUTOCHOICE_ID):
notify_users.add(parent.author.id)
2022-02-03 06:39:02 +00:00
for x in notify_users:
n = Notification(comment_id=c.id, user_id=x)
g.db.add(n)
if parent.author.id != v.id and PUSHER_ID:
if len(c.body) > 500: notifbody = c.body[:500] + '...'
2022-02-04 16:33:50 +00:00
else: notifbody = c.body
try:
beams_client.publish_to_interests(
interests=[f'{request.host}{parent.author.id}'],
publish_body={
'web': {
'notification': {
'title': f'New reply by @{c.author_name}',
'body': notifbody,
'deep_link': f'{SITE_FULL}/comment/{c.id}?context=8&read=true#context',
2022-02-05 23:24:54 +00:00
'icon': f'{SITE_FULL}/assets/images/{SITE_NAME}/icon.webp?a=1010',
2022-02-04 16:33:50 +00:00
}
2022-02-03 06:39:02 +00:00
},
2022-02-04 16:33:50 +00:00
'fcm': {
'notification': {
'title': f'New reply by @{c.author_name}',
'body': notifbody,
},
'data': {
'url': f'/comment/{c.id}?context=8&read=true#context',
}
2022-02-03 06:39:02 +00:00
}
2022-02-04 16:33:50 +00:00
},
)
except: pass
2022-02-03 06:39:02 +00:00
2021-10-15 14:08:27 +00:00
vote = CommentVote(user_id=v.id,
comment_id=c.id,
2021-11-30 14:18:16 +00:00
vote_type=1,
2021-10-15 14:08:27 +00:00
)
g.db.add(vote)
cache.delete_memoized(comment_idlist)
2021-11-06 15:52:48 +00:00
v.comment_count = g.db.query(Comment.id).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
2021-10-15 14:08:27 +00:00
g.db.add(v)
c.voted = 1
2022-01-17 11:47:30 +00:00
if v.id == PIZZASHILL_ID:
2022-01-14 11:53:38 +00:00
autovote = CommentVote(user_id=CARP_ID, comment_id=c.id, vote_type=1)
2022-01-11 19:46:50 +00:00
g.db.add(autovote)
2022-01-14 11:53:38 +00:00
autovote = CommentVote(user_id=AEVANN_ID, comment_id=c.id, vote_type=1)
g.db.add(autovote)
autovote = CommentVote(user_id=CRAT_ID, comment_id=c.id, vote_type=1)
g.db.add(autovote)
v.coins += 3
v.truecoins += 3
2022-01-11 19:46:50 +00:00
g.db.add(v)
2022-01-14 11:53:38 +00:00
c.upvotes += 3
2022-01-11 19:46:50 +00:00
g.db.add(c)
2022-01-17 11:47:30 +00:00
elif v.id == HIL_ID:
autovote = CommentVote(user_id=CARP_ID, comment_id=c.id, vote_type=1)
g.db.add(autovote)
v.coins += 1
v.truecoins += 1
g.db.add(v)
c.upvotes += 1
g.db.add(c)
2022-01-11 19:46:50 +00:00
2022-01-31 01:41:04 +00:00
if not v.rehab:
slots = Slots(g)
slots.check_for_slots_command(body, v, c)
2022-01-31 01:41:04 +00:00
blackjack = Blackjack(g)
blackjack.check_for_blackjack_commands(body, v, c)
treasure = Treasure(g)
treasure.check_for_treasure(body, c)
2022-01-31 00:58:08 +00:00
if not c.slots_result and not c.blackjack_result:
parent_post.comment_count += 1
g.db.add(parent_post)
2022-01-22 13:04:30 +00:00
g.db.commit()
2022-01-24 15:34:29 +00:00
2021-10-15 14:08:27 +00:00
if request.headers.get("Authorization"): return c.json
2022-01-30 21:19:59 +00:00
return render_template("comments.html", v=v, comments=[c], ajax=True)
2021-10-15 14:08:27 +00:00
@app.post("/edit_comment/<cid>")
2022-01-15 06:31:17 +00:00
@limiter.limit("1/second;30/minute;200/hour;1000/day")
2021-10-15 14:08:27 +00:00
@auth_required
def edit_comment(cid, v):
2021-11-11 19:14:11 +00:00
if v and v.patron:
2022-01-16 05:53:29 +00:00
if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413
elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413
2021-10-15 14:08:27 +00:00
c = get_comment(cid, v=v)
2022-01-22 09:58:22 +00:00
if c.author_id != v.id: abort(403)
2021-10-15 14:08:27 +00:00
2021-12-11 16:22:25 +00:00
body = request.values.get("body", "").strip()[:10000]
2021-12-10 19:53:16 +00:00
2022-01-27 21:26:20 +00:00
if len(body) < 1 and not (request.files.get("file") and request.headers.get("cf-ipcountry") != "T1"):
return {"error":"You have to actually type something!"}, 400
2021-10-27 00:37:34 +00:00
2021-12-30 05:47:09 +00:00
if body != c.body or request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
2021-10-28 22:33:08 +00:00
if v.marseyawarded:
2022-02-04 09:15:59 +00:00
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A))
2022-01-14 08:01:19 +00:00
if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 characters!"}, 403
2021-11-18 20:50:03 +00:00
2022-02-04 09:15:59 +00:00
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A):
2021-10-28 22:33:08 +00:00
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})')
2021-11-24 17:33:44 +00:00
2022-01-29 02:02:15 +00:00
if v.agendaposter and not v.marseyawarded:
2022-01-29 00:38:00 +00:00
body = torture_ap(body, v.username)
2021-11-24 17:49:17 +00:00
2021-12-03 23:34:03 +00:00
if not c.options:
2022-02-04 09:15:59 +00:00
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A):
2021-12-03 23:34:03 +00:00
body = body.replace(i.group(0), "")
c_option = Comment(author_id=AUTOPOLLER_ID,
parent_submission=c.parent_submission,
parent_comment_id=c.id,
level=c.level+1,
2021-12-07 23:18:06 +00:00
body_html=filter_emojis_only(i.group(1)),
2022-01-22 09:58:22 +00:00
upvotes=0,
is_bot=True
2021-12-03 23:34:03 +00:00
)
g.db.add(c_option)
2022-02-07 11:39:26 +00:00
if not c.choices:
for i in re.finditer('\s*##([^\$\n]+)##\s*', body, re.A):
body = body.replace(i.group(0), "")
c_choice = Comment(author_id=AUTOCHOICE_ID,
parent_submission=c.parent_submission,
parent_comment_id=c.id,
level=c.level+1,
body_html=filter_emojis_only(i.group(1)),
upvotes=0,
is_bot=True
)
g.db.add(c_choice)
2022-01-19 06:20:05 +00:00
body_html = sanitize(body, edit=True)
2021-10-15 14:08:27 +00:00
2022-02-04 09:15:59 +00:00
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403
2021-10-27 20:12:16 +00:00
2021-11-23 22:36:38 +00:00
if v.longpost:
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
elif v.bird:
if len(body) > 140 : return {"error":"You have to type less than 140 characters!"}, 403
2021-11-18 20:50:03 +00:00
2021-10-28 22:33:08 +00:00
bans = filter_comment_html(body_html)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
if bans:
ban = bans[0]
reason = f"Remove the {ban.domain} link from your comment and try again."
if ban.reason: reason += f" {ban.reason}"
2021-10-15 14:08:27 +00:00
2022-02-01 05:35:05 +00:00
return {'error': reason}, 400
2022-02-04 08:50:57 +00:00
if '!slots' not in body.lower() and '!blackjack' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():
2021-10-28 22:33:08 +00:00
now = int(time.time())
cutoff = now - 60 * 60 * 24
2021-10-22 23:50:00 +00:00
2021-10-28 22:33:08 +00:00
similar_comments = g.db.query(Comment
).filter(
Comment.author_id == v.id,
Comment.body.op(
'<->')(body) < app.config["SPAM_SIMILARITY_THRESHOLD"],
Comment.created_utc > cutoff
).all()
2021-10-22 23:50:00 +00:00
2021-10-28 22:33:08 +00:00
threshold = app.config["SPAM_SIMILAR_COUNT_THRESHOLD"]
if v.age >= (60 * 60 * 24 * 30):
threshold *= 4
elif v.age >= (60 * 60 * 24 * 7):
threshold *= 3
elif v.age >= (60 * 60 * 24):
threshold *= 2
2021-10-22 23:50:00 +00:00
2021-10-28 22:33:08 +00:00
if len(similar_comments) > threshold:
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
2021-12-20 20:03:59 +00:00
send_repeatable_notification(v.id, text)
2021-10-22 23:50:00 +00:00
2021-10-28 22:33:08 +00:00
v.ban(reason="Spamming.",
days=1)
2021-10-22 23:50:00 +00:00
2021-10-28 22:33:08 +00:00
for comment in similar_comments:
comment.is_banned = True
2021-11-05 14:40:14 +00:00
comment.ban_reason = "AutoJanny"
2021-10-28 22:33:08 +00:00
g.db.add(comment)
2021-10-22 23:50:00 +00:00
2021-10-28 22:33:08 +00:00
return {"error": "Too much spam!"}, 403
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
file=request.files["file"]
2021-12-18 02:59:40 +00:00
if file.content_type.startswith('image/'):
2022-01-24 23:40:34 +00:00
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(name)
url = process_image(name)
body += f"\n\n![]({url})"
2021-12-18 02:59:40 +00:00
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f:
2022-01-06 14:20:45 +00:00
try: url = requests.request("POST", "https://api.imgur.com/3/upload", headers={'Authorization': f'Client-ID {IMGUR_KEY}'}, files=[('video', f)]).json()['data']['link']
except: return {"error": "Imgur error"}, 400
2022-01-06 17:57:59 +00:00
if url.endswith('.'): url += 'mp4'
2021-12-18 04:48:10 +00:00
body += f"\n\n{url}"
2022-01-07 21:03:14 +00:00
else: return {"error": "Image/Video files only"}, 400
2021-12-18 02:59:40 +00:00
2022-01-19 06:20:05 +00:00
body_html = sanitize(body, edit=True)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
if len(body_html) > 20000: abort(400)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
c.body = body[:10000]
c.body_html = body_html
2021-10-15 14:08:27 +00:00
if v.agendaposter and not v.marseyawarded and AGENDAPOSTER_PHRASE not in c.body.lower():
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
c.is_banned = True
2021-11-03 16:15:06 +00:00
c.ban_reason = "AutoJanny"
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
g.db.add(c)
2021-10-15 14:08:27 +00:00
2022-01-18 11:19:32 +00:00
body = AGENDAPOSTER_MSG.format(username=v.username, type='comment', AGENDAPOSTER_PHRASE=AGENDAPOSTER_PHRASE)
2021-10-15 14:08:27 +00:00
2022-01-11 19:46:50 +00:00
body_jannied_html = sanitize(body)
2021-10-15 14:08:27 +00:00
2021-12-28 06:28:18 +00:00
c_jannied = Comment(author_id=NOTIFICATIONS_ID,
2021-10-28 22:33:08 +00:00
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,
2022-01-27 22:43:59 +00:00
top_comment_id=c.top_comment_id,
2022-02-01 23:19:41 +00:00
ghost=c.ghost
2021-10-28 22:33:08 +00:00
)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
g.db.add(c_jannied)
g.db.flush()
2021-10-15 14:08:27 +00:00
2022-02-01 04:37:10 +00:00
n = Notification(comment_id=c_jannied.id, user_id=v.id)
g.db.add(n)
2021-10-15 14:08:27 +00:00
2022-02-07 15:07:46 +00:00
elif SITE_NAME == 'Drama' and 'nigg' in c.body.lower() and not v.nwordpass:
2022-02-01 04:37:10 +00:00
2022-02-01 04:44:05 +00:00
c.is_banned = True
c.ban_reason = "AutoJanny"
g.db.add(c)
2022-02-01 04:37:10 +00:00
c_jannied = Comment(author_id=NOTIFICATIONS_ID,
parent_submission=c.parent_submission,
distinguish_level=6,
parent_comment_id=c.id,
level=c.level+1,
is_bot=True,
body_html=no_pass_phrase,
top_comment_id=c.top_comment_id,
2022-02-01 23:19:41 +00:00
ghost=c.ghost
2022-02-01 04:37:10 +00:00
)
g.db.add(c_jannied)
g.db.flush()
2022-02-01 04:44:05 +00:00
v.ban(reason="White people nonsense.", days=0.007)
2022-02-01 04:37:10 +00:00
2022-02-01 04:44:05 +00:00
text = "Your account has been suspended for 10 minutes for the following reason:\n\n> Unsanctioned NWord"
2022-02-01 04:37:10 +00:00
send_repeatable_notification(v.id, text)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
n = Notification(comment_id=c_jannied.id, user_id=v.id)
2022-02-01 04:37:10 +00:00
g.db.add(n)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
if int(time.time()) - c.created_utc > 60 * 3: c.edited_utc = int(time.time())
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
g.db.add(c)
2021-12-29 06:43:20 +00:00
notify_users = NOTIFY_USERS(body_html, v)
2021-12-26 02:29:01 +00:00
2021-11-13 14:21:53 +00:00
for x in notify_users:
2022-01-02 00:06:46 +00:00
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
2021-11-13 14:21:53 +00:00
if not notif:
n = Notification(comment_id=c.id, user_id=x)
g.db.add(n)
2021-10-15 14:08:27 +00:00
2021-10-28 22:33:08 +00:00
g.db.commit()
2021-10-15 14:08:27 +00:00
2022-01-19 14:08:45 +00:00
return c.realbody(v)
2021-10-15 14:08:27 +00:00
@app.post("/delete/comment/<cid>")
2022-01-15 06:31:17 +00:00
@limiter.limit("1/second;30/minute;200/hour;1000/day")
2021-10-15 14:08:27 +00:00
@auth_required
def delete_comment(cid, v):
2022-01-02 00:06:46 +00:00
c = g.db.query(Comment).filter_by(id=cid).one_or_none()
2021-10-15 14:08:27 +00:00
if not c: abort(404)
2022-01-22 09:58:22 +00:00
if c.author_id != v.id: abort(403)
2021-10-15 14:08:27 +00:00
c.deleted_utc = int(time.time())
g.db.add(c)
cache.delete_memoized(comment_idlist)
g.db.commit()
return {"message": "Comment deleted!"}
@app.post("/undelete/comment/<cid>")
2022-01-15 06:31:17 +00:00
@limiter.limit("1/second;30/minute;200/hour;1000/day")
2021-10-15 14:08:27 +00:00
@auth_required
def undelete_comment(cid, v):
2022-01-02 00:06:46 +00:00
c = g.db.query(Comment).filter_by(id=cid).one_or_none()
2021-10-15 14:08:27 +00:00
2022-01-25 18:31:24 +00:00
if not c: abort(404)
2021-10-15 14:08:27 +00:00
2022-01-22 09:58:22 +00:00
if c.author_id != v.id:
2021-10-15 14:08:27 +00:00
abort(403)
c.deleted_utc = 0
g.db.add(c)
cache.delete_memoized(comment_idlist)
g.db.commit()
return {"message": "Comment undeleted!"}
@app.post("/pin_comment/<cid>")
@auth_required
2021-12-26 01:03:21 +00:00
def pin_comment(cid, v):
2021-10-15 14:08:27 +00:00
comment = get_comment(cid, v=v)
2022-01-25 18:31:24 +00:00
if not comment: abort(404)
2021-12-26 01:03:21 +00:00
if v.id != comment.post.author_id: abort(403)
comment.is_pinned = v.username + " (OP)"
2021-10-15 14:08:27 +00:00
g.db.add(comment)
2021-12-26 01:03:21 +00:00
if v.id != comment.author_id:
message = f"@{v.username} (OP) has pinned your [comment]({comment.permalink})!"
send_repeatable_notification(comment.author_id, message)
2021-10-15 14:08:27 +00:00
g.db.commit()
2021-12-26 01:03:21 +00:00
return {"message": "Comment pinned!"}
2021-10-15 14:08:27 +00:00
2021-12-26 01:03:21 +00:00
@app.post("/unpin_comment/<cid>")
@auth_required
def unpin_comment(cid, v):
2021-10-15 14:08:27 +00:00
2021-12-26 01:03:21 +00:00
comment = get_comment(cid, v=v)
2021-10-15 14:08:27 +00:00
2022-01-25 18:31:24 +00:00
if not comment: abort(404)
2021-12-26 01:03:21 +00:00
if v.id != comment.post.author_id: abort(403)
if not comment.is_pinned.endswith(" (OP)"):
return {"error": "You can only unpin comments you have pinned!"}
comment.is_pinned = None
g.db.add(comment)
if v.id != comment.author_id:
message = f"@{v.username} (OP) has unpinned your [comment]({comment.permalink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}
2022-02-11 23:32:14 +00:00
@app.post("/mod_pin/<cid>")
@auth_required
def mod_pin(cid, v):
comment = get_comment(cid, v=v)
if not comment: abort(404)
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
comment.is_pinned = v.username + " (Mod)"
g.db.add(comment)
if v.id != comment.author_id:
message = f"@{v.username} (Mod) has pinned your [comment]({comment.permalink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment pinned!"}
@app.post("/mod_unpin/<cid>")
@auth_required
def mod_unpin(cid, v):
comment = get_comment(cid, v=v)
if not comment: abort(404)
if not (comment.post.sub and v.mods(comment.post.sub)): abort(403)
comment.is_pinned = None
g.db.add(comment)
if v.id != comment.author_id:
message = f"@{v.username} (Mod) has unpinned your [comment]({comment.permalink})!"
send_repeatable_notification(comment.author_id, message)
g.db.commit()
return {"message": "Comment unpinned!"}
2021-10-15 14:08:27 +00:00
@app.post("/save_comment/<cid>")
2022-01-15 06:31:17 +00:00
@limiter.limit("1/second;30/minute;200/hour;1000/day")
2021-10-15 14:08:27 +00:00
@auth_required
def save_comment(cid, v):
comment=get_comment(cid)
2022-01-29 13:43:29 +00:00
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
2021-10-15 14:08:27 +00:00
if not save:
2022-01-29 13:43:29 +00:00
new_save=SaveRelationship(user_id=v.id, comment_id=comment.id)
2021-10-15 14:08:27 +00:00
g.db.add(new_save)
2021-11-15 22:49:48 +00:00
2021-10-15 14:08:27 +00:00
try: g.db.commit()
except: g.db.rollback()
return {"message": "Comment saved!"}
@app.post("/unsave_comment/<cid>")
2022-01-15 06:31:17 +00:00
@limiter.limit("1/second;30/minute;200/hour;1000/day")
2021-10-15 14:08:27 +00:00
@auth_required
def unsave_comment(cid, v):
comment=get_comment(cid)
2022-01-29 13:43:29 +00:00
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id).one_or_none()
2021-10-15 14:08:27 +00:00
if save:
g.db.delete(save)
g.db.commit()
return {"message": "Comment unsaved!"}
@app.post("/blackjack/<cid>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@auth_required
def handle_blackjack_action(cid, v):
comment = get_comment(cid)
action = request.values.get("action", "")
blackjack = Blackjack(g)
2022-02-04 17:41:32 +00:00
if action == 'hit':
blackjack.player_hit(comment)
elif action == 'stay':
blackjack.player_stayed(comment)
2022-01-31 01:57:33 +00:00
g.db.add(comment)
g.db.add(v)
g.db.commit()
return { "message" : "..." }