add error codes

remotes/1693045480750635534/spooky-22
Aevann1 2022-09-12 11:52:07 +02:00
parent 7e811b47fb
commit 4abf75edc0
14 changed files with 64 additions and 64 deletions

View File

@ -194,7 +194,7 @@ def remove_admin(v, username):
@admin_level_required(3)
def distribute(v, option_id):
autojanny = get_account(AUTOJANNY_ID)
if autojanny.coins == 0: return {"error": "@AutoJanny has 0 coins"}
if autojanny.coins == 0: return {"error": "@AutoJanny has 0 coins"}, 400
try: option_id = int(option_id)
except: abort(400)
@ -310,7 +310,7 @@ def club_allow(v, username):
if not u: abort(404)
if u.admin_level >= v.admin_level: return {"error": "noob"}
if u.admin_level >= v.admin_level: return {"error": "noob"}, 400
u.club_allowed = True
g.db.add(u)
@ -337,7 +337,7 @@ def club_ban(v, username):
if not u: abort(404)
if u.admin_level >= v.admin_level: return {"error": "noob"}
if u.admin_level >= v.admin_level: return {"error": "noob"}, 400
u.club_allowed = False
@ -497,7 +497,7 @@ def purge_cache(v):
g.db.add(ma)
if response == "<Response [200]>": return {"message": "Cache purged!"}
return {"error": "Failed to purge cache."}
return {"error": "Failed to purge cache."}, 400
@app.post("/admin/under_attack")
@ -514,7 +514,7 @@ def under_attack(v):
response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"high"}', timeout=5))
if response == "<Response [200]>": return {"message": "Under attack mode disabled!"}
return {"error": "Failed to disable under attack mode."}
return {"error": "Failed to disable under attack mode."}, 400
else:
ma = ModAction(
kind="enable_under_attack",
@ -524,7 +524,7 @@ def under_attack(v):
response = str(requests.patch(f'https://api.cloudflare.com/client/v4/zones/{CF_ZONE}/settings/security_level', headers=CF_HEADERS, data='{"value":"under_attack"}', timeout=5))
if response == "<Response [200]>": return {"message": "Under attack mode enabled!"}
return {"error": "Failed to enable under attack mode."}
return {"error": "Failed to enable under attack mode."}, 400
@app.get("/admin/badge_grant")
@admin_level_required(2)
@ -1156,7 +1156,7 @@ def approve_post(post_id, v):
post = get_post(post_id)
if post.author.id == v.id and post.author.agendaposter and AGENDAPOSTER_PHRASE not in post.body.lower() and post.sub != 'chudrama':
return {"error": "You can't bypass the chud award!"}
return {"error": "You can't bypass the chud award!"}, 400
if not post:
abort(400)
@ -1351,7 +1351,7 @@ def approve_comment(c_id, v):
if not comment: abort(404)
if comment.author.id == v.id and comment.author.agendaposter and AGENDAPOSTER_PHRASE not in comment.body.lower() and comment.post.sub != 'chudrama':
return {"error": "You can't bypass the chud award!"}
return {"error": "You can't bypass the chud award!"}, 400
if comment.is_banned:
ma=ModAction(

View File

@ -460,7 +460,7 @@ def admin_userawards_post(v):
for key, value in notify_awards.items():
note += f"{value} {AWARDS[key]['title']}, "
if len(note) > 500: return {"error": "You're giving too many awards at the same time!"}
if len(note) > 500: return {"error": "You're giving too many awards at the same time!"}, 400
ma=ModAction(
kind="grant_awards",

View File

@ -58,34 +58,34 @@ def casino_game_feed(v, game):
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
def pull_slots(v):
if v.rehab: return {"error": "You are under Rehab award effect!"}
if v.rehab: return {"error": "You are under Rehab award effect!"}, 400
try:
wager = int(request.values.get("wager"))
except:
return {"error": "Invalid wager."}
return {"error": "Invalid wager."}, 400
try:
currency = request.values.get("currency")
except:
return {"error": "Invalid currency (expected 'dramacoin' or 'marseybux')."}
return {"error": "Invalid currency (expected 'dramacoin' or 'marseybux')."}, 400
if (currency == "dramacoin" and wager > v.coins) or (currency == "marseybux" and wager > v.procoins):
return {"error": f"Not enough {currency} to make that bet."}
return {"error": f"Not enough {currency} to make that bet."}, 400
success, game_state = casino_slot_pull(v, wager, currency)
if success:
return {"game_state": game_state, "gambler": {"coins": v.coins, "procoins": v.procoins}}
else:
return {"error": f"Wager must be more than 5 {currency}."}
return {"error": f"Wager must be more than 5 {currency}."}, 400
@app.post("/casino/twentyone/deal")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
def blackjack_deal_to_player(v):
if v.rehab: return {"error": "You are under Rehab award effect!"}
if v.rehab: return {"error": "You are under Rehab award effect!"}, 400
try:
wager = int(request.values.get("wager"))
@ -103,53 +103,53 @@ def blackjack_deal_to_player(v):
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
def blackjack_player_hit(v):
if v.rehab: return {"error": "You are under Rehab award effect!"}
if v.rehab: return {"error": "You are under Rehab award effect!"}, 400
try:
state = dispatch_action(v, BlackjackAction.HIT)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
return {"error": "Unable to hit."}
return {"error": "Unable to hit."}, 400
@app.post("/casino/twentyone/stay")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
def blackjack_player_stay(v):
if v.rehab: return {"error": "You are under Rehab award effect!"}
if v.rehab: return {"error": "You are under Rehab award effect!"}, 400
try:
state = dispatch_action(v, BlackjackAction.STAY)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
return {"error": "Unable to stay."}
return {"error": "Unable to stay."}, 400
@app.post("/casino/twentyone/double-down")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
def blackjack_player_doubled_down(v):
if v.rehab: return {"error": "You are under Rehab award effect!"}
if v.rehab: return {"error": "You are under Rehab award effect!"}, 400
try:
state = dispatch_action(v, BlackjackAction.DOUBLE_DOWN)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
return {"error": "Unable to double down."}
return {"error": "Unable to double down."}, 400
@app.post("/casino/twentyone/buy-insurance")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
def blackjack_player_bought_insurance(v):
if v.rehab: return {"error": "You are under Rehab award effect!"}
if v.rehab: return {"error": "You are under Rehab award effect!"}, 400
try:
state = dispatch_action(v, BlackjackAction.BUY_INSURANCE)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
return {"error": "Unable to buy insurance."}
return {"error": "Unable to buy insurance."}, 400

View File

@ -69,7 +69,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
post = get_post(pid, v=v)
if post.over_18 and not (v and v.over_18) and not session.get('over_18', 0) >= int(time.time()):
if request.headers.get("Authorization"): return {'error': 'This content is not suitable for some users and situations.'}
if request.headers.get("Authorization"): return {"error": 'This content is not suitable for some users and situations.'}, 403
else: return render_template("errors/nsfw.html", v=v)
try: context = min(int(request.values.get("context", 0)), 8)
@ -149,7 +149,7 @@ def comment(v):
if sub and v.exiled_from(sub): return {"error": f"You're exiled from /h/{sub}"}, 403
if sub in ('furry','vampire','racist','femboy') and not v.client and not v.house.lower().startswith(sub):
return {"error": f"You need to be a member of House {sub.capitalize()} to comment in /h/{sub}"}
return {"error": f"You need to be a member of House {sub.capitalize()} to comment in /h/{sub}"}, 400
if parent_post.club and not (v and (v.paid_dues or v.id == parent_post.author_id)): abort(403)
@ -196,7 +196,7 @@ def comment(v):
oldname = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(oldname)
image = process_image(oldname)
if image == "": return {"error":"Image upload failed"}
if image == "": return {"error":"Image upload failed"}, 400
if v.admin_level > 2 and level == 1:
if parent_post.id == SIDEBAR_THREAD:
li = sorted(os.listdir(f'files/assets/images/{SITE_NAME}/sidebar'),
@ -796,7 +796,7 @@ def unpin_comment(cid, v):
if v.id != comment.post.author_id: abort(403)
if not comment.stickied.endswith(" (OP)"):
return {"error": "You can only unpin comments you have pinned!"}
return {"error": "You can only unpin comments you have pinned!"}, 400
comment.stickied = None
g.db.add(comment)

View File

@ -9,7 +9,7 @@ import requests
@is_not_permabanned
def join_discord(v):
if v.shadowbanned: return {"error": "Internal server error"}
if v.shadowbanned: return {"error": "Internal server error"}, 400
now=int(time.time())

View File

@ -38,13 +38,13 @@ def buy_hat(v, hat_id):
if not FEATURES['HATS']: abort(404)
try: hat_id = int(hat_id)
except: return {"error": "Hat not found!"}
except: return {"error": "Hat not found!"}, 400
hat = g.db.query(HatDef).filter_by(submitter_id=None, id=hat_id).one_or_none()
if not hat: return {"error": "Hat not found!"}
if not hat: return {"error": "Hat not found!"}, 400
existing = g.db.query(Hat).filter_by(user_id=v.id, hat_id=hat.id).one_or_none()
if existing: return {"error": "You already own this hat!"}
if existing: return {"error": "You already own this hat!"}, 400
if request.values.get("mb"):
if v.procoins < hat.price: return {"error": "Not enough marseybux."}, 400
@ -85,10 +85,10 @@ def equip_hat(v, hat_id):
if not FEATURES['HATS']: abort(404)
try: hat_id = int(hat_id)
except: return {"error": "Hat not found!"}
except: return {"error": "Hat not found!"}, 400
hat = g.db.query(Hat).filter_by(hat_id=hat_id, user_id=v.id).one_or_none()
if not hat: return {"error": "You don't own this hat!"}
if not hat: return {"error": "You don't own this hat!"}, 400
hat.equipped = True
g.db.add(hat)
@ -101,10 +101,10 @@ def unequip_hat(v, hat_id):
if not FEATURES['HATS']: abort(404)
try: hat_id = int(hat_id)
except: return {"error": "Hat not found!"}
except: return {"error": "Hat not found!"}, 400
hat = g.db.query(Hat).filter_by(hat_id=hat_id, user_id=v.id).one_or_none()
if not hat: return {"error": "You don't own this hat!"}
if not hat: return {"error": "You don't own this hat!"}, 400
hat.equipped = False
g.db.add(hat)

View File

@ -29,7 +29,7 @@ def lottery_start(v):
@casino_required
def lottery_buy(v):
try: quantity = int(request.values.get("quantity"))
except: return {"error": "Invalid ticket quantity."}
except: return {"error": "Invalid ticket quantity."}, 400
success, message = purchase_lottery_tickets(v, quantity)
lottery, participants = get_active_lottery_stats()

View File

@ -19,10 +19,10 @@ def vote_option(option_id, v):
sub = option.post.sub
if sub in ('furry','vampire','racist','femboy') and not v.house.lower().startswith(sub):
return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"}
return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"}, 400
if option.exclusive == 2:
if v.coins < 200: return {"error": "You don't have 200 coins!"}
if v.coins < 200: return {"error": "You don't have 200 coins!"}, 400
v.coins -= 200
g.db.add(v)
autojanny = get_account(AUTOJANNY_ID)
@ -35,7 +35,7 @@ def vote_option(option_id, v):
SubmissionOptionVote.submission_id==option.submission_id,
SubmissionOption.exclusive==option.exclusive).one_or_none()
if vote:
if option.exclusive == 2: return {"error": "You already voted on this bet!"}
if option.exclusive == 2: return {"error": "You already voted on this bet!"}, 400
g.db.delete(vote)
existing = g.db.query(SubmissionOptionVote).filter_by(option_id=option_id, user_id=v.id).one_or_none()
@ -85,7 +85,7 @@ def vote_option_comment(option_id, v):
sub = option.comment.post.sub
if sub in ('furry','vampire','racist','femboy') and not v.house.lower().startswith(sub):
return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"}
return {"error": f"You need to be a member of House {sub.capitalize()} to vote on polls in /h/{sub}"}, 400
if option.exclusive:
vote = g.db.query(CommentOptionVote).join(CommentOption).filter(

View File

@ -1241,7 +1241,7 @@ def pin_post(post_id, v):
post = get_post(post_id)
if post:
if v.id != post.author_id: return {"error": "Only the post author's can do that!"}
if v.id != post.author_id: return {"error": "Only the post author's can do that!"}, 400
post.is_pinned = not post.is_pinned
g.db.add(post)
@ -1249,7 +1249,7 @@ def pin_post(post_id, v):
if post.is_pinned: return {"message": "Post pinned!"}
else: return {"message": "Post unpinned!"}
return {"error": "Post not found!"}
return {"error": "Post not found!"}, 400
extensions = (

View File

@ -21,13 +21,13 @@ def flag_post(pid, v):
send_repeatable_notification(CARP_ID, f"reports on {post.permalink}")
if v.is_muted:
return {"error": "You are forbidden from making reports."}
return {"error": "You are forbidden from making reports."}, 400
reason = reason[:100]
reason = filter_emojis_only(reason)
if len(reason) > 350: return {"error": "Too long."}
if len(reason) > 350: return {"error": "Too long."}, 400
if reason.startswith('!') and (v.admin_level > 1 or post.sub and v.mods(post.sub)):
post.flair = reason[1:]
@ -47,16 +47,16 @@ def flag_post(pid, v):
sub_to = g.db.query(Sub).filter_by(name=sub_to).one_or_none()
sub_to = sub_to.name if sub_to else None
if sub_from == sub_to: abort(400)
if sub_from == sub_to: {"error": f"Post is already in /h/{sub_to}"}, 400
if post.author.exiled_from(sub_to):
return {"error": f"User is exiled from this {HOLE_NAME}!"}
return {"error": f"User is exiled from this {HOLE_NAME}!"}, 400
if sub_to in ('furry','vampire','racist','femboy') and not v.client and not post.author.house.lower().startswith(sub_to):
if v.id == post.author_id:
return {"error": f"You need to be a member of House {sub.capitalize()} to post in /h/{sub}"}
return {"error": f"You need to be a member of House {sub.capitalize()} to post in /h/{sub}"}, 403
else:
return {"error": f"@{post.author.username} needs to be a member of House {sub.capitalize()} for their post to be moved to /h/{sub}"}
return {"error": f"@{post.author.username} needs to be a member of House {sub.capitalize()} for their post to be moved to /h/{sub}"}, 400
post.sub = sub_to
g.db.add(post)
@ -108,7 +108,7 @@ def flag_comment(cid, v):
reason = filter_emojis_only(reason)
if len(reason) > 350: return {"error": "Too long."}
if len(reason) > 350: return {"error": "Too long."}, 400
flag = CommentFlag(comment_id=comment.id, user_id=v.id, reason=reason)

View File

@ -72,10 +72,10 @@ def searchposts(v):
if 'author' in criteria:
posts = posts.filter(Submission.ghost == False)
author = get_user(criteria['author'])
if not author: return {"error": "User not found"}
if not author: return {"error": "User not found"}, 400
if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye:
if request.headers.get("Authorization"):
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}, 400
return render_template("search.html",
v=v,
query=query,
@ -202,17 +202,17 @@ def searchcomments(v):
if 'post' in criteria:
try: post = int(criteria['post'])
except: return {"error": f"Post with id {post} does not exist."}
except: return {"error": f"Post with id {post} does not exist."}, 400
comments = comments.filter(Comment.parent_submission == post)
if 'author' in criteria:
comments = comments.filter(Comment.ghost == False)
author = get_user(criteria['author'])
if not author: return {"error": "User not found"}
if not author: return {"error": "User not found"}, 400
if author.is_private and author.id != v.id and v.admin_level < 2 and not v.eye:
if request.headers.get("Authorization"):
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}
return {"error": f"@{author.username}'s profile is private; You can't use the 'author' syntax on them"}, 400
return render_template("search_comments.html", v=v, query=query, total=0, page=page, comments=[], sort=sort, t=t, next_exists=False, error=f"@{author.username}'s profile is private; You can't use the 'author' syntax on them.")

View File

@ -258,7 +258,7 @@ def settings_profile_post(v):
if theme:
if theme in {"4chan","classic","classic_dark","coffee","dark","dramblr","light","midnight","transparent","tron","win98"}:
if theme == "transparent" and not v.background:
return {"error": "You need to set a background to use the transparent theme!"}
return {"error": "You need to set a background to use the transparent theme!"}, 400
v.theme = theme
if theme == "win98": v.themecolor = "30409f"
updated = True
@ -581,12 +581,12 @@ def settings_css_get(v):
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
@auth_required
def settings_css(v):
if v.agendaposter: return {"error": "Agendapostered users can't edit css!"}
if v.agendaposter: return {"error": "Agendapostered users can't edit css!"}, 400
css = request.values.get("css").strip().replace('\\', '').strip()[:4000]
if '</style' in css.lower():
return {"error": "Please message @Aevann if you get this error"}
return {"error": "Please message @Aevann if you get this error"}, 400
v.css = css
g.db.add(v)

View File

@ -247,7 +247,7 @@ def add_mod(v, sub):
user = get_user(user)
if sub in ('furry','vampire','racist','femboy') and not v.client and not user.house.lower().startswith(sub):
return {"error": f"@{user.username} needs to be a member of House {sub.capitalize()} to be added as a mod there!"}
return {"error": f"@{user.username} needs to be a member of House {sub.capitalize()} to be added as a mod there!"}, 400
existing = g.db.query(Mod).filter_by(user_id=user.id, sub=sub).one_or_none()

View File

@ -696,7 +696,7 @@ def message2(v, username):
message = request.values.get("message", "").strip()[:10000].strip()
if not message: return {"error": "Message is empty!"}
if not message: return {"error": "Message is empty!"}, 400
if 'linkedin.com' in message: return {"error": "This domain 'linkedin.com' is banned."}, 403
@ -761,18 +761,18 @@ def messagereply(v):
body = request.values.get("body", "").strip().replace('','')
body = body.replace('\r\n', '\n')[:10000]
if not body and not request.files.get("file"): return {"error": "Message is empty!"}
if not body and not request.files.get("file"): return {"error": "Message is empty!"}, 400
if 'linkedin.com' in body: return {"error": "this domain 'linkedin.com' is banned"}
if 'linkedin.com' in body: return {"error": "this domain 'linkedin.com' is banned"}, 400
id = int(request.values.get("parent_id"))
parent = get_comment(id, v=v)
user_id = parent.author.id
if v.is_suspended_permanently and parent.sentto != 2:
return {"error": "You are permabanned and may not reply to messages."}
return {"error": "You are permabanned and may not reply to messages."}, 400
elif v.is_muted and parent.sentto == 2:
return {"error": "You are forbidden from replying to modmail."}
return {"error": "You are forbidden from replying to modmail."}, 400
if parent.sentto == 2: user_id = None
elif v.id == user_id: user_id = parent.sentto
@ -1189,7 +1189,7 @@ def unfollow_user(username, v):
if target.fish:
if not v.shadowbanned:
send_notification(target.id, f"@{v.username} has tried to unfollow you and failed because of your fish award!")
return {"error": "You can't unfollow this user!"}
return {"error": "You can't unfollow this user!"}, 400
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).one_or_none()