diff --git a/files/classes/user.py b/files/classes/user.py index 242a645d32..1cd03df48b 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 649335fea9..f28e364df8 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 db4fa81c9d..9b8f1de431 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 50da2ef43c..ae46d73284 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 d6b4f9af2a..bdd1c70c01 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 230829ce7a..9cdf7a9a88 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 cf46849fd6..afda87db90 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -23,11 +23,6 @@