From de4e019abcc1b01d21a3f6a393093b28c5c6e3a3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 13 Feb 2022 23:25:09 +0200 Subject: [PATCH] sfd --- files/classes/comment.py | 2 +- files/routes/admin.py | 2 -- files/routes/awards.py | 14 ++------------ files/routes/comments.py | 4 ++-- files/routes/login.py | 8 ++++---- files/routes/posts.py | 6 +++--- files/routes/users.py | 20 ++++++-------------- files/templates/authforms.html | 4 ++-- files/templates/default.html | 4 ++-- files/templates/log.html | 4 ++-- files/templates/login.html | 2 +- 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/submit.html | 4 ++-- seed-db.sql | 2 -- snappy_Drama.txt | 2 ++ 19 files changed, 35 insertions(+), 55 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index afe6b44a7..05b0b505c 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -70,7 +70,7 @@ class Comment(Base): @property @lazy def top_comment(self): - return g.db.query(Comment).filter_by(id=self.top_comment_id).first() + return g.db.query(Comment).filter_by(id=self.top_comment_id).one_or_none() @property @lazy diff --git a/files/routes/admin.py b/files/routes/admin.py index 7afa93d74..81031dfed 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -263,8 +263,6 @@ def remove_meme_admin(v, username): def monthly(v): if SITE_NAME == 'Drama' and v.id != AEVANN_ID: abort (403) - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id - data = {'access_token': GUMROAD_TOKEN} emails = [x['email'] for x in requests.get(f'https://api.gumroad.com/v2/products/{GUMROAD_ID}/subscribers', data=data, timeout=5).json()["subscribers"]] diff --git a/files/routes/awards.py b/files/routes/awards.py index 9d57195bc..60d184b43 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -169,10 +169,8 @@ def buy(v, award): if award == "lootbox": send_repeatable_notification(995, f"@{v.username} bought a lootbox!") for i in [1,2,3,4,5]: - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id - thing += 1 award = random.choice(["snow", "gingerbread", "lights", "candycane", "fireplace"]) - award = AwardRelationship(id=thing, user_id=v.id, kind=award) + award = AwardRelationship(user_id=v.id, kind=award) g.db.add(award) g.db.flush() v.lootboxes_bought += 1 @@ -193,9 +191,7 @@ def buy(v, award): send_notification(v.id, f"@AutoJanny has given you the following profile badge:\n\n![]({new_badge.path})\n\n{new_badge.name}") else: - thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id - thing += 1 - award = AwardRelationship(id=thing, user_id=v.id, kind=award) + award = AwardRelationship(user_id=v.id, kind=award) g.db.add(award) g.db.add(v) @@ -692,9 +688,6 @@ def admin_userawards_post(v): notify_awards = {} - latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first() - thing = latest.id - for key, value in request.values.items(): if key not in AWARDS: continue @@ -705,10 +698,7 @@ def admin_userawards_post(v): if int(value): notify_awards[key] = int(value) for x in range(int(value)): - thing += 1 - award = AwardRelationship( - id=thing, user_id=u.id, kind=key ) diff --git a/files/routes/comments.py b/files/routes/comments.py index 7b6076af5..422416866 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -211,7 +211,7 @@ def api_comment(v): try: badge_def = loads(body) name = badge_def["name"] - badge = g.db.query(BadgeDef).filter_by(name=name).first() + badge = g.db.query(BadgeDef).filter_by(name=name).one_or_none() if not badge: badge = BadgeDef(name=name, description=badge_def["description"]) g.db.add(badge) @@ -229,7 +229,7 @@ def api_comment(v): if "author" in marsey: author_id = get_user(marsey["author"]).id elif "author_id" in marsey: author_id = marsey["author_id"] else: abort(400) - if not g.db.query(Marsey.name).filter_by(name=name).first(): + if not g.db.query(Marsey.name).filter_by(name=name).one_or_none(): marsey = Marsey(name=marsey["name"], author_id=author_id, tags=marsey["tags"], count=0) g.db.add(marsey) filename = f'files/assets/images/emojis/{name}.webp' diff --git a/files/routes/login.py b/files/routes/login.py index 2d0366be2..f0daeeb7a 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -87,7 +87,9 @@ def login_post(): if not username: abort(400) if username.startswith('@'): username = username[1:] - if "@" in username: account = g.db.query(User).filter(User.email.ilike(username)).one_or_none() + if "@" in username: + try: account = g.db.query(User).filter(User.email.ilike(username)).one_or_none() + except: return "Multiple users use this email!" else: account = get_user(username, graceful=True) if not account: @@ -117,9 +119,7 @@ def login_post(): return redirect(f'{SITE_FULL}/login') formhash = request.values.get("hash") - if not validate_hash(f"{account.id}+{request.values.get('time')}+2fachallenge", - formhash - ): + if not validate_hash(f"{account.id}+{request.values.get('time')}+2fachallenge", formhash): return redirect(f"{SITE_FULL}/login") if not account.validate_2fa(request.values.get("2fa_token", "").strip()): diff --git a/files/routes/posts.py b/files/routes/posts.py index 48cfd4991..cb164acae 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -734,7 +734,7 @@ def thumbnail_thread(pid): body_html = sanitize(f'New {word} mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) - existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).first() + existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).one_or_none() if existing_comment: break @@ -757,7 +757,7 @@ def thumbnail_thread(pid): for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={k}&size=1').json()["data"]: try: body_html = sanitize(f'New mention of you: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) except: continue - existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html).first() + existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html).one_or_none() if existing_comment: break new_comment = Comment(author_id=NOTIFICATIONS_ID, @@ -785,7 +785,7 @@ def thumbnail_thread(pid): for i in data: body_html = sanitize(f'New pcmemes mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) - existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).first() + existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).one_or_none() if existing_comment: break diff --git a/files/routes/users.py b/files/routes/users.py index c2ca4ba0a..c70dd246d 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -470,7 +470,7 @@ def message2(v, username): existing = g.db.query(Comment.id).filter(Comment.author_id == v.id, Comment.sentto == user.id, Comment.body_html == text_html, - ).first() + ).one_or_none() if existing: return {"error": "Message already exists."}, 403 @@ -699,19 +699,11 @@ def u_username(username, v=None): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": f"That username is reserved for: {u.reserved}"} return render_template("userpage_reserved.html", u=u, v=v) - if v and u.id != v.id: - view = g.db.query(ViewerRelationship).filter( - and_( - ViewerRelationship.viewer_id == v.id, - ViewerRelationship.user_id == u.id - ) - ).first() + if v and u.id != v.id and u.patron: + view = g.db.query(ViewerRelationship).filter_by(viewer_id=v.id, user_id=u.id).one_or_none() - if view: - view.last_view_utc = g.timestamp - else: - view = ViewerRelationship(user_id = u.id, - viewer_id = v.id) + if view: view.last_view_utc = g.timestamp + else: view = ViewerRelationship(viewer_id=v.id, user_id=u.id) g.db.add(view) g.db.commit() @@ -1054,7 +1046,7 @@ def fp(v, fp): users += alts for u in users: li = [v.id, u.id] - existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).first() + existing = g.db.query(Alt).filter(Alt.user1.in_(li), Alt.user2.in_(li)).one_or_none() if existing: continue new_alt = Alt(user1=v.id, user2=u.id) g.db.add(new_alt) diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 3a1269134..ef85a775c 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/default.html b/files/templates/default.html index 02ac78c58..bc233c02c 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,7 +7,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% if sub and sub.css and not request.path.endswith('settings') %} diff --git a/files/templates/log.html b/files/templates/log.html index e75efa749..c59218c9f 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index be0ed6c09..05200a43f 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 02b488758..3371f9a63 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 31e66001c..ed02cefdf 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/sign_up.html b/files/templates/sign_up.html index daf8853f9..f788893b4 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index e4758a435..00c15a8db 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submit.html b/files/templates/submit.html index 37da316d1..61b8b8ef4 100644 --- a/files/templates/submit.html +++ b/files/templates/submit.html @@ -26,7 +26,7 @@ {% block stylesheets %} {% if v %} - + {% if v.agendaposter %} - + {% endif %} {% endblock %} diff --git a/seed-db.sql b/seed-db.sql index 8c00749a5..f476aaecf 100644 --- a/seed-db.sql +++ b/seed-db.sql @@ -9,8 +9,6 @@ INSERT INTO public.users (username, original_username) VALUES ('AutoBetter','AutoBetter'), ('AutoChoice','AutoChoice'); -insert into public.award_relationships(id,user_id,kind) values(1,1,'shit'); - INSERT INTO public.badge_defs VALUES (1,'Alpha User','Joined during open alpha'), (2,'Verified Email','Verified Email'), diff --git a/snappy_Drama.txt b/snappy_Drama.txt index 77da72ead..ea40dd019 100644 --- a/snappy_Drama.txt +++ b/snappy_Drama.txt @@ -3151,7 +3151,9 @@ Middle East is like a retarded tv war show I barely watch. To you guys it's real life lmaooooooo {[para]} I don't like loli + it is disgusting + rape though... {[para]} Don't be serious, you are going to make me laugh. Do you really think Carp cares about you as a person? He just wants to bolster his followers in rDrama. Even the people there and in ruqqus talk about how annoying you are. Seriously, you're kidding yourself.