xvc
This commit is contained in:
parent
23e49e1a30
commit
82e044ea93
11 changed files with 62 additions and 49 deletions
|
@ -10,14 +10,12 @@ class AwardRelationship(Base):
|
|||
__tablename__ = "award_relationships"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
||||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||
kind = Column(String)
|
||||
|
||||
user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", viewonly=True)
|
||||
|
||||
post = relationship("Submission", primaryjoin="AwardRelationship.submission_id==Submission.id", viewonly=True)
|
||||
comment = relationship("Comment", primaryjoin="AwardRelationship.comment_id==Comment.id", viewonly=True)
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ class Badge(Base):
|
|||
__tablename__ = "badges"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
|
||||
user_id = Column(Integer, ForeignKey('users.id'))
|
||||
badge_id = Column(Integer)
|
||||
description = Column(String)
|
||||
url = Column(String)
|
||||
|
||||
user = relationship("User", viewonly=True)
|
||||
badge = relationship("BadgeDef", primaryjoin="foreign(Badge.badge_id) == remote(BadgeDef.id)", viewonly=True)
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Badge(Base):
|
|||
@lazy
|
||||
def text(self):
|
||||
if self.name == "Chud":
|
||||
ti = self.user.agendaposter_expires_utc
|
||||
ti = self.user.agendaposter
|
||||
if ti: text = self.badge.description + " until " + datetime.utcfromtimestamp(ti).strftime('%Y-%m-%d %H:%M:%S')
|
||||
else: text = self.badge.description + " permanently"
|
||||
elif self.badge_id in (94,95,96,97,98,109):
|
||||
|
|
|
@ -18,6 +18,7 @@ class OauthApp(Base):
|
|||
redirect_uri = Column(String)
|
||||
description = Column(String)
|
||||
author_id = Column(Integer, ForeignKey("users.id"))
|
||||
|
||||
author = relationship("User", viewonly=True)
|
||||
|
||||
def __repr__(self): return f"<OauthApp(id={self.id})>"
|
||||
|
@ -69,6 +70,7 @@ class ClientAuth(Base):
|
|||
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
access_token = Column(String)
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
|
||||
user = relationship("User", viewonly=True)
|
||||
application = relationship("OauthApp", viewonly=True)
|
||||
|
||||
|
|
|
@ -35,9 +35,8 @@ class Comment(Base):
|
|||
is_bot = Column(Boolean, default=False)
|
||||
is_pinned = Column(String)
|
||||
is_pinned_utc = Column(Integer)
|
||||
sentto=Column(Integer, ForeignKey("users.id"))
|
||||
sentto = Column(Integer, ForeignKey("users.id"))
|
||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
oauth_app = relationship("OauthApp", viewonly=True)
|
||||
upvotes = Column(Integer, default=1)
|
||||
downvotes = Column(Integer, default=0)
|
||||
realupvotes = Column(Integer, default=1)
|
||||
|
@ -48,6 +47,7 @@ class Comment(Base):
|
|||
blackjack_result = Column(String)
|
||||
treasure_amount = Column(String)
|
||||
|
||||
oauth_app = relationship("OauthApp", viewonly=True)
|
||||
post = relationship("Submission", viewonly=True)
|
||||
author = relationship("User", primaryjoin="User.id==Comment.author_id")
|
||||
senttouser = relationship("User", primaryjoin="User.id==Comment.sentto", viewonly=True)
|
||||
|
@ -451,6 +451,7 @@ class Notification(Base):
|
|||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
comment_id = Column(Integer, ForeignKey("comments.id"))
|
||||
read = Column(Boolean, default=False)
|
||||
|
||||
comment = relationship("Comment", viewonly=True)
|
||||
user = relationship("User", viewonly=True)
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ from files.helpers.const import *
|
|||
class ModAction(Base):
|
||||
__tablename__ = "modactions"
|
||||
id = Column(Integer, primary_key=True)
|
||||
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
kind = Column(String)
|
||||
target_user_id = Column(Integer, ForeignKey("users.id"), default=0)
|
||||
|
|
|
@ -72,8 +72,7 @@ class User(Base):
|
|||
admin_level = Column(Integer, default=0)
|
||||
coins_spent = Column(Integer, default=0)
|
||||
lootboxes_bought = Column(Integer, default=0)
|
||||
agendaposter = Column(Boolean, default=False)
|
||||
agendaposter_expires_utc = Column(Integer, default=0)
|
||||
agendaposter = Column(Integer, default=0)
|
||||
changelogsub = Column(Boolean, default=False)
|
||||
is_activated = Column(Boolean, default=False)
|
||||
shadowbanned = Column(String)
|
||||
|
|
|
@ -794,54 +794,71 @@ def admin_removed_comments(v):
|
|||
def agendaposter(user_id, v):
|
||||
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||
|
||||
if user.username == '911roofer': abort(403)
|
||||
|
||||
expiry = request.values.get("days", 0)
|
||||
if expiry:
|
||||
expiry = float(expiry)
|
||||
expiry = g.timestamp + expiry*60*60*24
|
||||
else: expiry = g.timestamp + 2629746
|
||||
|
||||
user.agendaposter = not user.agendaposter
|
||||
user.agendaposter_expires_utc = expiry
|
||||
user.agendaposter = expiry
|
||||
g.db.add(user)
|
||||
|
||||
for alt in user.alts:
|
||||
if alt.admin_level: break
|
||||
alt.agendaposter = user.agendaposter
|
||||
alt.agendaposter_expires_utc = expiry
|
||||
if alt.admin_level: return {"error": "User is an admin!"}
|
||||
alt.agendaposter = expiry
|
||||
g.db.add(alt)
|
||||
|
||||
note = None
|
||||
|
||||
if not user.agendaposter: kind = "unagendaposter"
|
||||
else:
|
||||
kind = "agendaposter"
|
||||
note = f"for {request.values.get('days')} days" if expiry else "never expires"
|
||||
note = f"for {request.values.get('days')} days" if expiry else "never expires"
|
||||
|
||||
ma = ModAction(
|
||||
kind=kind,
|
||||
kind="agendaposter",
|
||||
user_id=v.id,
|
||||
target_user_id=user.id,
|
||||
note = note
|
||||
)
|
||||
g.db.add(ma)
|
||||
|
||||
if user.agendaposter:
|
||||
if not user.has_badge(26):
|
||||
badge = Badge(user_id=user.id, badge_id=26)
|
||||
g.db.add(badge)
|
||||
g.db.flush()
|
||||
send_notification(user.id, f"@AutoJanny has given you the following profile badge:\n\n\n\n{badge.name}")
|
||||
if not user.has_badge(26):
|
||||
badge = Badge(user_id=user.id, badge_id=26)
|
||||
g.db.add(badge)
|
||||
g.db.flush()
|
||||
send_notification(user.id, f"@AutoJanny has given you the following profile badge:\n\n\n\n{badge.name}")
|
||||
|
||||
else:
|
||||
badge = user.has_badge(26)
|
||||
if badge: g.db.delete(badge)
|
||||
|
||||
if user.agendaposter: send_repeatable_notification(user.id, f"You have been marked by an admin as an agendaposter ({note}).")
|
||||
else: send_repeatable_notification(user.id, "You have been unmarked by an admin as an agendaposter.")
|
||||
send_repeatable_notification(user.id, f"You have been marked by an admin as an agendaposter ({note}).")
|
||||
|
||||
g.db.commit()
|
||||
|
||||
return redirect(user.url)
|
||||
|
||||
|
||||
|
||||
@app.post("/unagendaposter/<user_id>")
|
||||
@admin_level_required(2)
|
||||
def unagendaposter(user_id, v):
|
||||
user = g.db.query(User).filter_by(id=user_id).one_or_none()
|
||||
|
||||
user.agendaposter = 0
|
||||
g.db.add(user)
|
||||
|
||||
for alt in user.alts:
|
||||
alt.agendaposter = 0
|
||||
g.db.add(alt)
|
||||
|
||||
ma = ModAction(
|
||||
kind="unagendaposter",
|
||||
user_id=v.id,
|
||||
target_user_id=user.id
|
||||
)
|
||||
|
||||
g.db.add(ma)
|
||||
|
||||
badge = user.has_badge(26)
|
||||
if badge: g.db.delete(badge)
|
||||
|
||||
send_repeatable_notification(user.id, "You have been unmarked by an admin as an agendaposter.")
|
||||
|
||||
g.db.commit()
|
||||
if user.agendaposter: return redirect(user.url)
|
||||
return {"message": "Chud theme disabled!"}
|
||||
|
||||
|
||||
|
|
|
@ -292,15 +292,14 @@ def award_post(pid, v):
|
|||
cache.delete_memoized(frontlist)
|
||||
else: post.stickied_utc = t
|
||||
g.db.add(post)
|
||||
elif kind == "agendaposter" and not (author.agendaposter and author.agendaposter_expires_utc == 0):
|
||||
elif kind == "agendaposter" and not (author.agendaposter and author.agendaposter == 0):
|
||||
if author.marseyawarded:
|
||||
return {"error": "This user is the under the effect of a conflicting award: Marsey award."}, 404
|
||||
|
||||
if author.username == "911roofer": abort(403)
|
||||
if author.agendaposter_expires_utc and time.time() < author.agendaposter_expires_utc: author.agendaposter_expires_utc += 86400
|
||||
else: author.agendaposter_expires_utc = int(time.time()) + 86400
|
||||
if author.agendaposter and time.time() < author.agendaposter: author.agendaposter += 86400
|
||||
else: author.agendaposter = int(time.time()) + 86400
|
||||
|
||||
author.agendaposter = True
|
||||
if not author.has_badge(26):
|
||||
badge = Badge(user_id=author.id, badge_id=26)
|
||||
g.db.add(badge)
|
||||
|
@ -527,15 +526,14 @@ def award_comment(cid, v):
|
|||
c.is_pinned_utc = None
|
||||
else: c.is_pinned_utc = t
|
||||
g.db.add(c)
|
||||
elif kind == "agendaposter" and not (author.agendaposter and author.agendaposter_expires_utc == 0):
|
||||
elif kind == "agendaposter" and not (author.agendaposter and author.agendaposter == 0):
|
||||
if author.marseyawarded:
|
||||
return {"error": "This user is the under the effect of a conflicting award: Marsey award."}, 404
|
||||
|
||||
if author.username == "911roofer": abort(403)
|
||||
if author.agendaposter_expires_utc and time.time() < author.agendaposter_expires_utc: author.agendaposter_expires_utc += 86400
|
||||
else: author.agendaposter_expires_utc = int(time.time()) + 86400
|
||||
if author.agendaposter and time.time() < author.agendaposter: author.agendaposter += 86400
|
||||
else: author.agendaposter = int(time.time()) + 86400
|
||||
|
||||
author.agendaposter = True
|
||||
if not author.has_badge(26):
|
||||
badge = Badge(user_id=author.id, badge_id=26)
|
||||
g.db.add(badge)
|
||||
|
|
|
@ -201,9 +201,8 @@ def front_all(v, sub=None):
|
|||
g.db.add(v)
|
||||
g.db.commit()
|
||||
|
||||
if v.agendaposter_expires_utc and v.agendaposter_expires_utc < time.time():
|
||||
v.agendaposter_expires_utc = 0
|
||||
v.agendaposter = None
|
||||
if v.agendaposter and v.agendaposter < time.time():
|
||||
v.agendaposter = 0
|
||||
send_repeatable_notification(v.id, "Your chud theme has expired!")
|
||||
g.db.add(v)
|
||||
badge = v.has_badge(26)
|
||||
|
|
|
@ -52,7 +52,7 @@ def grassed(v):
|
|||
@app.get("/agendaposters")
|
||||
@auth_required
|
||||
def agendaposters(v):
|
||||
users = [x for x in g.db.query(User).filter_by(agendaposter = True).order_by(User.username).all()]
|
||||
users = [x for x in g.db.query(User).filter(User.agendaposter > 0).order_by(User.username).all()]
|
||||
return render_template("agendaposters.html", v=v, users=users)
|
||||
|
||||
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
<input autocomplete="off" type="number" step="any" name="days" class="form-control" placeholder="Days (0 or blank = permanent)" >
|
||||
<input autocomplete="off" type="submit" class="btn btn-danger" value="Lock Chud Theme" >
|
||||
</form>
|
||||
<a id="unagendaposter" class="{% if not u.agendaposter %}d-none{% endif %} btn btn-success" role="button" onclick="post_toast2('/agendaposter/{{u.id}}','agendaposter1','unagendaposter')">Disable Chud Theme</a>
|
||||
<a id="unagendaposter" class="{% if not u.agendaposter %}d-none{% endif %} btn btn-success" role="button" onclick="post_toast2('/unagendaposter/{{u.id}}','agendaposter1','unagendaposter')">Disable Chud Theme</a>
|
||||
|
||||
<pre></pre>
|
||||
|
||||
|
@ -574,7 +574,7 @@
|
|||
<input autocomplete="off" type="number" step="any" name="days" class="form-control" placeholder="Days (0 or blank = permanent)" >
|
||||
<input autocomplete="off" type="submit" class="btn btn-danger" value="Lock Chud Theme" >
|
||||
</form>
|
||||
<a id="unagendaposter2" class="{% if not u.agendaposter %}d-none{% endif %} btn btn-success" role="button" onclick="post_toast2('/agendaposter/{{u.id}}','agendaposter2','unagendaposter2')">Disable Chud Theme</a>
|
||||
<a id="unagendaposter2" class="{% if not u.agendaposter %}d-none{% endif %} btn btn-success" role="button" onclick="post_toast2('/unagendaposter/{{u.id}}','agendaposter2','unagendaposter2')">Disable Chud Theme</a>
|
||||
|
||||
<pre></pre>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue