2021-10-18 20:46:57 +00:00
|
|
|
import time
|
2022-11-15 09:19:08 +00:00
|
|
|
from math import floor
|
|
|
|
from random import randint
|
2023-08-05 19:01:42 +00:00
|
|
|
from urllib.parse import parse_qs, urlencode, urlparse
|
2023-01-02 04:23:44 +00:00
|
|
|
from flask import g
|
2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
from sqlalchemy import Column, ForeignKey
|
2022-10-02 08:55:39 +00:00
|
|
|
from sqlalchemy.dialects.postgresql import TSVECTOR
|
2023-07-07 23:12:59 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
2022-11-15 09:19:08 +00:00
|
|
|
from sqlalchemy.schema import FetchedValue
|
|
|
|
from sqlalchemy.sql.sqltypes import *
|
|
|
|
|
|
|
|
from files.classes import Base
|
2022-12-11 23:44:34 +00:00
|
|
|
from files.helpers.config.const import *
|
2023-10-05 10:00:05 +00:00
|
|
|
from files.helpers.config.awards import *
|
2023-09-22 17:01:30 +00:00
|
|
|
from files.helpers.slurs_and_profanities import *
|
2021-08-04 15:35:10 +00:00
|
|
|
from files.helpers.lazy import lazy
|
2022-11-15 09:19:08 +00:00
|
|
|
from files.helpers.regex import *
|
2022-10-12 08:05:26 +00:00
|
|
|
from files.helpers.sorting_and_time import *
|
2024-02-12 07:14:19 +00:00
|
|
|
from files.helpers.bleach_body import *
|
2021-09-12 06:12:44 +00:00
|
|
|
|
2023-04-27 18:50:16 +00:00
|
|
|
from .saves import CommentSaveRelationship
|
2022-06-22 19:50:20 +00:00
|
|
|
|
2023-12-25 01:18:48 +00:00
|
|
|
def get_emoji_awards_emojis(obj, v, kind, NSFW_EMOJIS):
|
2023-10-08 22:42:05 +00:00
|
|
|
if g.show_nsfw:
|
|
|
|
emojis = [x.note for x in obj.awards if x.kind == kind]
|
|
|
|
else:
|
2023-12-25 01:18:48 +00:00
|
|
|
emojis = [x.note for x in obj.awards if x.kind == kind and x.note not in NSFW_EMOJIS]
|
2023-10-08 22:42:05 +00:00
|
|
|
return reversed(emojis[:20])
|
|
|
|
|
2023-10-02 08:05:30 +00:00
|
|
|
def get_award_classes(obj, v, title=False):
|
|
|
|
classes = []
|
|
|
|
|
2023-10-05 17:57:18 +00:00
|
|
|
if not (v and v.poor):
|
|
|
|
if obj.award_count('glowie', v):
|
|
|
|
classes.append("glow")
|
2023-10-06 17:39:27 +00:00
|
|
|
if obj.award_count('gold', v):
|
|
|
|
classes.append("gold-text")
|
2023-10-05 17:57:18 +00:00
|
|
|
if obj.rainbowed:
|
|
|
|
classes.append("rainbow-text")
|
|
|
|
if obj.queened:
|
|
|
|
classes.append("queen")
|
|
|
|
if obj.sharpened:
|
|
|
|
classes.append(f"sharpen")
|
|
|
|
if not title: classes.append(f"chud-img sharpen-{obj.id_last_num}")
|
|
|
|
|
2023-10-02 08:05:30 +00:00
|
|
|
if obj.chudded:
|
|
|
|
classes.append("text-uppercase")
|
|
|
|
if not title: classes.append(f"chud-img chud-{obj.id_last_num}")
|
|
|
|
|
|
|
|
if IS_HOMOWEEN():
|
|
|
|
if obj.award_count('ectoplasm', v):
|
|
|
|
classes.append("ectoplasm")
|
2023-12-18 18:29:45 +00:00
|
|
|
if obj.award_count('candycorn', v):
|
|
|
|
classes.append("candycorn")
|
2023-10-02 08:05:30 +00:00
|
|
|
if obj.award_count('stab', v) and isinstance(obj, Comment):
|
|
|
|
classes.append("blood")
|
|
|
|
|
2023-12-18 18:29:45 +00:00
|
|
|
if IS_FISTMAS():
|
|
|
|
if obj.award_count('candycane', v):
|
|
|
|
classes.append("candycane")
|
|
|
|
|
2023-10-02 08:05:30 +00:00
|
|
|
return ' '.join(classes)
|
|
|
|
|
2022-06-23 15:47:57 +00:00
|
|
|
def normalize_urls_runtime(body, v):
|
2023-09-08 22:41:17 +00:00
|
|
|
if v and v.reddit != 'old.reddit.com':
|
2022-08-13 08:26:33 +00:00
|
|
|
body = reddit_to_vreddit_regex.sub(rf'\1https://{v.reddit}/\2/', body)
|
2023-09-08 22:41:17 +00:00
|
|
|
|
2024-02-08 00:36:54 +00:00
|
|
|
if v and v.nitter:
|
|
|
|
body = twitter_to_nitter_regex.sub(r'\1https://nitter.unixfox.eu/', body)
|
|
|
|
|
2023-10-12 14:20:28 +00:00
|
|
|
if v and v.imgsed:
|
2024-01-12 08:16:39 +00:00
|
|
|
body = instagram_to_imgsed_regex.sub(r'\1https://imgsed.com/', body)
|
2023-09-08 22:41:17 +00:00
|
|
|
|
|
|
|
if not v or v.controversial:
|
|
|
|
captured = []
|
|
|
|
for i in controversial_regex.finditer(body):
|
|
|
|
if i.group(0) in captured: continue
|
|
|
|
captured.append(i.group(0))
|
|
|
|
|
|
|
|
url = i.group(0)
|
|
|
|
p = urlparse(url).query
|
|
|
|
p = parse_qs(p, keep_blank_values=True)
|
|
|
|
|
|
|
|
if 'sort' not in p:
|
|
|
|
p['sort'] = ['controversial']
|
|
|
|
|
|
|
|
url_noquery = url.split('?')[0]
|
|
|
|
body = body.replace(f'{url}', f'{url_noquery}?{urlencode(p, True)}')
|
|
|
|
|
2022-06-23 15:47:57 +00:00
|
|
|
return body
|
|
|
|
|
2023-03-12 17:36:35 +00:00
|
|
|
|
|
|
|
def add_options(self, body, v):
|
2023-08-14 19:09:51 +00:00
|
|
|
if 'details>' in body or 'summary>' in body:
|
2023-08-15 16:40:19 +00:00
|
|
|
return body
|
2023-08-14 19:09:51 +00:00
|
|
|
|
2023-03-12 17:36:35 +00:00
|
|
|
if isinstance(self, Comment):
|
|
|
|
kind = 'comment'
|
|
|
|
else:
|
|
|
|
kind = 'post'
|
|
|
|
|
|
|
|
if self.options:
|
|
|
|
curr = [x for x in self.options if x.exclusive and x.voted(v)]
|
2023-08-12 11:12:50 +00:00
|
|
|
if curr: curr = f" value=option-{kind}-" + str(curr[0].id)
|
2023-03-12 17:36:35 +00:00
|
|
|
else: curr = ''
|
2023-08-12 11:12:50 +00:00
|
|
|
body += f'<input class="d-none" id="current-option-{kind}-{self.id}"{curr}>'
|
2023-03-12 17:36:35 +00:00
|
|
|
winner = [x for x in self.options if x.exclusive == 3]
|
|
|
|
|
|
|
|
for o in self.options:
|
|
|
|
option_body = ''
|
|
|
|
|
|
|
|
if o.exclusive > 1:
|
2023-08-03 06:50:22 +00:00
|
|
|
option_body += f'''<div class="custom-control mt-2"><input name="option-{self.id}" autocomplete="off" class="custom-control-input bet" type="radio" id="{o.id}" data-nonce="{g.nonce}" data-onclick="option_vote_2(this,'{o.id}','{kind}')"'''
|
2023-03-12 17:36:35 +00:00
|
|
|
if o.voted(v): option_body += " checked "
|
2023-03-13 16:44:21 +00:00
|
|
|
|
|
|
|
if not (v and v.coins + v.marseybux >= POLL_BET_COINS) or self.total_bet_voted(v):
|
|
|
|
option_body += " disabled "
|
2023-03-12 17:36:35 +00:00
|
|
|
|
|
|
|
option_body += f'''><label class="custom-control-label" for="{o.id}">{o.body_html}<span class="presult-{self.id}'''
|
|
|
|
option_body += f'"> - <a href="/votes/{kind}/option/{o.id}"><span id="option-{o.id}">{o.upvotes}</span> bets</a>'
|
|
|
|
if not self.total_bet_voted(v):
|
|
|
|
option_body += f'''<span class="cost"> (cost of entry: {POLL_BET_COINS} coins or marseybux)</span>'''
|
|
|
|
option_body += "</label>"
|
|
|
|
|
|
|
|
if o.exclusive == 3:
|
|
|
|
option_body += " - <b>WINNER!</b>"
|
|
|
|
|
|
|
|
if not winner and v and v.admin_level >= PERMS['POST_BETS_DISTRIBUTE']:
|
|
|
|
option_body += f'''<button class="btn btn-primary distribute" data-areyousure="postToastReload(this,'/distribute/{kind}/{o.id}')" data-nonce="{g.nonce}" data-onclick="areyousure(this)">Declare winner</button>'''
|
|
|
|
option_body += "</div>"
|
|
|
|
else:
|
|
|
|
input_type = 'radio' if o.exclusive else 'checkbox'
|
2023-08-12 11:12:50 +00:00
|
|
|
option_body += f'<div class="custom-control mt-2"><input type="{input_type}" class="custom-control-input" id="option-{kind}-{o.id}" name="option-{self.id}"'
|
2023-03-12 17:36:35 +00:00
|
|
|
if o.voted(v): option_body += " checked"
|
|
|
|
|
2023-07-27 00:37:13 +00:00
|
|
|
disabled = False
|
|
|
|
|
2023-03-12 17:36:35 +00:00
|
|
|
if v:
|
2023-03-12 18:02:50 +00:00
|
|
|
if kind == 'post':
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = self.hole
|
2023-06-23 13:46:42 +00:00
|
|
|
elif self.parent_post:
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = self.post.hole
|
2023-04-29 16:43:08 +00:00
|
|
|
else:
|
2023-10-07 17:55:50 +00:00
|
|
|
hole = None
|
2023-08-01 07:38:58 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if hole in {'furry','vampire','racist','femboy','edgy'} and not v.house.lower().startswith(hole):
|
2023-07-27 00:18:14 +00:00
|
|
|
disabled = True
|
2023-03-13 16:44:21 +00:00
|
|
|
option_body += ' disabled '
|
|
|
|
|
2023-08-03 06:50:22 +00:00
|
|
|
option_body += f''' data-nonce="{g.nonce}" data-onclick="option_vote_{o.exclusive}('{o.id}', '{self.id}', '{kind}')"'''
|
2023-03-12 17:36:35 +00:00
|
|
|
else:
|
2023-08-03 06:50:22 +00:00
|
|
|
option_body += f''' data-nonce="{g.nonce}" data-onclick="option_vote_no_v()"'''
|
2023-03-12 17:36:35 +00:00
|
|
|
|
2023-08-12 11:12:50 +00:00
|
|
|
option_body += f'''><label class="custom-control-label" for="option-{kind}-{o.id}">{o.body_html}<span class="presult-{self.id}'''
|
2023-07-27 00:18:14 +00:00
|
|
|
if not disabled and not self.total_poll_voted(v):
|
|
|
|
option_body += ' d-none'
|
2024-02-12 07:14:19 +00:00
|
|
|
option_body += f'"> - <a href="/votes/{kind}/option/{o.id}"><score id="score-option-{kind}-{o.id}">{o.upvotes}</score> votes</a></label></div>'''
|
2023-03-12 17:36:35 +00:00
|
|
|
|
|
|
|
if o.exclusive > 1: s = '##'
|
|
|
|
elif o.exclusive: s = '&&'
|
|
|
|
else: s = '$$'
|
|
|
|
|
2023-06-24 18:54:36 +00:00
|
|
|
if f'{s}{o.body_html}{s}' in body:
|
|
|
|
body = body.replace(f'{s}{o.body_html}{s}', option_body, 1)
|
|
|
|
elif not o.created_utc or o.created_utc < 1677622270:
|
2023-03-12 17:36:35 +00:00
|
|
|
body += option_body
|
|
|
|
|
|
|
|
return body
|
2023-05-05 21:45:25 +00:00
|
|
|
|
2023-03-12 17:36:35 +00:00
|
|
|
|
2021-09-19 18:22:57 +00:00
|
|
|
class Comment(Base):
|
2021-07-21 01:12:26 +00:00
|
|
|
__tablename__ = "comments"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
author_id = Column(Integer, ForeignKey("users.id"))
|
2023-06-23 13:46:42 +00:00
|
|
|
parent_post = Column(Integer, ForeignKey("posts.id"))
|
2022-12-03 01:49:07 +00:00
|
|
|
wall_user_id = Column(Integer, ForeignKey("users.id"))
|
2022-09-19 20:40:33 +00:00
|
|
|
created_utc = Column(Integer)
|
2021-07-21 01:12:26 +00:00
|
|
|
edited_utc = Column(Integer, default=0)
|
|
|
|
is_banned = Column(Boolean, default=False)
|
2022-02-15 22:54:17 +00:00
|
|
|
ghost = Column(Boolean, default=False)
|
2022-06-25 00:11:00 +00:00
|
|
|
bannedfor = Column(String)
|
2022-11-05 02:12:17 +00:00
|
|
|
chuddedfor = Column(String)
|
2024-02-16 12:11:08 +00:00
|
|
|
distinguished = Column(Boolean, default=False)
|
2021-07-21 01:12:26 +00:00
|
|
|
deleted_utc = Column(Integer, default=0)
|
2022-02-13 11:02:44 +00:00
|
|
|
is_approved = Column(Integer, ForeignKey("users.id"))
|
2022-04-04 01:41:20 +00:00
|
|
|
level = Column(Integer, default=1)
|
2021-07-21 01:12:26 +00:00
|
|
|
parent_comment_id = Column(Integer, ForeignKey("comments.id"))
|
2021-12-05 02:21:38 +00:00
|
|
|
top_comment_id = Column(Integer)
|
2021-07-21 01:12:26 +00:00
|
|
|
is_bot = Column(Boolean, default=False)
|
2022-05-26 23:08:23 +00:00
|
|
|
stickied = Column(String)
|
|
|
|
stickied_utc = Column(Integer)
|
2023-12-04 13:41:42 +00:00
|
|
|
num_of_pinned_children = Column(Integer, default=0)
|
2022-02-12 23:10:29 +00:00
|
|
|
sentto = Column(Integer, ForeignKey("users.id"))
|
2021-07-25 23:49:53 +00:00
|
|
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
2021-10-29 16:22:51 +00:00
|
|
|
upvotes = Column(Integer, default=1)
|
2021-09-24 02:21:41 +00:00
|
|
|
downvotes = Column(Integer, default=0)
|
2021-11-30 14:18:16 +00:00
|
|
|
realupvotes = Column(Integer, default=1)
|
2021-11-06 17:30:39 +00:00
|
|
|
body = Column(String)
|
|
|
|
body_html = Column(String)
|
2022-10-02 09:11:26 +00:00
|
|
|
body_ts = Column(TSVECTOR(), server_default=FetchedValue())
|
2021-10-06 22:38:15 +00:00
|
|
|
ban_reason = Column(String)
|
2022-01-29 04:48:30 +00:00
|
|
|
treasure_amount = Column(String)
|
2022-10-30 00:36:23 +00:00
|
|
|
slots_result = Column(String)
|
2023-08-13 16:02:55 +00:00
|
|
|
ping_cost = Column(Integer, default=0)
|
2022-10-30 00:40:35 +00:00
|
|
|
blackjack_result = Column(String)
|
2022-10-30 00:36:23 +00:00
|
|
|
casino_game_id = Column(Integer, ForeignKey("casino_games.id"))
|
2023-06-23 13:14:23 +00:00
|
|
|
chudded = Column(Boolean, default=False)
|
2023-08-14 11:00:29 +00:00
|
|
|
rainbowed = Column(Boolean, default=False)
|
|
|
|
queened = Column(Boolean, default=False)
|
|
|
|
sharpened = Column(Boolean, default=False)
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2024-02-12 18:35:15 +00:00
|
|
|
if FEATURES['NSFW_MARKING']:
|
|
|
|
nsfw = Column(Boolean, default=False)
|
|
|
|
else:
|
|
|
|
nsfw = False
|
|
|
|
|
2022-07-02 06:48:04 +00:00
|
|
|
oauth_app = relationship("OauthApp")
|
2023-06-07 23:26:32 +00:00
|
|
|
post = relationship("Post", back_populates="comments")
|
2021-09-22 15:01:18 +00:00
|
|
|
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
2022-07-02 06:48:04 +00:00
|
|
|
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto")
|
2022-10-12 07:03:28 +00:00
|
|
|
parent_comment = relationship("Comment", remote_side=[id])
|
2022-07-02 06:48:04 +00:00
|
|
|
awards = relationship("AwardRelationship", order_by="AwardRelationship.awarded_utc.desc()", back_populates="comment")
|
2023-06-23 16:49:23 +00:00
|
|
|
reports = relationship("CommentReport", order_by="CommentReport.created_utc")
|
2022-07-02 06:48:04 +00:00
|
|
|
options = relationship("CommentOption", order_by="CommentOption.id")
|
2022-12-14 19:30:05 +00:00
|
|
|
casino_game = relationship("CasinoGame")
|
2022-12-03 01:49:07 +00:00
|
|
|
wall_user = relationship("User", primaryjoin="User.id==Comment.wall_user_id")
|
2022-06-29 07:22:18 +00:00
|
|
|
|
2022-09-19 20:40:33 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if "created_utc" not in kwargs:
|
|
|
|
kwargs["created_utc"] = int(time.time())
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
def __repr__(self):
|
2022-11-29 21:02:38 +00:00
|
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2023-03-05 22:50:06 +00:00
|
|
|
@property
|
2022-01-11 04:30:08 +00:00
|
|
|
@lazy
|
2023-03-05 22:50:06 +00:00
|
|
|
def top_comment(self):
|
2023-03-16 06:27:58 +00:00
|
|
|
return g.db.get(Comment, self.top_comment_id)
|
2022-02-07 11:39:26 +00:00
|
|
|
|
2021-12-27 02:09:06 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def controversial(self):
|
|
|
|
if self.downvotes > 5 and 0.25 < self.upvotes / self.downvotes < 4: return True
|
|
|
|
return False
|
|
|
|
|
2021-09-19 18:22:57 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def age_string(self):
|
2022-03-04 23:49:38 +00:00
|
|
|
notif_utc = self.__dict__.get("notif_utc")
|
2022-03-04 17:33:58 +00:00
|
|
|
|
|
|
|
if notif_utc: timestamp = notif_utc
|
2022-03-04 16:53:28 +00:00
|
|
|
elif self.created_utc: timestamp = self.created_utc
|
2022-03-02 00:05:30 +00:00
|
|
|
else: return None
|
2022-10-15 18:11:43 +00:00
|
|
|
return make_age_string(timestamp)
|
2021-09-19 18:22:57 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def edited_string(self):
|
2023-08-14 07:04:48 +00:00
|
|
|
if not self.edited_utc: return None
|
2022-10-15 18:11:43 +00:00
|
|
|
return make_age_string(self.edited_utc)
|
2021-09-19 18:22:57 +00:00
|
|
|
|
2022-02-05 17:51:42 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def score(self):
|
|
|
|
return self.upvotes - self.downvotes
|
2021-09-23 19:22:18 +00:00
|
|
|
|
2021-07-25 23:23:21 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def fullname(self):
|
2022-09-05 22:52:22 +00:00
|
|
|
return f"c_{self.id}"
|
2021-07-25 23:23:21 +00:00
|
|
|
|
2023-03-24 12:29:19 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def id_last_num(self):
|
|
|
|
return str(self.id)[-1]
|
|
|
|
|
2022-06-24 19:26:18 +00:00
|
|
|
@property
|
2021-07-30 05:23:17 +00:00
|
|
|
@lazy
|
|
|
|
def parent_fullname(self):
|
2022-09-05 22:52:22 +00:00
|
|
|
if self.parent_comment_id: return f"c_{self.parent_comment_id}"
|
2023-06-23 13:46:42 +00:00
|
|
|
elif self.parent_post: return f"p_{self.parent_post}"
|
2021-07-30 05:23:17 +00:00
|
|
|
|
2022-06-22 19:50:20 +00:00
|
|
|
@lazy
|
2023-07-08 13:32:14 +00:00
|
|
|
def replies(self, sort):
|
2022-07-02 10:44:05 +00:00
|
|
|
if self.replies2 != None:
|
|
|
|
return self.replies2
|
2022-10-12 07:03:28 +00:00
|
|
|
|
2023-12-04 13:41:42 +00:00
|
|
|
replies = g.db.query(Comment).filter_by(parent_comment_id=self.id).order_by(Comment.stickied, Comment.num_of_pinned_children.desc())
|
2023-06-23 13:46:42 +00:00
|
|
|
if not self.parent_post: sort='old'
|
2023-02-27 15:38:12 +00:00
|
|
|
return sort_objects(sort, replies, Comment).all()
|
2022-05-25 17:01:29 +00:00
|
|
|
|
2022-02-04 05:42:24 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
@property
|
|
|
|
def replies2(self):
|
2022-03-04 23:49:38 +00:00
|
|
|
return self.__dict__.get("replies2")
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
@replies2.setter
|
|
|
|
def replies2(self, value):
|
|
|
|
self.__dict__["replies2"] = value
|
|
|
|
|
2021-09-12 06:12:44 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def shortlink(self):
|
2022-12-05 03:01:50 +00:00
|
|
|
if self.wall_user_id:
|
2022-12-24 19:19:47 +00:00
|
|
|
return f"/@{self.wall_user.username}/wall/comment/{self.id}#context"
|
2024-02-11 16:45:00 +00:00
|
|
|
if self.parent_post:
|
|
|
|
return f"{self.post.shortlink}/{self.id}#context"
|
|
|
|
return f"/notification/{self.id}"
|
2021-09-12 06:12:44 +00:00
|
|
|
|
2022-01-28 21:44:32 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
2022-02-24 13:20:48 +00:00
|
|
|
def permalink(self):
|
2022-10-27 17:53:08 +00:00
|
|
|
return f"{SITE_FULL}{self.shortlink}"
|
2022-01-28 21:44:32 +00:00
|
|
|
|
2022-07-13 15:20:10 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def log_link(self):
|
2022-10-27 17:53:08 +00:00
|
|
|
return f"{SITE_FULL}/transfers/{self.id}"
|
2022-07-13 15:20:10 +00:00
|
|
|
|
2022-01-17 21:26:03 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
2022-12-29 14:20:27 +00:00
|
|
|
def more_comments(self):
|
2023-02-18 22:58:17 +00:00
|
|
|
if self.wall_user_id:
|
|
|
|
return f"/@{self.wall_user.username}/wall/comment/{self.id}?context=0#context"
|
2022-12-24 19:19:47 +00:00
|
|
|
return f"{self.post.permalink}/{self.id}?context=0#context"
|
2022-01-17 21:26:03 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
2022-02-17 07:12:38 +00:00
|
|
|
def author_name(self):
|
2023-10-26 23:21:55 +00:00
|
|
|
if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻'
|
2022-10-06 23:31:09 +00:00
|
|
|
return self.author.user_name
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2024-02-11 10:48:11 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def author_name_punish_modal(self):
|
|
|
|
if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻'
|
|
|
|
return self.author.username
|
|
|
|
|
2022-06-23 16:36:39 +00:00
|
|
|
@lazy
|
2022-06-27 02:14:53 +00:00
|
|
|
def award_count(self, kind, v):
|
2023-10-12 18:46:22 +00:00
|
|
|
if v and v.poor:
|
2023-10-05 09:47:21 +00:00
|
|
|
return 0
|
2023-08-23 05:59:25 +00:00
|
|
|
return len([x for x in self.awards if x.kind == kind])
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2023-06-08 00:49:37 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def json(self):
|
2021-07-21 01:12:26 +00:00
|
|
|
if self.is_banned:
|
2022-09-04 23:15:37 +00:00
|
|
|
data = {'is_banned': True,
|
2022-11-14 04:03:51 +00:00
|
|
|
'ban_reason': self.ban_reason,
|
2021-07-30 05:31:38 +00:00
|
|
|
'id': self.id,
|
2021-12-14 18:35:56 +00:00
|
|
|
'post': self.post.id if self.post else 0,
|
2021-07-21 01:12:26 +00:00
|
|
|
'level': self.level,
|
2021-07-25 23:23:21 +00:00
|
|
|
'parent': self.parent_fullname
|
2021-07-21 01:12:26 +00:00
|
|
|
}
|
2022-01-12 01:19:13 +00:00
|
|
|
elif self.deleted_utc:
|
2022-09-04 23:15:37 +00:00
|
|
|
data = {'deleted_utc': self.deleted_utc,
|
2021-07-30 05:31:38 +00:00
|
|
|
'id': self.id,
|
2021-12-14 18:35:56 +00:00
|
|
|
'post': self.post.id if self.post else 0,
|
2021-07-21 01:12:26 +00:00
|
|
|
'level': self.level,
|
2021-07-25 23:23:21 +00:00
|
|
|
'parent': self.parent_fullname
|
2021-07-21 01:12:26 +00:00
|
|
|
}
|
|
|
|
else:
|
2023-06-23 16:49:23 +00:00
|
|
|
reports = {}
|
|
|
|
for r in self.reports:
|
|
|
|
reports[r.user.username] = r.reason
|
2022-07-11 13:14:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
data = {
|
2022-07-11 13:14:34 +00:00
|
|
|
'id': self.id,
|
|
|
|
'level': self.level,
|
2023-07-08 13:33:12 +00:00
|
|
|
'author_id': '👻' if self.ghost else self.author_id,
|
2022-07-11 13:14:34 +00:00
|
|
|
'author_name': self.author_name,
|
|
|
|
'body': self.body,
|
|
|
|
'body_html': self.body_html,
|
|
|
|
'is_bot': self.is_bot,
|
|
|
|
'created_utc': self.created_utc,
|
|
|
|
'edited_utc': self.edited_utc or 0,
|
|
|
|
'is_banned': bool(self.is_banned),
|
|
|
|
'deleted_utc': self.deleted_utc,
|
2023-10-05 10:19:50 +00:00
|
|
|
'is_nsfw': self.nsfw,
|
2023-02-07 02:34:11 +00:00
|
|
|
'permalink': f'/comment/{self.id}#context',
|
2022-07-11 13:14:34 +00:00
|
|
|
'stickied': self.stickied,
|
2024-02-16 12:11:08 +00:00
|
|
|
'distinguished': self.distinguished,
|
2022-07-11 13:14:34 +00:00
|
|
|
'post_id': self.post.id if self.post else 0,
|
|
|
|
'score': self.score,
|
|
|
|
'upvotes': self.upvotes,
|
|
|
|
'downvotes': self.downvotes,
|
|
|
|
'is_bot': self.is_bot,
|
2023-06-23 16:49:23 +00:00
|
|
|
'reports': reports,
|
2023-07-08 13:33:12 +00:00
|
|
|
'replies': [x.id for x in self.replies(sort="old")]
|
2022-07-11 13:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if self.level >= 2: data['parent_comment_id'] = self.parent_comment_id
|
2021-07-21 01:12:26 +00:00
|
|
|
|
|
|
|
return data
|
|
|
|
|
2023-03-12 17:36:35 +00:00
|
|
|
@lazy
|
|
|
|
def total_bet_voted(self, v):
|
|
|
|
if "closed" in self.body.lower(): return True
|
|
|
|
if v:
|
|
|
|
for o in self.options:
|
|
|
|
if o.exclusive == 3: return True
|
|
|
|
if o.exclusive == 2 and o.voted(v): return True
|
|
|
|
return False
|
|
|
|
|
2022-11-11 19:02:57 +00:00
|
|
|
@lazy
|
|
|
|
def total_poll_voted(self, v):
|
|
|
|
if v:
|
2023-09-18 16:48:16 +00:00
|
|
|
if v.id == self.author_id:
|
|
|
|
return True
|
2022-11-11 19:02:57 +00:00
|
|
|
for o in self.options:
|
|
|
|
if o.voted(v): return True
|
|
|
|
return False
|
|
|
|
|
2022-06-23 16:36:39 +00:00
|
|
|
@lazy
|
2021-07-21 01:12:26 +00:00
|
|
|
def realbody(self, v):
|
2022-10-07 02:04:27 +00:00
|
|
|
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
|
2022-10-13 14:26:35 +00:00
|
|
|
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
|
2021-09-24 03:00:54 +00:00
|
|
|
|
2022-02-08 20:05:06 +00:00
|
|
|
body = self.body_html or ""
|
2021-08-21 11:06:28 +00:00
|
|
|
|
2023-03-12 17:36:35 +00:00
|
|
|
body = add_options(self, body, v)
|
2022-01-22 16:22:31 +00:00
|
|
|
|
2023-03-02 01:15:04 +00:00
|
|
|
if body:
|
2023-10-07 17:55:50 +00:00
|
|
|
if not (self.parent_post and self.post.hole == 'chudrama'):
|
2023-09-22 17:01:30 +00:00
|
|
|
body = censor_slurs_profanities(body, v)
|
2023-05-05 21:45:25 +00:00
|
|
|
|
2023-03-02 01:15:04 +00:00
|
|
|
body = normalize_urls_runtime(body, v)
|
|
|
|
|
2024-02-12 07:18:43 +00:00
|
|
|
body = bleach_body_html(body, runtime=True) #to stop slur filters and poll options being used as a vector for html/js injection
|
2024-02-12 07:14:19 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
return body
|
|
|
|
|
2022-06-23 16:36:39 +00:00
|
|
|
@lazy
|
2021-10-02 20:58:14 +00:00
|
|
|
def plainbody(self, v):
|
2022-10-06 00:57:08 +00:00
|
|
|
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
|
2022-10-13 14:26:35 +00:00
|
|
|
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
|
2021-10-02 20:58:14 +00:00
|
|
|
|
|
|
|
body = self.body
|
|
|
|
|
|
|
|
if not body: return ""
|
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
if not (self.parent_post and self.post.hole == 'chudrama'):
|
2023-09-26 15:37:07 +00:00
|
|
|
body = censor_slurs_profanities(body, v, True)
|
2022-10-06 22:34:25 +00:00
|
|
|
|
|
|
|
return body
|
2021-10-02 20:58:14 +00:00
|
|
|
|
2021-09-19 20:06:52 +00:00
|
|
|
@lazy
|
2023-08-05 10:08:19 +00:00
|
|
|
def collapse_for_user(self, v, comment_info, path=''):
|
2022-01-31 04:22:14 +00:00
|
|
|
if v and self.author_id == v.id: return False
|
2022-01-31 04:20:59 +00:00
|
|
|
|
2022-01-31 04:17:27 +00:00
|
|
|
if path == '/admin/removed/comments': return False
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2023-08-05 10:08:19 +00:00
|
|
|
if comment_info: return False
|
2022-06-22 16:25:11 +00:00
|
|
|
|
2023-10-05 10:19:50 +00:00
|
|
|
if self.nsfw and not (any(path.startswith(x) for x in ('/post/','/comment/','/h/')) and self.post.nsfw) and not g.show_nsfw:
|
2023-10-04 13:45:13 +00:00
|
|
|
return True
|
2021-07-21 01:12:26 +00:00
|
|
|
|
2021-11-12 14:06:22 +00:00
|
|
|
if self.is_banned: return True
|
2022-01-31 22:13:16 +00:00
|
|
|
|
2023-03-06 17:19:49 +00:00
|
|
|
if self.author.shadowbanned: return True
|
2022-11-13 22:13:14 +00:00
|
|
|
|
2022-01-31 22:13:16 +00:00
|
|
|
if v and v.filter_words and self.body and any(x in self.body for x in v.filter_words): return True
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2021-07-21 01:12:26 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2021-07-31 13:55:49 +00:00
|
|
|
def is_op(self): return self.author_id==self.post.author_id
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2021-07-27 00:16:30 +00:00
|
|
|
@lazy
|
2023-06-23 16:49:23 +00:00
|
|
|
def filtered_reports(self, v):
|
|
|
|
return [r for r in self.reports if not r.user.shadowbanned or (v and v.id == r.user_id) or (v and v.admin_level)]
|
2022-07-11 18:13:00 +00:00
|
|
|
|
|
|
|
@lazy
|
2023-06-23 16:49:23 +00:00
|
|
|
def active_reports(self, v):
|
|
|
|
return len(self.filtered_reports(v))
|
2022-07-11 18:13:00 +00:00
|
|
|
|
2022-10-30 00:40:35 +00:00
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def blackjack_html(self):
|
|
|
|
if not self.blackjack_result: return ''
|
|
|
|
|
|
|
|
split_result = self.blackjack_result.split('_')
|
|
|
|
blackjack_status = split_result[3]
|
|
|
|
player_hand = split_result[0].replace('X', '10')
|
|
|
|
dealer_hand = split_result[1].split('/')[0] if blackjack_status == 'active' else split_result[1]
|
|
|
|
dealer_hand = dealer_hand.replace('X', '10')
|
|
|
|
wager = int(split_result[4])
|
|
|
|
try: kind = split_result[5]
|
|
|
|
except: kind = "coins"
|
|
|
|
currency_kind = "Coins" if kind == "coins" else "Marseybux"
|
|
|
|
|
|
|
|
try: is_insured = split_result[6]
|
|
|
|
except: is_insured = "0"
|
|
|
|
|
|
|
|
body = f"<span id='blackjack-{self.id}' class='ml-2'><em>{player_hand} vs. {dealer_hand}</em>"
|
|
|
|
|
|
|
|
if blackjack_status == 'push':
|
|
|
|
body += f"<strong class='ml-2'>Pushed. Refunded {wager} {currency_kind}.</strong>"
|
|
|
|
elif blackjack_status == 'bust':
|
|
|
|
body += f"<strong class='ml-2'>Bust. Lost {wager} {currency_kind}.</strong>"
|
|
|
|
elif blackjack_status == 'lost':
|
|
|
|
body += f"<strong class='ml-2'>Lost {wager} {currency_kind}.</strong>"
|
|
|
|
elif blackjack_status == 'won':
|
|
|
|
body += f"<strong class='ml-2'>Won {wager} {currency_kind}.</strong>"
|
|
|
|
elif blackjack_status == 'blackjack':
|
|
|
|
body += f"<strong class='ml-2'>Blackjack! Won {floor(wager * 3/2)} {currency_kind}.</strong>"
|
|
|
|
|
|
|
|
if is_insured == "1":
|
2023-02-24 02:54:31 +00:00
|
|
|
body += " <em class='text-success'>Insured.</em>"
|
2022-10-30 00:40:35 +00:00
|
|
|
|
|
|
|
body += '</span>'
|
|
|
|
return body
|
2023-04-27 18:50:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
|
|
|
def num_savers(self):
|
|
|
|
return g.db.query(CommentSaveRelationship).filter_by(comment_id=self.id).count()
|
2023-10-02 08:05:30 +00:00
|
|
|
|
|
|
|
@lazy
|
2023-10-03 06:19:46 +00:00
|
|
|
def award_classes(self, v):
|
2023-10-02 08:05:30 +00:00
|
|
|
return get_award_classes(self, v)
|
2023-10-08 22:42:05 +00:00
|
|
|
|
|
|
|
@lazy
|
2023-12-25 01:18:48 +00:00
|
|
|
def emoji_awards_emojis(self, v, kind, NSFW_EMOJIS):
|
|
|
|
return get_emoji_awards_emojis(self, v, kind, NSFW_EMOJIS)
|
2023-10-15 13:54:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@lazy
|
2024-02-06 19:39:52 +00:00
|
|
|
def is_longpost(self):
|
2024-01-10 22:08:15 +00:00
|
|
|
return len(self.body) >= 2000
|
2023-12-03 22:41:16 +00:00
|
|
|
|
|
|
|
def pin_parents(self):
|
|
|
|
c = self
|
|
|
|
while c.level > 2:
|
|
|
|
c = c.parent_comment
|
2023-12-04 13:41:42 +00:00
|
|
|
c.num_of_pinned_children += 1
|
2023-12-03 22:41:16 +00:00
|
|
|
g.db.add(c)
|
|
|
|
|
|
|
|
def unpin_parents(self):
|
2023-12-04 13:41:42 +00:00
|
|
|
c = self
|
|
|
|
while c.level > 2:
|
|
|
|
c = c.parent_comment
|
|
|
|
c.num_of_pinned_children -= 1
|
|
|
|
if c.num_of_pinned_children < 0:
|
|
|
|
c.num_of_pinned_children = 0
|
2023-12-03 22:41:16 +00:00
|
|
|
g.db.add(c)
|