fix a couple of potentially rare 500s

remotes/1693045480750635534/spooky-22
justcool393 2022-10-15 04:02:02 -07:00
parent 6138c94a10
commit 32a4693da9
5 changed files with 11 additions and 9 deletions

View File

@ -815,7 +815,7 @@ class User(Base):
def ban(self, admin=None, reason=None, days=0):
def ban(self, admin=None, reason=None, days=0.0):
if days:
self.unban_utc = int(time.time()) + (days * 86400)
g.db.add(self)

View File

@ -62,6 +62,7 @@ def execute_snappy(post, v):
else: SNAPPY_CHOICES = SNAPPY_QUOTES
elif SNAPPY_MARSEYS: SNAPPY_CHOICES = SNAPPY_MARSEYS
elif SNAPPY_QUOTES: SNAPPY_CHOICES = SNAPPY_QUOTES
else: SNAPPY_CHOICES = [""]
body = random.choice(SNAPPY_CHOICES).strip()
if body.startswith(''):

View File

@ -993,7 +993,11 @@ def ban_user(user_id, v):
if user.admin_level > v.admin_level:
abort(403)
days = float(request.values.get("days")) if request.values.get('days') else 0
days = 0.0
try:
days = float(request.values.get("days"))
except:
pass
reason = request.values.get("reason").strip()[:256]
reason = filter_emojis_only(reason)
@ -1009,8 +1013,11 @@ def ban_user(user_id, v):
continue
x.ban(admin=v, reason=reason, days=days)
duration = "permanently"
if days:
days_txt = str(days).rstrip('.0')
duration = f"for {days_txt} day"
if days != 1: duration += "s"
if reason: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days for the following reason:\n\n> {reason}"
else: text = f"@{v.username} (Admin) has banned you for **{days_txt}** days."
else:
@ -1018,10 +1025,6 @@ def ban_user(user_id, v):
else: text = f"@{v.username} (Admin) has banned you permanently."
send_repeatable_notification(user.id, text)
if days == 0: duration = "permanently"
elif days == 1: duration = "for 1 day"
else: duration = f"for {days_txt} days"
note = f'reason: "{reason}", duration: {duration}'
ma=ModAction(

View File

@ -843,8 +843,8 @@ def submit_post(v, sub=None):
if len(url) > 2048:
return error("There's a 2048 character limit for URLs.")
bets = []
if v and v.admin_level >= PERMS['POST_BETS']:
bets = []
for i in bet_regex.finditer(body):
bets.append(i.group(1))
body = body.replace(i.group(0), "")

View File

@ -11,9 +11,7 @@ from files.helpers.sanitize import filter_emojis_only
@limiter.limit("1/second;30/minute;200/hour;1000/day", key_func=lambda:f'{SITE}-{session.get("lo_user")}')
@auth_required
def flag_post(pid, v):
post = get_post(pid)
reason = request.values.get("reason", "").strip()
if blackjack and any(i in reason.lower() for i in blackjack.split()):