remotes/1693045480750635534/spooky-22
Aevann1 2022-03-05 22:53:39 +02:00
parent 7d44f8456f
commit bf391394a8
10 changed files with 53 additions and 104 deletions

View File

@ -67,7 +67,6 @@ class User(Base):
comment_count = Column(Integer, default=0)
received_award_count = Column(Integer, default=0)
created_utc = Column(Integer)
suicide_utc = Column(Integer, default=0)
rent_utc = Column(Integer, default=0)
steal_utc = Column(Integer, default=0)
fail_utc = Column(Integer, default=0)
@ -584,24 +583,18 @@ class User(Base):
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all()
return [x[0] for x in posts]
@lazy
def userblocks(self):
return [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()] + [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()]
@lazy
def saved_idlist(self, page=1):
saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter_by(user_id=self.id).all()]
posts = g.db.query(Submission.id).filter(Submission.id.in_(saved), Submission.is_banned == False, Submission.deleted_utc == 0)
if self.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).filter_by(
user_id=self.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).filter_by(
target_id=self.id).all()]
posts = posts.filter(
Submission.author_id.notin_(blocking),
Submission.author_id.notin_(blocked)
)
if self.admin_level < 2:
posts = posts.filter(Submission.author_id.notin_(self.blocks))
return [x[0] for x in posts.order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).all()]
@ -611,18 +604,8 @@ class User(Base):
saved = [x[0] for x in g.db.query(CommentSaveRelationship.comment_id).filter_by(user_id=self.id).all()]
comments = g.db.query(Comment.id).filter(Comment.id.in_(saved), Comment.is_banned == False, Comment.deleted_utc == 0)
if self.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).filter_by(
user_id=self.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).filter_by(
target_id=self.id).all()]
comments = comments.filter(
Comment.author_id.notin_(blocking),
Comment.author_id.notin_(blocked)
)
if self.admin_level < 2:
comments = comments.filter(Comment.author_id.notin_(self.blocks))
return [x[0] for x in comments.order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).all()]

View File

@ -35,7 +35,7 @@ def get_logged_in_user():
return v
def check_ban_evade(v):
if v and not v.patron and v.admin_level == 0 and v.ban_evade and not v.unban_utc:
if v and not v.patron and v.admin_level < 2 and v.ban_evade and not v.unban_utc:
if randint(0,30) < v.ban_evade: v.shadowbanned = "AutoJanny"
else: v.ban_evade +=1
g.db.add(v)

View File

@ -17,7 +17,7 @@ def join_discord(v):
if v.shadowbanned: return {"error": "Internal server error"}
if SITE_NAME == 'Drama' and v.admin_level == 0 and v.patron == 0 and v.truecoins < 150:
if SITE_NAME == 'Drama' and v.admin_level < 2 and v.patron == 0 and v.truecoins < 150:
return "You must receive 150 upvotes/downvotes from other users before being able to join the Discord server."
now=int(time.time())

View File

