Пример #1
0
def answer(req: ParsedRequest, event, creds: CredManager = CredManager):
    # assert_hunt_running(event)
    js = req.json
    answer = sanitize(js.get("answer", ""))
    # don't even bother if the user is trying an absurdly large answer
    if len(answer) > 50 or not answer:
        return {"is_correct": False}
    user = get_user_by_id(creds.user)
    if user.event != event:
        raise AppException("Not your event..")
    if user.is_disqualified:
        return {"disqualified": True, "reason": user.disqualification_reason}
    try:
        try:
            q = get_question(event, user.level)
        except AppException:
            return {"game_over": True}
        is_correct = sanitize(q["_secure_"]["answer"]) == answer
        log_answer(user.user, q["question_number"], js["answer"], is_correct)
        if is_correct:
            user.level += 1
            user.points += q["question_points"]
            user.last_question_answered_at = time()
            save_to_db()
            return invalidate(f"{event}-leaderboard", {"is_correct": is_correct})
        return {"is_correct": is_correct}

    except Exception as e:
        print(e)
        raise Exception("An unknown error occured")
Пример #2
0
def delete(user, creds: CredManager = CredManager):
    user_data = get_user_by_id(user)
    if user_data.is_admin:
        raise AppException("Cannot delete an admin account!")
    delete_from_db(user_data)
    send_admin_action_webhook([f"{user} was deleted by {creds.user}"])
    return {"success": True}
Пример #3
0
def requalify(user, creds=CredManager):
    user_data = get_user_by_id(user)
    user_data.is_disqualified = False
    user_data.disqualification_reason = None
    js = user_data.as_json
    save_to_db()
    send_admin_action_webhook([f"{user} was requalified by {creds.user}"])
    return invalidate(f"{user_data.event}-leaderboard", js)
Пример #4
0
def question(event, creds: CredManager = CredManager):
    # assert_hunt_running(event)
    user = get_user_by_id(creds.user)
    if user.event != event:
        raise AppException("Not your event..")
    if user.is_disqualified:
        return {"disqualified": True, "reason": user.disqualification_reason}
    try:
        try:
            q = get_question(event, user.level)
        except AppException:
            return {"game_over": True}
        q.pop("_secure_")
        return q
    except:
        raise Exception("Unknown error occured")
Пример #5
0
def disqualify(req: ParsedRequest, user, *, creds: CredManager = CredManager):
    json = req.json
    reason = json.get("reason")
    deduct_points = json.get("points")
    if deduct_points < 0:
        raise AppException("You're adding points! Don't use negative symbol")
    user_data = get_user_by_id(user)
    if user_data.is_admin:
        raise AppException("Cannot disqualify an admin!")
    user_data.is_disqualified = True
    user_data.disqualification_reason = reason
    user_data.points -= deduct_points
    js = user_data.as_json
    send_admin_action_webhook([f"{user} was disqualified by {creds.user}"])
    save_to_db()
    return invalidate(f"{user_data.event}-leaderboard", js)