diff --git a/files/classes/badges.py b/files/classes/badges.py index 27937a82be..2ec4d5ee26 100644 --- a/files/classes/badges.py +++ b/files/classes/badges.py @@ -55,7 +55,7 @@ class Badge(Base): @property @lazy def path(self): - return f"/static/assets/images/badges/{self.name.replace(' ','%20')}.webp?a=4" + return f"/static/assets/images/badges/{self.name.replace(' ','%20')}.webp?a=5" @property @lazy diff --git a/files/classes/submission.py b/files/classes/submission.py index 4b5a1e8d3d..4326a55e11 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -68,7 +68,7 @@ class Submission(Base): @property @lazy def comments(self): - return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter_by(parent_submission=self.id) + return g.db.query(Comment.author_id, Comment.created_utc, Comment.id).filter(Submission.parent_submission == self.id, Submission.author_id.notin_((AUTOPOLLER_ID,AUTOBETTER_ID))) @property @lazy diff --git a/files/classes/user.py b/files/classes/user.py index 57df1c3c12..e2977dafdc 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -433,10 +433,10 @@ class User(Base): @property @lazy def profile_url(self): - if self.agendaposter: return f"https://{site}/static/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?a=202" + if self.agendaposter: return f"https://{site}/static/assets/images/defaultpictures/agendaposter/{random.randint(1, 50)}.webp?a=203" if self.profileurl: return self.profileurl if "rama" in site: return f"https://{site}/static/assets/images/defaultpictures/{random.randint(1, 150)}.webp?a=202" - return f"https://{site}/static/assets/images/default-profile-pic.webp?a=202" + return f"https://{site}/static/assets/images/default-profile-pic.webp?a=203" @lazy def json_popover(self, v): diff --git a/files/helpers/const.py b/files/helpers/const.py index 5976f5e6f7..1d7d67e8c1 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -141,7 +141,8 @@ if SITE == 'rdrama.net': AUTOPOLLER_ID = 6176 AUTOBETTER_ID = 7668 TAX_RECEIVER_ID = 995 - AUTO_UPVOTE_IDS = (2424,4245) + PIZZASHILL_ID = 2424 + HIL_ID = 4245 CRAT_ID = 747 IDIO_ID = 30 CARP_ID = 995 @@ -167,7 +168,8 @@ elif SITE == "pcmemes.net": AUTOPOLLER_ID = 3369 AUTOBETTER_ID = 1867 TAX_RECEIVER_ID = 1592 - AUTO_UPVOTE_IDS = () + PIZZASHILL_ID = 0 + HIL_ID = 0 CRAT_ID = 0 IDIO_ID = 0 CARP_ID = 0 @@ -193,7 +195,8 @@ else: AUTOPOLLER_ID = 6 AUTOBETTER_ID = 7 TAX_RECEIVER_ID = 8 - AUTO_UPVOTE_IDS = () + PIZZASHILL_ID = 0 + HIL_ID = 0 CRAT_ID = 0 IDIO_ID = 0 CARP_ID = 0 diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 62bf6c4ff3..6ed4086254 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -109,7 +109,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False): for i in re.finditer("
@((\w|-){1,25})", sanitized): u = get_user(i.group(1), graceful=True) if u: - sanitized = sanitized.replace(i.group(0), f'''
@{u.username}''') + sanitized = sanitized.replace(i.group(0), f'''
@{u.username}''', 1) else: sanitized = re.sub('(^|\s|\n|
)\/?((r|u)\/\w{3,25})', r'\1\2', sanitized)
@@ -118,9 +118,9 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False):
if u and (not g.v.any_block_exists(u) or g.v.admin_level > 1):
if noimages:
- sanitized = sanitized.replace(i.group(0), f'{i.group(1)}@{u.username}')
+ sanitized = sanitized.replace(i.group(0), f'{i.group(1)}@{u.username}', 1)
else:
- sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}@{u.username}''')
+ sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}@{u.username}''', 1)
for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))', sanitized):
diff --git a/files/routes/admin.py b/files/routes/admin.py
index e0b2ef440b..19f12588cd 100644
--- a/files/routes/admin.py
+++ b/files/routes/admin.py
@@ -58,6 +58,9 @@ def remove_admin(v, username):
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(3)
def distribute(v, comment):
+ autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none()
+ if autobetter.coins == 0: return {"error": "@AutoBetter has 0 coins"}
+
try: comment = int(comment)
except: abort(400)
post = g.db.query(Comment.parent_submission).filter_by(id=comment).one_or_none()[0]
@@ -67,6 +70,10 @@ def distribute(v, comment):
for option in post.bet_options: pool += option.upvotes
pool *= 200
+ autobetter.coins -= pool
+ if autobetter.coins < 0: autobetter.coins = 0
+ g.db.add(autobetter)
+
votes = g.db.query(CommentVote).filter_by(comment_id=comment)
coinsperperson = int(pool / votes.count())
@@ -76,11 +83,6 @@ def distribute(v, comment):
u.coins += coinsperperson
add_notif(cid, u.id)
- autobetter = g.db.query(User).filter_by(id=AUTOBETTER_ID).one_or_none()
- autobetter.coins -= pool
- if autobetter.coins < 0: return {"error": "Not enough coins in bool"}, 400
- g.db.add(autobetter)
-
cid = notif_comment(f"You lost the 200 coins you bet on [{post.permalink}]({post.permalink}) :marseylaugh:")
cids = [x.id for x in post.bet_options]
cids.remove(comment)
@@ -500,14 +502,11 @@ def users_list(v):
@admin_level_required(2)
def alt_votes_get(v):
- if not request.values.get("u1") or not request.values.get("u2"):
- return render_template("admin/alt_votes.html", v=v)
-
u1 = request.values.get("u1")
u2 = request.values.get("u2")
if not u1 or not u2:
- return redirect("/admin/alt_votes")
+ return render_template("admin/alt_votes.html", v=v)
u1 = get_user(u1)
u2 = get_user(u2)
diff --git a/files/routes/awards.py b/files/routes/awards.py
index 5abef536b2..f99c9a3417 100644
--- a/files/routes/awards.py
+++ b/files/routes/awards.py
@@ -356,7 +356,8 @@ def award_post(pid, v):
g.db.add(post.author)
g.db.commit()
- if request.referrer and len(request.referrer) > 1: return redirect(request.referrer)
+ if request.referrer and len(request.referrer) > 1 and (request.referrer.startswith('/') or request.referrer.startswith(request.host_url)):
+ return redirect(request.referrer)
else: return redirect("/")
@@ -540,7 +541,8 @@ def award_comment(cid, v):
g.db.add(c.author)
g.db.commit()
- if request.referrer and len(request.referrer) > 1: return redirect(request.referrer)
+ if request.referrer and len(request.referrer) > 1 and (request.referrer.startswith('/') or request.referrer.startswith(request.host_url)):
+ return redirect(request.referrer)
else: return redirect("/")
@app.get("/admin/awards")
diff --git a/files/routes/comments.py b/files/routes/comments.py
index 166c4ef3d0..ef3534d287 100644
--- a/files/routes/comments.py
+++ b/files/routes/comments.py
@@ -469,29 +469,32 @@ def api_comment(v):
if len(c.body) > 500: notifbody = c.body[:500] + '...'
else: notifbody = c.body
- beams_client.publish_to_interests(
- interests=[f'{request.host}{parent.author.id}'],
- publish_body={
- 'web': {
- 'notification': {
- 'title': f'New reply by @{v.username}',
- 'body': notifbody,
- 'deep_link': f'https://{site}/comment/{c.id}?context=9&read=true#context',
- 'icon': f'https://{request.host}/assets/images/{SITE_NAME}/icon.webp',
- }
- },
- 'fcm': {
- 'notification': {
- 'title': f'New reply by @{v.username}',
- 'body': notifbody,
+ try:
+ beams_client.publish_to_interests(
+ interests=[f'{request.host}{parent.author.id}'],
+ publish_body={
+ 'web': {
+ 'notification': {
+ 'title': f'New reply by @{v.username}',
+ 'body': notifbody,
+ 'deep_link': f'https://{site}/comment/{c.id}?context=9&read=true#context',
+ 'icon': f'https://{request.host}/assets/images/{SITE_NAME}/icon.webp',
+ }
},
- 'data': {
- 'url': f'comment/{c.id}?context=9&read=true#context',
+ 'fcm': {
+ 'notification': {
+ 'title': f'New reply by @{v.username}',
+ 'body': notifbody,
+ },
+ 'data': {
+ 'url': f'comment/{c.id}?context=9&read=true#context',
+ }
}
- }
- },
- )
-
+ },
+ )
+ except Exception as e:
+ print(e)
+ print(c.id)
vote = CommentVote(user_id=v.id,
@@ -512,7 +515,7 @@ def api_comment(v):
c.voted = 1
- if v.id in AUTO_UPVOTE_IDS:
+ if v.id == PIZZASHILL_ID:
autovote = CommentVote(user_id=CARP_ID, comment_id=c.id, vote_type=1)
g.db.add(autovote)
autovote = CommentVote(user_id=AEVANN_ID, comment_id=c.id, vote_type=1)
@@ -524,6 +527,14 @@ def api_comment(v):
g.db.add(v)
c.upvotes += 3
g.db.add(c)
+ 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)
g.db.commit()
diff --git a/files/routes/errors.py b/files/routes/errors.py
index 31a33760f2..9c36a9a404 100644
--- a/files/routes/errors.py
+++ b/files/routes/errors.py
@@ -13,13 +13,12 @@ def error_400(e):
@app.errorhandler(401)
def error_401(e):
- path = request.path
- qs = urlencode(dict(request.values))
- argval = quote(f"{path}?{qs}", safe='')
- output = f"/login?redirect={argval}"
-
if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": "401 Not Authorized"}, 401
- else: return redirect(output)
+ else:
+ path = request.path
+ qs = urlencode(dict(request.values))
+ argval = quote(f"{path}?{qs}", safe='')
+ return redirect(f"/login?redirect={argval}")
@app.errorhandler(403)
@@ -61,4 +60,6 @@ def error_500(e):
@app.post("/allow_nsfw")
def allow_nsfw():
session["over_18"] = int(time.time()) + 3600
- return redirect(request.values.get("redir", "/"))
\ No newline at end of file
+ redir = request.values.get("redir")
+ if redir and redir.startswith(request.host_url) or redir.startswith('/'): return redirect(redir)
+ return redirect('/')
\ No newline at end of file
diff --git a/files/routes/front.py b/files/routes/front.py
index de7a471beb..4d61f9c0ec 100644
--- a/files/routes/front.py
+++ b/files/routes/front.py
@@ -6,11 +6,6 @@ from files.classes.submission import Submission
defaulttimefilter = environ.get("DEFAULT_TIME_FILTER", "all").strip()
SITE_NAME = environ.get("SITE_NAME", "").strip()
-@app.get("/post/")
-@auth_required
-def slash_post(v):
- return redirect("/")
-
@app.post("/clear")
@auth_required
def clear(v):
@@ -123,7 +118,8 @@ def notifications(v):
@auth_desired
def front_all(v):
- if not v and request.path == "/" and not request.headers.get("Authorization"): return redirect(f"/logged_out{request.full_path}")
+ if not v and request.path == "/" and not request.headers.get("Authorization"):
+ return redirect(f"/logged_out{request.full_path}")
if v and request.path.startswith('/logged_out'): v = None
@@ -436,7 +432,7 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"):
elif sort == "controversial":
comments = comments.order_by(-1 * Comment.upvotes * Comment.downvotes * Comment.downvotes)
elif sort == "top":
- comments = comments.order_by(Comment.realupvotes.desc())
+ comments = comments.order_by(Comment.downvotes - Comment.upvotes)
elif sort == "bottom":
comments = comments.order_by(Comment.upvotes - Comment.downvotes)
@@ -466,4 +462,18 @@ def all_comments(v):
idlist = idlist[:25]
if request.headers.get("Authorization"): return {"data": [x.json for x in comments]}
- return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists)
\ No newline at end of file
+ return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists)
+
+
+@app.get("/transfers")
+@auth_required
+def transfers(v):
+
+ page = int(request.values.get("page", 1))
+
+ comments = g.db.query(Comment).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.parent_submission == None, Comment.distinguish_level == 6, Comment.body_html.like("% has transferred %"), Comment.created_utc == 0).offset(25 * (page - 1)).limit(26).all()
+
+ next_exists = len(comments) > 25
+ comments = comments[:25]
+
+ return render_template("transfers.html", v=v, page=page, comments=comments, standalone=True, next_exists=next_exists)
\ No newline at end of file
diff --git a/files/routes/login.py b/files/routes/login.py
index 0a44b9c615..ff479a9ec0 100644
--- a/files/routes/login.py
+++ b/files/routes/login.py
@@ -12,13 +12,14 @@ valid_password_regex = re.compile("^.{8,100}$")
@auth_desired
def login_get(v):
- redir = request.values.get("redirect", "/").replace("/logged_out", "").strip()
- if v:
- return redirect(redir)
+ redir = request.values.get("redirect")
+ if redir:
+ redir = redir.replace("/logged_out", "").strip()
+ if not redir.startswith(request.host_url) and not redir.startswith('/'): redir = None
- return render_template("login.html",
- failed=False,
- redirect=redir)
+ if v and redir: return redirect(redir)
+
+ return render_template("login.html", failed=False, redirect=redir)
def check_for_alts(current_id):
@@ -137,10 +138,13 @@ def login_post():
if account.id != PW_ID: check_for_alts(account.id)
- redir = request.values.get("redirect", "/").replace("/logged_out", "").strip()
-
g.db.commit()
+ redir = request.values.get("redirect")
+ if redir:
+ redir = redir.replace("/logged_out", "").strip()
+ if not redir.startswith(request.host_url) and not redir.startswith('/'): redir = '/'
+
return redirect(redir)
diff --git a/files/routes/posts.py b/files/routes/posts.py
index 3618feda77..28b6700d81 100644
--- a/files/routes/posts.py
+++ b/files/routes/posts.py
@@ -96,7 +96,8 @@ def submit_get(v):
@app.get("/logged_out/post/ {% if u.quadrant %}{% endif %}{{u.customtitle | safe}} {% if u.quadrant %}{% endif %}{{u.customtitle | safe}} {% if u.quadrant %}{% endif %}{{u.customtitle | safe}} {% if u.quadrant %}{% endif %}{{u.customtitle | safe}}
+
{{v['name']}}
{{v['description']}}
diff --git a/files/templates/admin/badge_remove.html b/files/templates/admin/badge_remove.html
index 2bf7ad2c1f..c225978c38 100644
--- a/files/templates/admin/badge_remove.html
+++ b/files/templates/admin/badge_remove.html
@@ -60,7 +60,7 @@
-
+
{{v['name']}}
{{v['description']}}
diff --git a/files/templates/authforms.html b/files/templates/authforms.html
index 5645ac9048..e2632b5233 100644
--- a/files/templates/authforms.html
+++ b/files/templates/authforms.html
@@ -15,7 +15,7 @@
{% if v %}
-
+
{% if v.agendaposter %}
-
+
{% endif %}
@@ -111,7 +111,7 @@
-
+
diff --git a/files/templates/badges.html b/files/templates/badges.html
index 364ad22497..f244aab80b 100644
--- a/files/templates/badges.html
+++ b/files/templates/badges.html
@@ -21,7 +21,7 @@
{% for k,v in badges.items() %}
{% endfor %}
diff --git a/files/templates/comments.html b/files/templates/comments.html
index 07af7358df..f488fc9a50 100644
--- a/files/templates/comments.html
+++ b/files/templates/comments.html
@@ -149,8 +149,8 @@
{% if c.post and c.post.over_18 %}+18{% endif %}
{% if c.post %}
- {% if c.author_id==v.id and c.child_comments and is_notification_page%}
- Comment {{'Replies' if (c.child_comments | length)>1 else 'Reply'}}: {{c.post.realtitle(v) | safe}}
+ {% if c.author_id==v.id and replies and is_notification_page%}
+ Comment {{'Replies' if (replies | length)>1 else 'Reply'}}: {{c.post.realtitle(v) | safe}}
{% elif c.post.author_id==v.id and c.level == 1 and is_notification_page%}
Post Reply: {{c.post.realtitle(v) | safe}}
{% elif is_notification_page and c.parent_submission in v.subscribed_idlist() %}
@@ -217,7 +217,7 @@
{% endif %}
{{c.author.username}}
- {% if c.author.customtitle %} {% if c.author.quadrant %}{% endif %}{{c.author.customtitle | safe}}{% endif %}
+ {% if c.author.customtitle %} {% if c.author.quadrant %}{% endif %}{{c.author.customtitle | safe}}{% endif %}
{% if c.parent_comment_id and not standalone and level != 1 %}{{c.parent_comment.author.username}}{% endif %}
diff --git a/files/templates/default.html b/files/templates/default.html
index dca273a80a..53bbae16fd 100644
--- a/files/templates/default.html
+++ b/files/templates/default.html
@@ -7,7 +7,7 @@
{% if v %}
-
+
{% if v.agendaposter %}
-
+
{% endif %}
diff --git a/files/templates/emoji_modal.html b/files/templates/emoji_modal.html
index f4a851b352..16d4bcfe45 100644
--- a/files/templates/emoji_modal.html
+++ b/files/templates/emoji_modal.html
@@ -29,6 +29,9 @@
{{v['name']}}
-
+
{{v['description']}}
diff --git a/files/templates/patrons.html b/files/templates/patrons.html
index be02a72370..e2e36ab0cd 100644
--- a/files/templates/patrons.html
+++ b/files/templates/patrons.html
@@ -14,7 +14,7 @@
{{loop.index}}
{{k[0]}}
-
+
{{k[2]}}
{% if k[1] in ('anton-d','unknown') %}{{k[1]}}{% else %}{{k[1]}}{% endif %}
{{loop.index}}
{{u.username}}
-
+
{% endfor %}
diff --git a/files/templates/settings.html b/files/templates/settings.html
index a394ad030f..f3cb88500c 100644
--- a/files/templates/settings.html
+++ b/files/templates/settings.html
@@ -34,7 +34,7 @@
-
+
{% if v.agendaposter %}
-
+
{% else %}
-
+
{% endif %}
diff --git a/files/templates/sidebar_Drama.html b/files/templates/sidebar_Drama.html
index 984236bd0f..90128ab051 100644
--- a/files/templates/sidebar_Drama.html
+++ b/files/templates/sidebar_Drama.html
@@ -1,6 +1,6 @@
diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html
index a260ae1ddf..49af3aacd8 100644
--- a/files/templates/sign_up_failed_ref.html
+++ b/files/templates/sign_up_failed_ref.html
@@ -32,7 +32,7 @@