@ -307,17 +307,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false"
if (sort == "hot" or (v and v.id == Q_ID)) and ccmode == "false" and not gt and not lt:
posts = posts.filter_by(stickied=None)
if v and v.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
posts = posts.filter(
Submission.author_id.notin_(blocking),
Submission.author_id.notin_(blocked)
)
if v and v.admin_level < 2:
posts = posts.filter(Submission.author_id.notin_(v.userblocks))
if not (v and v.changelogsub):
posts=posts.filter(not_(Submission.title.ilike('[changelog]%')))
@ -365,10 +356,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false"
if v and v.all_blocks: pins = pins.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks)))
else: pins = pins.filter(Submission.sub == None)
if v and v.admin_level == 0:
blocking = [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()]
pins = pins.filter(Submission.author_id.notin_(blocking), Submission.author_id.notin_(blocked))
if v and v.admin_level < 2:
pins = pins.filter(Submission.author_id.notin_(v.userblocks))
pins = pins.all()
@ -419,17 +408,8 @@ def changeloglist(v=None, sort="new", page=1 ,t="all"):
posts = g.db.query(Submission.id).filter_by(is_banned=False, private=False,).filter(Submission.deleted_utc == 0)
if v and v.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
posts = posts.filter(
Submission.author_id.notin_(blocking),
Submission.author_id.notin_(blocked)
)
if v.admin_level < 2:
posts = posts.filter(Submission.author_id.notin_(v.userblocks))
admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level > 0).all()]
posts = posts.filter(Submission.title.ilike('_changelog%'), Submission.author_id.in_(admins))
@ -481,22 +461,18 @@ def random_post(v):
@cache.memoize(timeout=86400)
def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"):
cc_or_private = [x[0] for x in g.db.query(Submission.id).filter(or_(Submission.club == True, Submission.private == True)).all()]
comments = g.db.query(Comment.id).filter(Comment.parent_submission != None)
comments = g.db.query(Comment.id).filter(Comment.parent_submission != None, Comment.parent_submission.notin_(cc_or_private))
if v.admin_level < 2:
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
if v and v.admin_level <= 3:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private))
comments = comments.filter(Comment.author_id.notin_(blocking), Comment.author_id.notin_(blocked))
if not v or not v.admin_level > 1:
comments = comments.filter(Comment.is_banned==False, Comment.deleted_utc == 0)
if not v.paid_dues:
club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()]
comments = comments.filter(Comment.parent_submission.notin_(club))
now = int(time.time())
if t == 'hour':

View File

@ -73,7 +73,7 @@ def toggle_club(pid, v):
if v.club_allowed == False: abort(403)
post = get_post(pid)
if post.author_id != v.id and v.admin_level == 0: abort(403)
if post.author_id != v.id and v.admin_level < 2: abort(403)
post.club = not post.club
g.db.add(post)

View File

@ -57,9 +57,11 @@ def searchposts(v):
posts = g.db.query(Submission.id)
if not (v and v.paid_dues): posts = posts.filter(Submission.club == False)
if not v.paid_dues: posts = posts.filter_by(club=False)
if not (v and v.admin_level > 1): posts = posts.filter(Submission.private == False)
if v.admin_level < 2:
posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False, Submission.private == False, Submission.author_id.notin_(v.userblocks))
if 'author' in criteria:
@ -114,21 +116,6 @@ def searchposts(v):
)
)
if not (v and v.admin_level > 1): posts = posts.filter(Submission.deleted_utc == 0, Submission.is_banned == False)
if v and v.admin_level > 1: pass
elif v:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
posts = posts.filter(
Submission.author_id.notin_(blocking),
Submission.author_id.notin_(blocked),
)
if t:
now = int(time.time())
@ -232,8 +219,6 @@ def searchcomments(v):
if 'over18' in criteria: comments = comments.filter(Comment.over_18 == True)
if not (v and v.admin_level > 1): comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False)
if t:
now = int(time.time())
if t == 'hour':
@ -251,6 +236,16 @@ def searchcomments(v):
comments = comments.filter(Comment.created_utc >= cutoff)
if v.admin_level < 2:
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
comments = comments.filter(Comment.author_id.notin_(v.userblocks), Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private))
if not v.paid_dues:
club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()]
comments = comments.filter(Comment.parent_submission.notin_(club))
if sort == "new":
comments = comments.order_by(Comment.created_utc.desc())

View File

@ -251,16 +251,12 @@ def thiefs(v):
@app.post("/@<username>/suicide")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@limiter.limit("5/day")
@auth_required
def suicide(v, username):
t = int(time.time())
if v.admin_level == 0 and t - v.suicide_utc < 86400: return {"message": "You're on 1-day cooldown!"}
user = get_user(username)
suicide = f"Hi there,\n\nA [concerned user](/id/{v.id}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help."
send_repeatable_notification(user.id, suicide)
v.suicide_utc = t
g.db.add(v)
send_notification(user.id, suicide)
g.db.commit()
return {"message": "Help message sent!"}
@ -826,7 +822,7 @@ def u_username_comments(username, v=None):
comments = g.db.query(Comment.id).filter(Comment.author_id == u.id, Comment.parent_submission != None)
if not v or (v.id != u.id and v.admin_level == 0):
if not v or (v.id != u.id and v.admin_level < 2):
comments = comments.filter(Comment.deleted_utc == 0, Comment.is_banned == False, Comment.ghost == False)
now = int(time.time())

