comment betting code

remotes/1693045480750635534/spooky-22
Aevann1 2022-08-22 22:48:47 +02:00
parent 20e4e7c57a
commit 666b0cb063
2 changed files with 52 additions and 52 deletions

View File

@ -179,52 +179,52 @@ def remove_admin(v, username):
return {"message": "Admin removed!"}
@app.post("/distribute/<comment>")
@limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(3)
def distribute(v, comment):
autobetter = get_account(AUTOBETTER_ID)
if autobetter.coins == 0: return {"error": "@AutoBetter has 0 coins"}
# @app.post("/distribute/<comment>")
# @limiter.limit("1/second;30/minute;200/hour;1000/day")
# @admin_level_required(3)
# def distribute(v, comment):
# autobetter = get_account(AUTOBETTER_ID)
# if autobetter.coins == 0: return {"error": "@AutoBetter has 0 coins"}
try: comment = int(comment)
except: abort(400)
post = g.db.query(Comment.parent_submission).filter_by(id=comment).one_or_none()[0]
post = get_post(post)
# try: comment = int(comment)
# except: abort(400)
# post = g.db.query(Comment.parent_submission).filter_by(id=comment).one_or_none()[0]
# post = get_post(post)
pool = 0
for option in post.bet_options: pool += option.upvotes
pool *= 200
# pool = 0
# for option in post.bet_options: pool += option.upvotes
# pool *= 200
autobetter.coins -= pool
if autobetter.coins < 0: autobetter.coins = 0
g.db.add(autobetter)
# autobetter.coins -= pool
# if autobetter.coins < 0: autobetter.coins = 0
# g.db.add(autobetter)
votes = g.db.query(CommentVote).filter_by(comment_id=comment)
coinsperperson = int(pool / votes.count())
# votes = g.db.query(CommentVote).filter_by(comment_id=comment)
# coinsperperson = int(pool / votes.count())
cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:")
for vote in votes:
u = vote.user
u.coins += coinsperperson
add_notif(cid, u.id)
# cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:")
# for vote in votes:
# u = vote.user
# u.coins += coinsperperson
# add_notif(cid, u.id)
cid = notif_comment(f"You lost the 200 coins you bet on [{post.title}]({post.shortlink}) :marseylaugh:")
cids = [x.id for x in post.bet_options]
cids.remove(comment)
votes = g.db.query(CommentVote).filter(CommentVote.comment_id.in_(cids)).all()
for vote in votes: add_notif(cid, vote.user.id)
# cid = notif_comment(f"You lost the 200 coins you bet on [{post.title}]({post.shortlink}) :marseylaugh:")
# cids = [x.id for x in post.bet_options]
# cids.remove(comment)
# votes = g.db.query(CommentVote).filter(CommentVote.comment_id.in_(cids)).all()
# for vote in votes: add_notif(cid, vote.user.id)
post.body += '\n\nclosed'
g.db.add(post)
# post.body += '\n\nclosed'
# g.db.add(post)
ma = ModAction(
kind="distribute",
user_id=v.id,
target_comment_id=comment
)
g.db.add(ma)
# ma = ModAction(
# kind="distribute",
# user_id=v.id,
# target_comment_id=comment
# )
# g.db.add(ma)
return {"message": f"Each winner has received {coinsperperson} coins!"}
# return {"message": f"Each winner has received {coinsperperson} coins!"}
@app.post("/@<username>/revert_actions")
@limiter.limit("1/second;30/minute;200/hour;1000/day")

View File

@ -879,11 +879,11 @@ def submit_post(v, sub=None):
if len(url) > 2048:
return error("There's a 2048 character limit for URLs.")
if v and v.admin_level > 2:
bet_options = []
for i in bet_regex.finditer(body):
bet_options.append(i.group(1))
body = body.replace(i.group(0), "")
# if v and v.admin_level > 2:
# bet_options = []
# for i in bet_regex.finditer(body):
# bet_options.append(i.group(1))
# body = body.replace(i.group(0), "")
options = []
for i in poll_regex.finditer(body):
@ -951,17 +951,17 @@ def submit_post(v, sub=None):
g.db.add(v)
send_repeatable_notification(CARP_ID, post.permalink)
if v and v.admin_level > 2:
for option in bet_options:
bet_option = Comment(author_id=AUTOBETTER_ID,
parent_submission=post.id,
level=1,
body_html=filter_emojis_only(option),
upvotes=0,
is_bot=True
)
# if v and v.admin_level > 2:
# for option in bet_options:
# bet_option = Comment(author_id=AUTOBETTER_ID,
# parent_submission=post.id,
# level=1,
# body_html=filter_emojis_only(option),
# upvotes=0,
# is_bot=True
# )
g.db.add(bet_option)
# g.db.add(bet_option)
for option in options:
option = SubmissionOption(