forked from rDrama/rDrama
1
0
Fork 0

comment betting code

master
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!"} return {"message": "Admin removed!"}
@app.post("/distribute/<comment>") # @app.post("/distribute/<comment>")
@limiter.limit("1/second;30/minute;200/hour;1000/day") # @limiter.limit("1/second;30/minute;200/hour;1000/day")
@admin_level_required(3) # @admin_level_required(3)
def distribute(v, comment): # def distribute(v, comment):
autobetter = get_account(AUTOBETTER_ID) # autobetter = get_account(AUTOBETTER_ID)
if autobetter.coins == 0: return {"error": "@AutoBetter has 0 coins"} # if autobetter.coins == 0: return {"error": "@AutoBetter has 0 coins"}
try: comment = int(comment) # try: comment = int(comment)
except: abort(400) # except: abort(400)
post = g.db.query(Comment.parent_submission).filter_by(id=comment).one_or_none()[0] # post = g.db.query(Comment.parent_submission).filter_by(id=comment).one_or_none()[0]
post = get_post(post) # post = get_post(post)
pool = 0 # pool = 0
for option in post.bet_options: pool += option.upvotes # for option in post.bet_options: pool += option.upvotes
pool *= 200 # pool *= 200
autobetter.coins -= pool # autobetter.coins -= pool
if autobetter.coins < 0: autobetter.coins = 0 # if autobetter.coins < 0: autobetter.coins = 0
g.db.add(autobetter) # g.db.add(autobetter)
votes = g.db.query(CommentVote).filter_by(comment_id=comment) # votes = g.db.query(CommentVote).filter_by(comment_id=comment)
coinsperperson = int(pool / votes.count()) # coinsperperson = int(pool / votes.count())
cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:") # cid = notif_comment(f"You won {coinsperperson} coins betting on [{post.title}]({post.shortlink}) :marseyparty:")
for vote in votes: # for vote in votes:
u = vote.user # u = vote.user
u.coins += coinsperperson # u.coins += coinsperperson
add_notif(cid, u.id) # add_notif(cid, u.id)
cid = notif_comment(f"You lost the 200 coins you bet on [{post.title}]({post.shortlink}) :marseylaugh:") # 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 = [x.id for x in post.bet_options]
cids.remove(comment) # cids.remove(comment)
votes = g.db.query(CommentVote).filter(CommentVote.comment_id.in_(cids)).all() # votes = g.db.query(CommentVote).filter(CommentVote.comment_id.in_(cids)).all()
for vote in votes: add_notif(cid, vote.user.id) # for vote in votes: add_notif(cid, vote.user.id)
post.body += '\n\nclosed' # post.body += '\n\nclosed'
g.db.add(post) # g.db.add(post)
ma = ModAction( # ma = ModAction(
kind="distribute", # kind="distribute",
user_id=v.id, # user_id=v.id,
target_comment_id=comment # target_comment_id=comment
) # )
g.db.add(ma) # 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") @app.post("/@<username>/revert_actions")
@limiter.limit("1/second;30/minute;200/hour;1000/day") @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: if len(url) > 2048:
return error("There's a 2048 character limit for URLs.") return error("There's a 2048 character limit for URLs.")
if v and v.admin_level > 2: # if v and v.admin_level > 2:
bet_options = [] # bet_options = []
for i in bet_regex.finditer(body): # for i in bet_regex.finditer(body):
bet_options.append(i.group(1)) # bet_options.append(i.group(1))
body = body.replace(i.group(0), "") # body = body.replace(i.group(0), "")
options = [] options = []
for i in poll_regex.finditer(body): for i in poll_regex.finditer(body):
@ -951,17 +951,17 @@ def submit_post(v, sub=None):
g.db.add(v) g.db.add(v)
send_repeatable_notification(CARP_ID, post.permalink) send_repeatable_notification(CARP_ID, post.permalink)
if v and v.admin_level > 2: # if v and v.admin_level > 2:
for option in bet_options: # for option in bet_options:
bet_option = Comment(author_id=AUTOBETTER_ID, # bet_option = Comment(author_id=AUTOBETTER_ID,
parent_submission=post.id, # parent_submission=post.id,
level=1, # level=1,
body_html=filter_emojis_only(option), # body_html=filter_emojis_only(option),
upvotes=0, # upvotes=0,
is_bot=True # is_bot=True
) # )
g.db.add(bet_option) # g.db.add(bet_option)
for option in options: for option in options:
option = SubmissionOption( option = SubmissionOption(