View File

@ -432,7 +432,7 @@
<ul class="d-none d-md-flex list-inline text-right text-md-left"><li>
{% if v and request.path.startswith('/@') and v.admin_level == 0%}
{% if v and request.path.startswith('/@') and v.admin_level < 2%}
{% if voted==1 %}
<button class="btn caction py-0 m-0 px-3 nobackground arrow-up mx-0 comment-{{c.id}}-up active"></button>
{% endif %}
@ -449,7 +449,7 @@
<span data-bs-toggle="tooltip" data-bs-placement="top" title="+{{ups}} | -{{downs}}" class="comment-score-{{c.id}} score comment-score-{{c.id}} {% if voted==1 %}score-up{% elif voted==-1%}score-down{% endif %}{% if c.controversial %} controversial{% endif %}">{{score}}</span>
</button>
{% if v and request.path.startswith('/@') and v.admin_level == 0 %}
{% if v and request.path.startswith('/@') and v.admin_level < 2 %}
{% if voted==-1 %}
<li class=" arrow-down py-0 m-0 px-3 comment-{{c.id}}-down active"></li>
{% endif %}

View File

@ -573,7 +573,6 @@ CREATE TABLE public.users (
profilecss character varying(4000),
coins integer DEFAULT 0 NOT NULL,
agendaposter integer DEFAULT 0 NOT NULL,
suicide_utc integer DEFAULT 0 NOT NULL,
post_count integer DEFAULT 0 NOT NULL,
comment_count integer DEFAULT 0 NOT NULL,
highres character varying(60),

View File

@ -1,38 +1,38 @@
INSERT INTO public.users (username, passhash, created_utc, admin_level, over_18, is_activated, bio, bio_html, login_nonce, is_private,
unban_utc, original_username, customtitle, defaultsorting, defaultsortingcomments, defaulttime, namecolor, titlecolor,
customtitleplain, theme, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter, suicide_utc,
customtitleplain, theme, themecolor, changelogsub, oldreddit, css, profilecss, coins, agendaposter,
post_count, comment_count, background, verified, truecoins, cardview
) VALUES ('Drama', '', 0, 0, true, true, '', '', 0, false,
0, 'Drama', '', 'hot', 'top', 'day', 'ff66ac', 'ff66ac',
'', 'dark', 'ff66ac', false, false, '', '', 0, 0, 0,
'', 'dark', 'ff66ac', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('AutoJanny', '', 0, 0, true, true, '', '', 0, false,
0, 'AutoJanny', '', 'hot', 'top', 'day', 'ff66ac', 'ff66ac',
'', 'dark', 'ff66ac', false, false, '', '', 0, 0, 0,
'', 'dark', 'ff66ac', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('Snappy', '', 0, 0, true, true, '', '', 0, false,
0, 'Snappy', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
'', 'dark', '30409f', false, false, '', '', 0, 0, 0,
'', 'dark', '30409f', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('longpostbot', '', 0, 0, true, true, '', '', 0, false,
0, 'longpostbot', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
'', 'dark', '30409f', false, false, '', '', 0, 0, 0,
'', 'dark', '30409f', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('zozbot', '', 0, 0, true, true, '', '', 0, false,
0, 'zozbot', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
'', 'dark', '30409f', false, false, '', '', 0, 0, 0,
'', 'dark', '30409f', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('AutoPoller', '', 0, 0, true, true, '', '', 0, false,
0, 'AutoPoller', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
'', 'dark', '30409f', false, false, '', '', 0, 0, 0,
'', 'dark', '30409f', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('AutoBetter', '', 0, 0, true, true, '', '', 0, false,
0, 'AutoBetter', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
'', 'dark', '30409f', false, false, '', '', 0, 0, 0,
'', 'dark', '30409f', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false),
('AutoChoice', '', 0, 0, true, true, '', '', 0, false,
0, 'AutoChoice', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
'', 'dark', '30409f', false, false, '', '', 0, 0, 0,
'', 'dark', '30409f', false, false, '', '', 0, 0,
0, 0, '', 'Verified', 0, false);
INSERT INTO public.badge_defs VALUES