Track coins awarded with votes.

Supports more complicated double XP shenanigans without creating
any cycles of user actions that create positive DC.
remotes/1693176582716663532/tmp_refs/heads/watchparty
Snakes 2022-10-23 18:23:51 -04:00
parent dbb7296dd7
commit d869353fdf
Signed by: Snakes
GPG Key ID: E745A82778055C7E
2 changed files with 13 additions and 10 deletions

View File

@ -14,6 +14,7 @@ class Vote(Base):
vote_type = Column(Integer)
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
real = Column(Boolean, default=True)
coins = Column(Integer, default=1, nullable=False)
created_utc = Column(Integer)
user = relationship("User")
@ -44,6 +45,7 @@ class CommentVote(Base):
vote_type = Column(Integer)
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
real = Column(Boolean, default=True)
coins = Column(Integer, default=1, nullable=False)
created_utc = Column(Integer)
user = relationship("User")

View File

@ -72,22 +72,21 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
abort(400)
existing = existing.one_or_none()
if DOUBLE_XP_ENABLED > 0:
if not existing and int(time.time()) > DOUBLE_XP_ENABLED:
coin_mult = 2
elif existing and existing.created_utc > DOUBLE_XP_ENABLED:
coin_mult = 2
if DOUBLE_XP_ENABLED > 0 and int(time.time()) > DOUBLE_XP_ENABLED:
coin_mult = 2
coin_value = coin_delta * coin_mult
if existing and existing.vote_type == new: return "", 204
if existing:
if existing.vote_type == 0 and new != 0:
target.author.coins += coin_delta * coin_mult
target.author.coins += coin_value
target.author.truecoins += coin_delta
g.db.add(target.author)
existing.vote_type = new
existing.coins = coin_value
g.db.add(existing)
elif existing.vote_type != 0 and new == 0:
target.author.charge_account('coins', coin_delta * coin_mult)
target.author.charge_account('coins', existing.coins)
target.author.truecoins -= coin_delta
g.db.add(target.author)
g.db.delete(existing)
@ -95,7 +94,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
existing.vote_type = new
g.db.add(existing)
elif new != 0:
target.author.coins += coin_delta * coin_mult
target.author.coins += coin_value
target.author.truecoins += coin_delta
g.db.add(target.author)
@ -106,14 +105,16 @@ def vote_post_comment(target_id, new, v, cls, vote_cls):
vote_type=new,
submission_id=target_id,
app_id=v.client.application.id if v.client else None,
real = real
real=real,
coins=coin_value
)
elif vote_cls == CommentVote:
vote = CommentVote(user_id=v.id,
vote_type=new,
comment_id=target_id,
app_id=v.client.application.id if v.client else None,
real=real
real=real,
coins=coin_value
)
g.db.add(vote)
g.db.flush()