From 8a7aa2e25e41a53b8b8ba53ff626ce16d28873eb Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 18 Nov 2021 22:50:03 +0200 Subject: [PATCH] fdsfd --- files/classes/user.py | 1 + files/helpers/const.py | 16 ++++++++++++++++ files/routes/awards.py | 22 ++++++++++++++++++++++ files/routes/comments.py | 16 ++++++++++++++++ files/routes/posts.py | 23 +++++++++++++++++++++-- files/templates/authforms.html | 4 ++-- files/templates/award_modal.html | 5 ----- files/templates/comments.html | 2 +- files/templates/default.html | 4 ++-- files/templates/log.html | 4 ++-- files/templates/login_2fa.html | 2 +- files/templates/settings.html | 2 +- files/templates/settings2.html | 4 ++-- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submission.html | 2 +- files/templates/submit.html | 4 ++-- 17 files changed, 92 insertions(+), 23 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 242a645d3..1cd03df48 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -50,6 +50,7 @@ class User(Base): verified = Column(String) verifiedcolor = Column(String) marseyawarded = Column(Integer) + longpost = Column(Integer) email = deferred(Column(String)) css = deferred(Column(String)) profilecss = deferred(Column(String)) diff --git a/files/helpers/const.py b/files/helpers/const.py index 649335fea..f28e364df 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -194,6 +194,14 @@ AWARDS = { "color": "text-black", "price": 1000 }, + "longpost": { + "kind": "longpost", + "title": "Longpost", + "description": "Forces the recipient to make all posts/comments > 280 characters for 24 hours.", + "icon": "fas fa-book", + "color": "text-green", + "price": 1000 + }, "flairlock": { "kind": "flairlock", "title": "1-Day Flairlock", @@ -374,6 +382,14 @@ AWARDS2 = { "color": "text-black", "price": 1000 }, + "longpost": { + "kind": "longpost", + "title": "Longpost", + "description": "Forces the recipient to make all posts/comments > 280 characters for 24 hours.", + "icon": "fas fa-book", + "color": "text-green", + "price": 1000 + }, "flairlock": { "kind": "flairlock", "title": "1-Day Flairlock", diff --git a/files/routes/awards.py b/files/routes/awards.py index db4fa81c9..9b8f1de43 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -98,6 +98,16 @@ def shop(v): "price": 1000, "MB": True }, + "longpost": { + "kind": "longpost", + "title": "Longpost", + "description": "Forces the recipient to make all posts/comments > 280 characters for 24 hours.", + "icon": "fas fa-book", + "color": "text-green", + "owned": 0, + "price": 1000, + "MB": True + }, "flairlock": { "kind": "flairlock", "title": "1-Day Flairlock", @@ -264,6 +274,14 @@ def buy(v, award): "color": "text-black", "price": 1000 }, + "longpost": { + "kind": "longpost", + "title": "Longpost", + "description": "Forces the recipient to make all posts/comments > 280 characters for 24 hours.", + "icon": "fas fa-book", + "color": "text-green", + "price": 1000, + }, "flairlock": { "kind": "flairlock", "title": "1-Day Flairlock", @@ -519,6 +537,8 @@ def award_post(pid, v): g.db.add(new_badge) elif kind == "marsey": author.marseyawarded = time.time() + 86400 + elif kind == "longpost": + author.longpost = time.time() + 86400 elif kind == "eye": author.eye = True send_notification(995, f"@{v.username} bought {kind} award!") @@ -648,6 +668,8 @@ def award_comment(cid, v): g.db.add(new_badge) elif kind == "marsey": author.marseyawarded = time.time() + 86400 + elif kind == "longpost": + author.longpost = time.time() + 86400 elif kind == "eye": author.eye = True send_notification(995, f"@{v.username} bought {kind} award!") diff --git a/files/routes/comments.py b/files/routes/comments.py index 50da2ef43..ae46d7328 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -164,6 +164,12 @@ def api_comment(v): marregex = list(re.finditer("^(:!?m\w+:\s*)+$", body)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 + if v.longpost: + if time.time() > v.longpost: + v.longpost = None + g.db.add(v) + elif len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400 for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): @@ -188,6 +194,8 @@ def api_comment(v): if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))) > 0: return {"error":"You can only type marseys!"}, 403 + if v.longpost and len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + bans = filter_comment_html(body_html) if bans: @@ -609,6 +617,12 @@ def edit_comment(cid, v): marregex = list(re.finditer("^(:!?m\w+:\s*)+$", body)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 + if v.longpost: + if time.time() > v.longpost: + v.longpost = None + g.db.add(v) + elif len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') body_md = CustomRenderer().render(mistletoe.Document(body)) @@ -616,6 +630,8 @@ def edit_comment(cid, v): if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))) > 0: return {"error":"You can only type marseys!"}, 403 + if v.longpost and len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + bans = filter_comment_html(body_html) if bans: diff --git a/files/routes/posts.py b/files/routes/posts.py index d6b4f9af2..bdd1c70c0 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -234,6 +234,12 @@ def edit_post(pid, v): marregex = list(re.finditer("^(:!?m\w+:\s*)+$", body)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 + if v.longpost: + if time.time() > v.longpost: + v.longpost = None + g.db.add(v) + elif len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + if title != p.title: title_html = filter_title(title) if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html))) > 0: return {"error":"You can only type marseys!"}, 403 @@ -257,6 +263,9 @@ def edit_post(pid, v): p.body = body if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))) > 0: return {"error":"You can only type marseys!"}, 40 + + if v.longpost and len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + p.body_html = body_html if "rama" in request.host and "ivermectin" in body_html.lower(): @@ -518,8 +527,12 @@ def submit_post(v): title = request.values.get("title", "").strip() url = request.values.get("url", "").strip() title_html = filter_title(title) + body = request.values.get("body", "").strip() + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html))) > 0: return {"error":"You can only type marseys!"}, 40 + if v.longpost and len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + if url: if "/i.imgur.com/" in url: url = url.replace(".png", ".webp").replace(".jpg", ".webp").replace(".jpeg", ".webp") elif "/media.giphy.com/" in url or "/c.tenor.com/" in url: url = url.replace(".gif", ".webp") @@ -590,8 +603,6 @@ def submit_post(v): elif len(title) > 500: if request.headers.get("Authorization"): return {"error": "500 character limit for titles"}, 400 else: render_template("submit.html", v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.values.get("body", "")), 400 - - body = request.values.get("body", "").strip() if v.marseyawarded: if time.time() > v.marseyawarded: @@ -604,6 +615,12 @@ def submit_post(v): marregex = list(re.finditer("^(:!?m\w+:\s*)+$", body)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 + if v.longpost: + if time.time() > v.longpost: + v.longpost = None + g.db.add(v) + elif len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + dup = g.db.query(Submission).filter( Submission.author_id == v.id, Submission.deleted_utc == 0, @@ -685,6 +702,8 @@ def submit_post(v): if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))) > 0: return {"error":"You can only type marseys!"}, 400 + if v.longpost and len(body) < 280: return {"error":"You have to type more than 280 characters!"}, 403 + if len(body_html) > 20000: return {"error":"Submission body too long!"}, 400 bans = filter_comment_html(body_html) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 230829ce7..9cdf7a9a8 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,11 +15,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index cf46849fd..afda87db9 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -23,11 +23,6 @@
{{award.owned}} owned
{% endfor %} - - -
 
-
 
-
diff --git a/files/templates/comments.html b/files/templates/comments.html index 7b3600ec7..d580b8d26 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -27,7 +27,7 @@ {% if v %} {% include "award_modal.html" %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 9b7fd738d..a936d6141 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -254,12 +254,12 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} {% endblock %} diff --git a/files/templates/log.html b/files/templates/log.html index 27578e4b8..e9ebd9e0a 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -17,11 +17,11 @@ {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %}
diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 8bb2501e6..1da0240e5 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -12,7 +12,7 @@ 2-Step Login - {{'SITE_NAME' | app_config}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 82feeb1be..ccf9ca26d 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -55,7 +55,7 @@ - + {% if v.agendaposter %}{% elif v.css %}{% endif %} diff --git a/files/templates/settings2.html b/files/templates/settings2.html index c550f2b80..9c1000245 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -40,10 +40,10 @@ {% if v %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 7ca7bd668..3808260f3 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -36,7 +36,7 @@ - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 5cb8cb542..279cea875 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -31,7 +31,7 @@ - + diff --git a/files/templates/submission.html b/files/templates/submission.html index 371442e2c..7f88da0b5 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -146,7 +146,7 @@ {% if v %} - + {% include "award_modal.html" %} {% include "emoji_modal.html" %} {% include "gif_modal.html" %} diff --git a/files/templates/submit.html b/files/templates/submit.html index 182fb1012..5c69cb3ef 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -31,11 +31,11 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %}{% elif v.css %}{% endif %} {% else %} - + {% endif %} {% endblock %}