fsfds
This commit is contained in:
parent
da305ee935
commit
dae513cc4d
2 changed files with 91 additions and 145 deletions
|
@ -137,57 +137,108 @@ def remove_fake_admin(v, username):
|
||||||
return {"message": "Fake admin removed!"}
|
return {"message": "Fake admin removed!"}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/admin/monthly")
|
@app.get("/admin/monthly")
|
||||||
@limiter.limit("1/day")
|
@limiter.limit("1/day")
|
||||||
@admin_level_required(6)
|
@admin_level_required(6)
|
||||||
def monthly(v):
|
def monthly(v):
|
||||||
if 'pcm' in request.host or ('rdrama' in request.host and v.id in [1,12,28,29,747,995,1480]) or ('rdrama' not in request.host and 'pcm' not in request.host):
|
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
||||||
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
|
_awards = []
|
||||||
_awards = []
|
t = time.time()
|
||||||
for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all():
|
for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all():
|
||||||
grant_awards = {}
|
grant_awards = {}
|
||||||
|
|
||||||
if u.patron == 1:
|
if u.patron == 1:
|
||||||
grant_awards["shit"] = 1
|
grant_awards["shit"] = 1
|
||||||
grant_awards["stars"] = 1
|
grant_awards["stars"] = 1
|
||||||
elif u.patron == 2:
|
elif u.patron == 2:
|
||||||
grant_awards["shit"] = 3
|
grant_awards["shit"] = 3
|
||||||
grant_awards["stars"] = 3
|
grant_awards["stars"] = 3
|
||||||
elif u.patron == 3:
|
elif u.patron == 3:
|
||||||
grant_awards["shit"] = 5
|
grant_awards["shit"] = 5
|
||||||
grant_awards["stars"] = 5
|
grant_awards["stars"] = 5
|
||||||
grant_awards["ban"] = 1
|
grant_awards["ban"] = 1
|
||||||
elif u.patron == 4:
|
elif u.patron == 4:
|
||||||
grant_awards["shit"] = 10
|
grant_awards["shit"] = 10
|
||||||
grant_awards["stars"] = 10
|
grant_awards["stars"] = 10
|
||||||
grant_awards["ban"] = 3
|
grant_awards["ban"] = 3
|
||||||
elif u.patron == 5 or u.patron == 8:
|
elif u.patron == 5 or u.patron == 8:
|
||||||
grant_awards["shit"] = 20
|
grant_awards["shit"] = 20
|
||||||
grant_awards["stars"] = 20
|
grant_awards["stars"] = 20
|
||||||
grant_awards["ban"] = 6
|
grant_awards["ban"] = 6
|
||||||
|
|
||||||
|
|
||||||
for name in grant_awards:
|
for name in grant_awards:
|
||||||
for count in range(grant_awards[name]):
|
for count in range(grant_awards[name]):
|
||||||
|
|
||||||
thing += 1
|
thing += 1
|
||||||
|
|
||||||
_awards.append(AwardRelationship(
|
_awards.append(AwardRelationship(
|
||||||
id=thing,
|
id=thing,
|
||||||
user_id=u.id,
|
user_id=u.id,
|
||||||
kind=name
|
kind=name
|
||||||
))
|
))
|
||||||
|
|
||||||
text = "You were given the following awards:\n\n"
|
text = "You were given the following awards:\n\n"
|
||||||
|
|
||||||
for key, value in grant_awards.items():
|
for key, value in grant_awards.items():
|
||||||
text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n"
|
text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n"
|
||||||
|
|
||||||
send_notification(NOTIFICATIONS_ACCOUNT, u, text)
|
send_notification(NOTIFICATIONS_ACCOUNT, u, text)
|
||||||
|
|
||||||
g.db.add_all(_awards)
|
g.db.add_all(_awards)
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
print(time.time() - t)
|
||||||
|
return {"message": "Monthly awards granted"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/admin/monthly2")
|
||||||
|
@limiter.limit("1/day")
|
||||||
|
@admin_level_required(6)
|
||||||
|
def monthly(v):
|
||||||
|
t = time.time()
|
||||||
|
for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all():
|
||||||
|
grant_awards = {}
|
||||||
|
|
||||||
|
if u.patron == 1:
|
||||||
|
grant_awards["shit"] = 1
|
||||||
|
grant_awards["stars"] = 1
|
||||||
|
elif u.patron == 2:
|
||||||
|
grant_awards["shit"] = 3
|
||||||
|
grant_awards["stars"] = 3
|
||||||
|
elif u.patron == 3:
|
||||||
|
grant_awards["shit"] = 5
|
||||||
|
grant_awards["stars"] = 5
|
||||||
|
grant_awards["ban"] = 1
|
||||||
|
elif u.patron == 4:
|
||||||
|
grant_awards["shit"] = 10
|
||||||
|
grant_awards["stars"] = 10
|
||||||
|
grant_awards["ban"] = 3
|
||||||
|
elif u.patron == 5 or u.patron == 8:
|
||||||
|
grant_awards["shit"] = 20
|
||||||
|
grant_awards["stars"] = 20
|
||||||
|
grant_awards["ban"] = 6
|
||||||
|
|
||||||
|
|
||||||
|
for name in grant_awards:
|
||||||
|
for count in range(grant_awards[name]):
|
||||||
|
|
||||||
|
a = AwardRelationship(
|
||||||
|
user_id=u.id,
|
||||||
|
kind=name
|
||||||
|
))
|
||||||
|
g.db.add(a)
|
||||||
|
|
||||||
|
text = "You were given the following awards:\n\n"
|
||||||
|
|
||||||
|
for key, value in grant_awards.items():
|
||||||
|
text += f" - **{value}** {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}\n"
|
||||||
|
|
||||||
|
send_notification(NOTIFICATIONS_ACCOUNT, u, text)
|
||||||
|
|
||||||
|
g.db.commit()
|
||||||
|
print(time.time() - t)
|
||||||
return {"message": "Monthly awards granted"}
|
return {"message": "Monthly awards granted"}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ def notifications(v):
|
||||||
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
||||||
|
|
||||||
comments = []
|
comments = []
|
||||||
notifs = []
|
|
||||||
|
|
||||||
for index, x in enumerate(notifications):
|
for index, x in enumerate(notifications):
|
||||||
c = x.comment
|
c = x.comment
|
||||||
|
@ -38,114 +37,9 @@ def notifications(v):
|
||||||
elif not x.read:
|
elif not x.read:
|
||||||
c.unread = True
|
c.unread = True
|
||||||
x.read = True
|
x.read = True
|
||||||
notifs.append(x)
|
g.db.add(x)
|
||||||
comments.append(c)
|
comments.append(c)
|
||||||
|
|
||||||
g.db.add_all(notifs)
|
|
||||||
g.db.commit()
|
|
||||||
|
|
||||||
next_exists = (len(comments) > 25)
|
|
||||||
listing = comments[:25]
|
|
||||||
else:
|
|
||||||
|
|
||||||
notifications = v.notifications.join(Notification.comment).filter(
|
|
||||||
Comment.is_banned == False,
|
|
||||||
Comment.deleted_utc == 0,
|
|
||||||
Comment.author_id != AUTOJANNY_ACCOUNT,
|
|
||||||
).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
|
||||||
|
|
||||||
next_exists = (len(notifications) > 25)
|
|
||||||
notifications = notifications[:25]
|
|
||||||
cids = [x.comment_id for x in notifications]
|
|
||||||
comments = get_comments(cids, v=v, load_parent=True)
|
|
||||||
|
|
||||||
t = time.time()
|
|
||||||
i = 0
|
|
||||||
notifs = []
|
|
||||||
for x in notifications:
|
|
||||||
try:
|
|
||||||
if not x.read:
|
|
||||||
comments[i].unread = True
|
|
||||||
x.read = True
|
|
||||||
notifs.append(x)
|
|
||||||
except: continue
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
g.db.add_all(notifs)
|
|
||||||
g.db.commit()
|
|
||||||
print(time.time() - t)
|
|
||||||
|
|
||||||
if not posts:
|
|
||||||
listing = []
|
|
||||||
for c in comments:
|
|
||||||
c._is_blocked = False
|
|
||||||
c._is_blocking = False
|
|
||||||
if c.parent_submission and c.parent_comment and c.parent_comment.author_id == v.id:
|
|
||||||
c.replies = []
|
|
||||||
while c.parent_comment and c.parent_comment.author_id == v.id:
|
|
||||||
parent = c.parent_comment
|
|
||||||
if c not in parent.replies2:
|
|
||||||
parent.replies2 = parent.replies2 + [c]
|
|
||||||
parent.replies = parent.replies2
|
|
||||||
c = parent
|
|
||||||
if c not in listing:
|
|
||||||
listing.append(c)
|
|
||||||
c.replies = c.replies2
|
|
||||||
elif c.parent_submission:
|
|
||||||
c.replies = []
|
|
||||||
if c not in listing:
|
|
||||||
listing.append(c)
|
|
||||||
else:
|
|
||||||
if c.parent_comment:
|
|
||||||
while c.level > 1:
|
|
||||||
c = c.parent_comment
|
|
||||||
|
|
||||||
if c not in listing:
|
|
||||||
listing.append(c)
|
|
||||||
|
|
||||||
|
|
||||||
return render_template("notifications.html",
|
|
||||||
v=v,
|
|
||||||
notifications=listing,
|
|
||||||
next_exists=next_exists,
|
|
||||||
page=page,
|
|
||||||
standalone=True,
|
|
||||||
render_replies=True,
|
|
||||||
is_notification_page=True)
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/notifications2")
|
|
||||||
@auth_required
|
|
||||||
def notifications2(v):
|
|
||||||
try: page = int(request.args.get('page', 1))
|
|
||||||
except: page = 1
|
|
||||||
messages = request.args.get('messages', False)
|
|
||||||
modmail = request.args.get('modmail', False)
|
|
||||||
posts = request.args.get('posts', False)
|
|
||||||
if modmail and v.admin_level == 6:
|
|
||||||
comments = g.db.query(Comment).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all()
|
|
||||||
next_exists = (len(comments) > 25)
|
|
||||||
comments = comments[:25]
|
|
||||||
elif messages:
|
|
||||||
comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all()
|
|
||||||
next_exists = (len(comments) > 25)
|
|
||||||
comments = comments[:25]
|
|
||||||
elif posts:
|
|
||||||
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ACCOUNT).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(26).all()
|
|
||||||
|
|
||||||
comments = []
|
|
||||||
notifs = []
|
|
||||||
|
|
||||||
for index, x in enumerate(notifications):
|
|
||||||
c = x.comment
|
|
||||||
if x.read and index > 26: break
|
|
||||||
elif not x.read:
|
|
||||||
c.unread = True
|
|
||||||
x.read = True
|
|
||||||
notifs.append(x)
|
|
||||||
comments.append(c)
|
|
||||||
|
|
||||||
g.db.add_all(notifs)
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
next_exists = (len(comments) > 25)
|
next_exists = (len(comments) > 25)
|
||||||
|
@ -176,7 +70,7 @@ def notifications2(v):
|
||||||
|
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
print(time.time() - t)
|
print(time.time() - t)
|
||||||
|
|
||||||
if not posts:
|
if not posts:
|
||||||
listing = []
|
listing = []
|
||||||
for c in comments:
|
for c in comments:
|
||||||
|
@ -216,6 +110,7 @@ def notifications2(v):
|
||||||
is_notification_page=True)
|
is_notification_page=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cache.memoize(timeout=3600)
|
@cache.memoize(timeout=3600)
|
||||||
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', **kwargs):
|
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', **kwargs):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue