diff --git a/files/assets/images/emojis/marseyemperor.webp b/files/assets/images/emojis/marseyemperor.webp index 3e01411e35..3dc3103810 100644 Binary files a/files/assets/images/emojis/marseyemperor.webp and b/files/assets/images/emojis/marseyemperor.webp differ diff --git a/files/assets/js/comments_v.js b/files/assets/js/comments_v.js index 2c48724149..aa75383123 100644 --- a/files/assets/js/comments_v.js +++ b/files/assets/js/comments_v.js @@ -16,8 +16,6 @@ function report_commentModal(id, author) { document.getElementById("comment-author").textContent = author; - document.getElementById("reportCommentFormBefore").classList.remove('d-none'); - reportCommentButton.innerHTML='Report comment'; reportCommentButton.disabled = false; reportCommentButton.classList.remove('disabled'); @@ -43,7 +41,6 @@ function report_commentModal(id, author) { try {data = JSON.parse(xhr.response)} catch(e) {console.log(e)} if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) { - document.getElementById("reportCommentFormBefore").classList.add('d-none'); document.getElementById('toast-post-success-text').innerText = data["message"]; bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show(); } else { diff --git a/files/assets/js/report_post_modal.js b/files/assets/js/report_post_modal.js index 421438d805..555599e748 100644 --- a/files/assets/js/report_post_modal.js +++ b/files/assets/js/report_post_modal.js @@ -13,7 +13,6 @@ reason_post.addEventListener('keydown', (e) => { function report_postModal(id) { - document.getElementById("reportPostFormBefore").classList.remove('d-none'); reportPostButton.disabled = false; reportPostButton.classList.remove('disabled'); reportPostButton.innerHTML='Report post'; @@ -41,7 +40,6 @@ function report_postModal(id) { try {data = JSON.parse(xhr.response)} catch(e) {console.log(e)} if (xhr.status >= 200 && xhr.status < 300 && data && data['message']) { - document.getElementById("reportPostFormBefore").classList.add('d-none'); document.getElementById('toast-post-success-text').innerText = data["message"]; bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success')).show(); } else { diff --git a/files/classes/alts.py b/files/classes/alts.py index 5e9bf1d8ae..1a0c11a3c4 100644 --- a/files/classes/alts.py +++ b/files/classes/alts.py @@ -1,6 +1,6 @@ from sqlalchemy import * from files.__main__ import Base - +import time class Alt(Base): __tablename__ = "alts" @@ -8,6 +8,11 @@ class Alt(Base): user1 = Column(Integer, ForeignKey("users.id"), primary_key=True) user2 = Column(Integer, ForeignKey("users.id"), primary_key=True) is_manual = Column(Boolean, default=False) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/classes/award.py b/files/classes/award.py index 4e2793ad9f..60b00664d8 100644 --- a/files/classes/award.py +++ b/files/classes/award.py @@ -3,6 +3,7 @@ from sqlalchemy.orm import relationship from files.__main__ import Base from files.helpers.lazy import lazy from files.helpers.const import * +import time class AwardRelationship(Base): @@ -15,11 +16,16 @@ class AwardRelationship(Base): kind = Column(String) awarded_utc = Column(Integer) granted = Column(Boolean) + created_utc = Column(Integer) user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards") post = relationship("Submission", primaryjoin="AwardRelationship.submission_id==Submission.id", back_populates="awards") comment = relationship("Comment", primaryjoin="AwardRelationship.comment_id==Comment.id", back_populates="awards") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" diff --git a/files/classes/badges.py b/files/classes/badges.py index 98fe6a3ff9..0fc6333f44 100644 --- a/files/classes/badges.py +++ b/files/classes/badges.py @@ -11,6 +11,11 @@ class BadgeDef(Base): id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String) description = Column(String) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" diff --git a/files/classes/category.py b/files/classes/category.py index 655e711d6d..c601bb1258 100644 --- a/files/classes/category.py +++ b/files/classes/category.py @@ -1,6 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class Category(Base): __tablename__ = "category" @@ -10,6 +11,14 @@ class Category(Base): sub = Column(String(20), ForeignKey("subs.name")) color_text = Column(String(6)) color_bg = Column(String(6)) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" def as_json(self): data = { diff --git a/files/classes/clients.py b/files/classes/clients.py index 2a767d3fde..12d753d472 100644 --- a/files/classes/clients.py +++ b/files/classes/clients.py @@ -18,9 +18,14 @@ class OauthApp(Base): redirect_uri = Column(String) description = Column(String) author_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) author = relationship("User", back_populates="apps") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" @@ -61,9 +66,14 @@ class ClientAuth(Base): user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) oauth_client = Column(Integer, ForeignKey("oauth_apps.id"), primary_key=True) access_token = Column(String) - + created_utc = Column(Integer) + user = relationship("User") application = relationship("OauthApp") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/domains.py b/files/classes/domains.py index 9047dbe76b..fb24316fed 100644 --- a/files/classes/domains.py +++ b/files/classes/domains.py @@ -1,11 +1,17 @@ from sqlalchemy import * from files.__main__ import Base +import time class BannedDomain(Base): __tablename__ = "banneddomains" domain = Column(String, primary_key=True) reason = Column(String) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/exiles.py b/files/classes/exiles.py index 16ba16bc55..9330840d0b 100644 --- a/files/classes/exiles.py +++ b/files/classes/exiles.py @@ -1,6 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class Exile(Base): @@ -8,8 +9,13 @@ class Exile(Base): user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String, ForeignKey("subs.name"), primary_key=True) exiler_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) exiler = relationship("User", primaryjoin="User.id==Exile.exiler_id") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/hats.py b/files/classes/hats.py index a65739a4c2..32824b7c38 100644 --- a/files/classes/hats.py +++ b/files/classes/hats.py @@ -4,6 +4,7 @@ from files.__main__ import Base from files.helpers.lazy import lazy from files.helpers.regex import censor_slurs from flask import g +import time class HatDef(Base): __tablename__ = "hat_defs" @@ -14,10 +15,18 @@ class HatDef(Base): author_id = Column(Integer, ForeignKey('users.id')) price = Column(Integer) submitter_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) author = relationship("User", primaryjoin="HatDef.author_id == User.id", back_populates="designed_hats") submitter = relationship("User", primaryjoin="HatDef.submitter_id == User.id") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" + @property @lazy def number_sold(self): @@ -33,10 +42,18 @@ class Hat(Base): user_id = Column(Integer, ForeignKey('users.id'), primary_key=True) hat_id = Column(Integer, ForeignKey('hat_defs.id'), primary_key=True) equipped = Column(Boolean, default=False) + created_utc = Column(Integer) hat_def = relationship("HatDef") owners = relationship("User", back_populates="owned_hats") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + + def __repr__(self): + return f"" + @property @lazy def name(self): diff --git a/files/classes/lottery.py b/files/classes/lottery.py index b05ece920f..8ea2fe1d1b 100644 --- a/files/classes/lottery.py +++ b/files/classes/lottery.py @@ -4,7 +4,6 @@ from files.__main__ import Base from files.helpers.lazy import lazy from files.helpers.const import * - class Lottery(Base): __tablename__ = "lotteries" @@ -14,6 +13,11 @@ class Lottery(Base): prize = Column(Integer, default=0) tickets_sold = Column(Integer, default=0) winner_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" diff --git a/files/classes/marsey.py b/files/classes/marsey.py index a5c88a7187..8a60a12a95 100644 --- a/files/classes/marsey.py +++ b/files/classes/marsey.py @@ -1,5 +1,6 @@ from sqlalchemy import * from files.__main__ import Base +import time class Marsey(Base): __tablename__ = "marseys" @@ -9,6 +10,11 @@ class Marsey(Base): tags = Column(String) count = Column(Integer, default=0) submitter_id = Column(Integer, ForeignKey("users.id")) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/polls.py b/files/classes/polls.py index 066b3006d5..1b90dba28b 100644 --- a/files/classes/polls.py +++ b/files/classes/polls.py @@ -12,10 +12,15 @@ class SubmissionOption(Base): submission_id = Column(Integer, ForeignKey("submissions.id")) body_html = Column(Text) exclusive = Column(Integer) + created_utc = Column(Integer) votes = relationship("SubmissionOptionVote") post = relationship("Submission", back_populates="options") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" @@ -57,10 +62,15 @@ class CommentOption(Base): comment_id = Column(Integer, ForeignKey("comments.id")) body_html = Column(Text) exclusive = Column(Integer) + created_utc = Column(Integer) votes = relationship("CommentOptionVote") comment = relationship("Comment", back_populates="options") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" diff --git a/files/classes/saves.py b/files/classes/saves.py index 6143395569..85a11afa2b 100644 --- a/files/classes/saves.py +++ b/files/classes/saves.py @@ -1,7 +1,7 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base - +import time class SaveRelationship(Base): @@ -9,9 +9,14 @@ class SaveRelationship(Base): user_id=Column(Integer, ForeignKey("users.id"), primary_key=True) submission_id=Column(Integer, ForeignKey("submissions.id"), primary_key=True) + created_utc = Column(Integer) post = relationship("Submission", uselist=False) + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" @@ -22,8 +27,13 @@ class CommentSaveRelationship(Base): user_id=Column(Integer, ForeignKey("users.id"), primary_key=True) comment_id=Column(Integer, ForeignKey("comments.id"), primary_key=True) + created_utc = Column(Integer) comment = relationship("Comment", uselist=False) + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/sub.py b/files/classes/sub.py index d9e4f8954f..97f3a54ad4 100644 --- a/files/classes/sub.py +++ b/files/classes/sub.py @@ -5,6 +5,7 @@ from files.helpers.lazy import lazy from os import environ from .sub_block import * from .sub_subscription import * +import time SITE_NAME = environ.get("SITE_NAME", '').strip() SITE = environ.get("DOMAIN", '').strip() @@ -21,10 +22,15 @@ class Sub(Base): marseyurl = Column(String) css = Column(String) stealth = Column(Boolean) + created_utc = Column(Integer) blocks = relationship("SubBlock", primaryjoin="SubBlock.sub==Sub.name") followers = relationship("SubSubscription", primaryjoin="SubSubscription.sub==Sub.name") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return self.name diff --git a/files/classes/sub_block.py b/files/classes/sub_block.py index cfdcad1415..6f8d387500 100644 --- a/files/classes/sub_block.py +++ b/files/classes/sub_block.py @@ -1,10 +1,16 @@ from sqlalchemy import * from files.__main__ import Base +import time class SubBlock(Base): __tablename__ = "sub_blocks" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/sub_join.py b/files/classes/sub_join.py index 7bb60780f8..b4ba7e23e8 100644 --- a/files/classes/sub_join.py +++ b/files/classes/sub_join.py @@ -1,10 +1,16 @@ from sqlalchemy import * from files.__main__ import Base +import time class SubJoin(Base): __tablename__ = "sub_joins" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/sub_subscription.py b/files/classes/sub_subscription.py index a82ffc8853..4f289f145a 100644 --- a/files/classes/sub_subscription.py +++ b/files/classes/sub_subscription.py @@ -1,10 +1,16 @@ from sqlalchemy import * from files.__main__ import Base +import time class SubSubscription(Base): __tablename__ = "sub_subscriptions" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) sub = Column(String(20), ForeignKey("subs.name"), primary_key=True) + created_utc = Column(Integer) + + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/subscriptions.py b/files/classes/subscriptions.py index debdad8824..dc2b9c27d2 100644 --- a/files/classes/subscriptions.py +++ b/files/classes/subscriptions.py @@ -1,16 +1,19 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class Subscription(Base): __tablename__ = "subscriptions" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True) - + created_utc = Column(Integer) + user = relationship("User", uselist=False) post = relationship("Submission", uselist=False) def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) super().__init__(*args, **kwargs) def __repr__(self): diff --git a/files/classes/user.py b/files/classes/user.py index 268bac9a4e..dca2d8a87a 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -475,9 +475,6 @@ class User(Base): def url(self): return f"/@{self.username}" - def __repr__(self): - return f"" - @property @lazy def unban_string(self): diff --git a/files/classes/userblock.py b/files/classes/userblock.py index b4c5ad3ac9..2dd5bd3e4d 100644 --- a/files/classes/userblock.py +++ b/files/classes/userblock.py @@ -1,15 +1,21 @@ from sqlalchemy import * from sqlalchemy.orm import relationship from files.__main__ import Base +import time class UserBlock(Base): __tablename__ = "userblocks" user_id = Column(Integer, ForeignKey("users.id"), primary_key=True) target_id = Column(Integer, ForeignKey("users.id"), primary_key=True) + created_utc = Column(Integer) user = relationship("User", primaryjoin="User.id==UserBlock.user_id", back_populates="blocking") target = relationship("User", primaryjoin="User.id==UserBlock.target_id", back_populates="blocked") + def __init__(self, *args, **kwargs): + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + super().__init__(*args, **kwargs) + def __repr__(self): return f"" \ No newline at end of file diff --git a/files/classes/views.py b/files/classes/views.py index 2b12f5695a..b3007003de 100644 --- a/files/classes/views.py +++ b/files/classes/views.py @@ -11,14 +11,13 @@ class ViewerRelationship(Base): user_id = Column(Integer, ForeignKey('users.id'), primary_key=True) viewer_id = Column(Integer, ForeignKey('users.id'), primary_key=True) last_view_utc = Column(Integer) + created_utc = Column(Integer) viewer = relationship("User", primaryjoin="ViewerRelationship.viewer_id == User.id") def __init__(self, **kwargs): - - if 'last_view_utc' not in kwargs: - kwargs['last_view_utc'] = int(time.time()) - + if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time()) + if 'last_view_utc' not in kwargs: kwargs['last_view_utc'] = int(time.time()) super().__init__(**kwargs) def __repr__(self): diff --git a/files/helpers/const.py b/files/helpers/const.py index ad0cc73bf1..7e42a189ef 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -182,6 +182,7 @@ BBBB_ID = 0 SCHIZO_ID = 0 KIPPY_ID = 0 MCCOX_ID = 0 +CHIOBU_ID = 0 PIZZASHILL_ID = 0 GUMROAD_MESSY = () PIZZA_VOTERS = () @@ -234,6 +235,7 @@ if SITE == 'rdrama.net': SCHIZO_ID = 8494 KIPPY_ID = 7150 MCCOX_ID = 8239 + CHIOBU_ID = 5214 PIZZASHILL_ID = 2424 GUMROAD_MESSY = (1230,1379) PIZZA_VOTERS = (747,1963,9712) @@ -853,6 +855,7 @@ NOTIFIED_USERS = { 'kippy': KIPPY_ID, 'mccox': MCCOX_ID, + 'chiobu': CHIOBU_ID, 'donger': DONGER_ID, 'soren': SOREN_ID, } diff --git a/files/routes/admin.py b/files/routes/admin.py index df34b50fe8..8f409fb17a 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -194,7 +194,7 @@ def remove_admin(v, username): @admin_level_required(3) def distribute(v, option_id): autojanny = get_account(AUTOJANNY_ID) - if autojanny.coins == 0: return {"error": "@AutoJanny has 0 coins"} + if autojanny.coins == 0: return {"error": "@AutoJanny has 0 coins"}, 400 try: option_id = int(option_id) except: abort(400) @@ -310,7 +310,7 @@ def club_allow(v, username): if not u: abort(404) - if u.admin_level >= v.admin_level: return {"error": "noob"} + if u.admin_level >= v.admin_level: return {"error": "noob"}, 400 u.club_allowed = True g.db.add(u) @@ -337,7 +337,7 @@ def club_ban(v, username): if not u: abort(404) - if u.admin_level >= v.admin_level: return {"error": "noob"} + if u.admin_level >= v.admin_level: return {"error": "noob"}, 400 u.club_allowed = False @@ -497,7 +497,7 @@ def purge_cache(v): g.db.add(ma) if response == "": return {"message": "Cache purged!"} - return {"error": "Failed to purge cache."} + return {"error": "Failed to purge cache."}, 400 @app.post("/admin/under_attack") @@ -514,7 +514,7 @@ def under_attack(v): response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"high"}', timeout=5)) if response == "": return {"message": "Under attack mode disabled!"} - return {"error": "Failed to disable under attack mode."} + return {"error": "Failed to disable under attack mode."}, 400 else: ma = ModAction( kind="enable_under_attack", @@ -524,7 +524,7 @@ def under_attack(v): response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}', timeout=5)) if response == "": return {"message": "Under attack mode enabled!"} - return {"error": "Failed to enable under attack mode."} + return {"error": "Failed to enable under attack mode."}, 400 @app.get("/admin/badge_grant") @admin_level_required(2) @@ -1156,7 +1156,7 @@ def approve_post(post_id, v): post = get_post(post_id) if post.author.id == v.id and post.author.agendaposter and AGENDAPOSTER_PHRASE not in post.body.lower() and post.sub != 'chudrama': - return {"error": "You can't bypass the chud award!"} + return {"error": "You can't bypass the chud award!"}, 400 if not post: abort(400) @@ -1351,7 +1351,7 @@ def approve_comment(c_id, v): if not comment: abort(404) if comment.author.id == v.id and comment.author.agendaposter and AGENDAPOSTER_PHRASE not in comment.body.lower() and comment.post.sub != 'chudrama': - return {"error": "You can't bypass the chud award!"} + return {"error": "You can't bypass the chud award!"}, 400 if comment.is_banned: ma=ModAction( diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index 27b4a274d2..0c32d62c40 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -86,7 +86,7 @@ def submit_marsey(v): filename = f'/asset_submissions/marseys/{name}.webp' copyfile(highquality, filename) - process_image(filename, resize=300, trim=True) + process_image(filename, resize=250, trim=True) marsey = Marsey(name=name, author_id=author.id, tags=tags, count=0, submitter_id=v.id) g.db.add(marsey) diff --git a/files/routes/awards.py b/files/routes/awards.py index 9c0608b888..8f7b91ccd5 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -460,7 +460,7 @@ def admin_userawards_post(v): for key, value in notify_awards.items(): note += f"{value} {AWARDS[key]['title']}, " - if len(note) > 500: return {"error": "You're giving too many awards at the same time!"} + if len(note) > 500: return {"error": "You're giving too many awards at the same time!"}, 400 ma=ModAction( kind="grant_awards", diff --git a/files/routes/casino.py b/files/routes/casino.py index 5a361a8e4b..cec14ee717 100644 --- a/files/routes/casino.py +++ b/files/routes/casino.py @@ -58,34 +58,34 @@ def casino_game_feed(v, game): @limiter.limit("100/minute;2000/hour;12000/day") @auth_required def pull_slots(v): - if v.rehab: return {"error": "You are under Rehab award effect!"} + if v.rehab: return {"error": "You are under Rehab award effect!"}, 400 try: wager = int(request.values.get("wager")) except: - return {"error": "Invalid wager."} + return {"error": "Invalid wager."}, 400 try: currency = request.values.get("currency") except: - return {"error": "Invalid currency (expected 'dramacoin' or 'marseybux')."} + return {"error": "Invalid currency (expected 'dramacoin' or 'marseybux')."}, 400 if (currency == "dramacoin" and wager > v.coins) or (currency == "marseybux" and wager > v.procoins): - return {"error": f"Not enough {currency} to make that bet."} + return {"error": f"Not enough {currency} to make that bet."}, 400 success, game_state = casino_slot_pull(v, wager, currency) if success: return {"game_state": game_state, "gambler": {"coins": v.coins, "procoins": v.procoins}} else: - return {"error": f"Wager must be more than 5 {currency}."} + return {"error": f"Wager must be more than 5 {currency}."}, 400 @app.post("/casino/twentyone/deal") @limiter.limit("100/minute;2000/hour;12000/day") @auth_required def blackjack_deal_to_player(v): - if v.rehab: return {"error": "You are under Rehab award effect!"} + if v.rehab: return {"error": "You are under Rehab award effect!"}, 400 try: wager = int(request.values.get("wager")) @@ -103,53 +103,53 @@ def blackjack_deal_to_player(v): @limiter.limit("100/minute;2000/hour;12000/day") @auth_required def blackjack_player_hit(v): - if v.rehab: return {"error": "You are under Rehab award effect!"} + if v.rehab: return {"error": "You are under Rehab award effect!"}, 400 try: state = dispatch_action(v, BlackjackAction.HIT) feed = get_game_feed('blackjack') return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}} except: - return {"error": "Unable to hit."} + return {"error": "Unable to hit."}, 400 @app.post("/casino/twentyone/stay") @limiter.limit("100/minute;2000/hour;12000/day") @auth_required def blackjack_player_stay(v): - if v.rehab: return {"error": "You are under Rehab award effect!"} + if v.rehab: return {"error": "You are under Rehab award effect!"}, 400 try: state = dispatch_action(v, BlackjackAction.STAY) feed = get_game_feed('blackjack') return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}} except: - return {"error": "Unable to stay."} + return {"error": "Unable to stay."}, 400 @app.post("/casino/twentyone/double-down") @limiter.limit("100/minute;2000/hour;12000/day") @auth_required def blackjack_player_doubled_down(v): - if v.rehab: return {"error": "You are under Rehab award effect!"} + if v.rehab: return {"error": "You are under Rehab award effect!"}, 400 try: state = dispatch_action(v, BlackjackAction.DOUBLE_DOWN) feed = get_game_feed('blackjack') return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}} except: - return {"error": "Unable to double down."} + return {"error": "Unable to double down."}, 400 @app.post("/casino/twentyone/buy-insurance") @limiter.limit("100/minute;2000/hour;12000/day") @auth_required def blackjack_player_bought_insurance(v): - if v.rehab: return {"error": "You are under Rehab award effect!"} + if v.rehab: return {"error": "You are under Rehab award effect!"}, 400 try: state = dispatch_action(v, BlackjackAction.BUY_INSURANCE) feed = get_game_feed('blackjack') return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}} except: - return {"error": "Unable to buy insurance."} + return {"error": "Unable to buy insurance."}, 400 diff --git a/files/routes/comments.py b/files/routes/comments.py index 44acfb9578..f154d3a161 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -69,7 +69,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): 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()): - if request.headers.get("Authorization"): return {'error': 'This content is not suitable for some users and situations.'} + if request.headers.get("Authorization"): return {"error": 'This content is not suitable for some users and situations.'}, 403 else: return render_template("errors/nsfw.html", v=v) try: context = min(int(request.values.get("context", 0)), 8) @@ -149,7 +149,7 @@ def comment(v): if sub and v.exiled_from(sub): return {"error": f"You're exiled from /h/{sub}"}, 403 if sub in ('furry','vampire','racist','femboy') and not v.client and not v.house.lower().startswith(sub): - return {"error": f"You need to be a member of House {sub.capitalize()} to comment in /h/{sub}"} + return {"error": f"You need to be a member of House {sub.capitalize()} to comment in /h/{sub}"}, 400 if parent_post.club and not (v and (v.paid_dues or v.id == parent_post.author_id)): abort(403) @@ -196,7 +196,7 @@ def comment(v): oldname = f'/images/{time.time()}'.replace('.','') + '.webp' file.save(oldname) image = process_image(oldname) - if image == "": return {"error":"Image upload failed"} + if image == "": return {"error":"Image upload failed"}, 400 if v.admin_level > 2 and level == 1: if parent_post.id == SIDEBAR_THREAD: li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/sidebar'), @@ -796,7 +796,7 @@ def unpin_comment(cid, v): if v.id != comment.post.author_id: abort(403) if not comment.stickied.endswith(" (OP)"): - return {"error": "You can only unpin comments you have pinned!"} + return {"error": "You can only unpin comments you have pinned!"}, 400 comment.stickied = None g.db.add(comment) diff --git a/files/routes/discord.py b/files/routes/discord.py index ba9129145d..d481e23a28 100644 --- a/files/routes/discord.py +++ b/files/routes/discord.py @@ -9,7 +9,7 @@ import requests @is_not_permabanned def join_discord(v): - if v.shadowbanned: return {"error": "Internal server error"} + if v.shadowbanned: return {"error": "Internal server error"}, 400 now=int(time.time()) diff --git a/files/routes/hats.py b/files/routes/hats.py index a4e3499cfe..823005d823 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -38,13 +38,13 @@ def buy_hat(v, hat_id): if not FEATURES['HATS']: abort(404) try: hat_id = int(hat_id) - except: return {"error": "Hat not found!"} + except: return {"error": "Hat not found!"}, 400 hat = g.db.query(HatDef).filter_by(submitter_id=None, id=hat_id).one_or_none() - if not hat: return {"error": "Hat not found!"} + if not hat: return {"error": "Hat not found!"}, 400 existing = g.db.query(Hat).filter_by(user_id=v.id, hat_id=hat.id).one_or_none() - if existing: return {"error": "You already own this hat!"} + if existing: return {"error": "You already own this hat!"}, 400 if request.values.get("mb"): if v.procoins < hat.price: return {"error": "Not enough marseybux."}, 400 @@ -85,10 +85,10 @@ def equip_hat(v, hat_id): if not FEATURES['HATS']: abort(404) try: hat_id = int(hat_id) - except: return {"error": "Hat not found!"} + except: return {"error": "Hat not found!"}, 400 hat = g.db.query(Hat).filter_by(hat_id=hat_id, user_id=v.id).one_or_none() - if not hat: return {"error": "You don't own this hat!"} + if not hat: return {"error": "You don't own this hat!"}, 400 hat.equipped = True g.db.add(hat) @@ -101,10 +101,10 @@ def unequip_hat(v, hat_id): if not FEATURES['HATS']: abort(404) try: hat_id = int(hat_id) - except: return {"error": "Hat not found!"} + except: return {"error": "Hat not found!"}, 400 hat = g.db.query(Hat).filter_by(hat_id=hat_id, user_id=v.id).one_or_none() - if not hat: return {"error": "You don't own this hat!"} + if not hat: return {"error": "You don't own this hat!"}, 400 hat.equipped = False g.db.add(hat) diff --git a/files/routes/lottery.py b/files/routes/lottery.py index ab0da75a44..dfb87d207b 100644 --- a/files/routes/lottery.py +++ b/files/routes/lottery.py @@ -29,7 +29,7 @@ def lottery_start(v): @casino_required def lottery_buy(v): try: quantity = int(request.values.get("quantity")) - except: return {"error": "Invalid ticket quantity."} + except: return {"error": "Invalid ticket quantity."}, 400 success, message = purchase_lottery_tickets(v, quantity) lottery, participants = get_active_lottery_stats() diff --git a/files/routes/polls.py b/files/routes/polls.py index b681215d9d..0f3d7acf3e 100644 --- a/files/routes/polls.py +++ b/files/routes/polls.py @@ -19,10 +19,10 @@ def vote_option(option_id, v): sub = option.post.sub if sub in ('furry','vampire','racist','femboy') and not v.house.lower().startswith(sub): - return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"} + return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"}, 400 if option.exclusive == 2: - if v.coins < 200: return {"error": "You don't have 200 coins!"} + if v.coins < 200: return {"error": "You don't have 200 coins!"}, 400 v.coins -= 200 g.db.add(v) autojanny = get_account(AUTOJANNY_ID) @@ -35,7 +35,7 @@ def vote_option(option_id, v): SubmissionOptionVote.submission_id==option.submission_id, SubmissionOption.exclusive==option.exclusive).one_or_none() if vote: - if option.exclusive == 2: return {"error": "You already voted on this bet!"} + if option.exclusive == 2: return {"error": "You already voted on this bet!"}, 400 g.db.delete(vote) existing = g.db.query(SubmissionOptionVote).filter_by(option_id=option_id, user_id=v.id).one_or_none() @@ -85,7 +85,7 @@ def vote_option_comment(option_id, v): sub = option.comment.post.sub if sub in ('furry','vampire','racist','femboy') and not v.house.lower().startswith(sub): - return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"} + return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"}, 400 if option.exclusive: vote = g.db.query(CommentOptionVote).join(CommentOption).filter( diff --git a/files/routes/posts.py b/files/routes/posts.py index 9d67fb8adb..d83e727a85 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1241,7 +1241,7 @@ def pin_post(post_id, v): post = get_post(post_id) if post: - if v.id != post.author_id: return {"error": "Only the post author's can do that!"} + if v.id != post.author_id: return {"error": "Only the post author's can do that!"}, 400 post.is_pinned = not post.is_pinned g.db.add(post) @@ -1249,7 +1249,7 @@ def pin_post(post_id, v): if post.is_pinned: return {"message": "Post pinned!"} else: return {"message": "Post unpinned!"} - return {"error": "Post not found!"} + return {"error": "Post not found!"}, 400 extensions = ( diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 84636c1750..2131343908 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -21,13 +21,13 @@ def flag_post(pid, v): send_repeatable_notification(CARP_ID, f"reports on {post.permalink}") if v.is_muted: - return {"error": "You are forbidden from making reports."} + return {"error": "You are forbidden from making reports."}, 400 reason = reason[:100] reason = filter_emojis_only(reason) - if len(reason) > 350: return {"error": "Too long."} + if len(reason) > 350: return {"error": "Too long."}, 400 if reason.startswith('!') and (v.admin_level > 1 or post.sub and v.mods(post.sub)): post.flair = reason[1:] @@ -47,16 +47,16 @@ def flag_post(pid, v): sub_to = g.db.query(Sub).filter_by(name=sub_to).one_or_none() sub_to = sub_to.name if sub_to else None - if sub_from == sub_to: abort(400) + if sub_from == sub_to: {"error": f"Post is already in /h/{sub_to}"}, 400 if post.author.exiled_from(sub_to): - return {"error": f"User is exiled from this {HOLE_NAME}!"} + return {"error": f"User is exiled from this {HOLE_NAME}!"}, 400 if sub_to in ('furry','vampire','racist','femboy') and not v.client and not post.author.house.lower().startswith(sub_to): if v.id == post.author_id: - return {"error": f"You need to be a member of House {sub.capitalize()} to post in /h/{sub}"} + return {"error": f"You need to be a member of House {sub.capitalize()} to post in /h/{sub}"}, 403 else: - return {"error": f"@{post.author.username} needs to be a member of House {sub.capitalize()} for their post to be moved to /h/{sub}"} + return {"error": f"@{post.author.username} needs to be a member of House {sub.capitalize()} for their post to be moved to /h/{sub}"}, 400 post.sub = sub_to g.db.add(post) @@ -77,7 +77,8 @@ def flag_post(pid, v): return {"message": f"Post moved to /h/{post.sub}"} else: existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none() - if existing: return "", 409 + if existing: + return {"error": "You already reported this post!"}, 409 flag = Flag(post_id=post.id, user_id=v.id, reason=reason) g.db.add(flag) @@ -94,7 +95,8 @@ def flag_comment(cid, v): comment = get_comment(cid) existing = g.db.query(CommentFlag.comment_id).filter_by(user_id=v.id, comment_id=comment.id).one_or_none() - if existing: return "", 409 + if existing: + return {"error": "You already reported this comment!"}, 409 reason = request.values.get("reason", "").strip() @@ -106,7 +108,7 @@ def flag_comment(cid, v): reason = filter_emojis_only(reason) - if len(reason) > 350: return {"error": "Too long."} + if len(reason) > 350: return {"error": "Too long."}, 400 flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason) diff --git a/files/routes/search.py b/files/routes/search.py index f039e4a6da..0444d3b66f 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -72,10 +72,10 @@ def searchposts(v): if 'author' in criteria: posts = posts.filter(Submission.ghost == False) author = get_user(criteria['author']) - if not author: return {"error": "User not found"} + if not author: return {"error": "User not found"}, 400 if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye: if request.headers.get("Authorization"): - return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"} + return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}, 400 return render_template("search.html", v=v, query=query, @@ -202,17 +202,17 @@ def searchcomments(v): if 'post' in criteria: try: post = int(criteria['post']) - except: return {"error": f"Post with id {post} does not exist."} + except: return {"error": f"Post with id {post} does not exist."}, 400 comments = comments.filter(Comment.parent_submission == post) if 'author' in criteria: comments = comments.filter(Comment.ghost == False) author = get_user(criteria['author']) - if not author: return {"error": "User not found"} + if not author: return {"error": "User not found"}, 400 if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye: if request.headers.get("Authorization"): - return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"} + return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}, 400 return render_template("search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, next_exists=False, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them.") diff --git a/files/routes/settings.py b/files/routes/settings.py index c6c72d70e1..5763c93f09 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -258,7 +258,7 @@ def settings_profile_post(v): if theme: if theme in {"4chan","classic","classic_dark","coffee","dark","dramblr","light","midnight","transparent","tron","win98"}: if theme == "transparent" and not v.background: - return {"error": "You need to set a background to use the transparent theme!"} + return {"error": "You need to set a background to use the transparent theme!"}, 400 v.theme = theme if theme == "win98": v.themecolor = "30409f" updated = True @@ -581,12 +581,12 @@ def settings_css_get(v): @limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}') @auth_required def settings_css(v): - if v.agendaposter: return {"error": "Agendapostered users can't edit css!"} + if v.agendaposter: return {"error": "Agendapostered users can't edit css!"}, 400 css = request.values.get("css").strip().replace('\\', '').strip()[:4000] if ' -
- - + +
diff --git a/files/templates/notifications.html b/files/templates/notifications.html index 9ffbb4e1a9..fbeb0a2c2e 100644 --- a/files/templates/notifications.html +++ b/files/templates/notifications.html @@ -17,12 +17,12 @@