Skip to content

Commit

Permalink
updating scoreboard and grant_points
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyftXero committed Nov 29, 2023
1 parent 1611d52 commit bc64120
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 7 additions & 5 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,18 @@ def get_user_by_id(target: str | int) -> User:

@db_session
def grant_points(
user: str,
requested_user: str,
admin_user: db.User = None,
amount: float = 0,
msg: str = "admin granted points",
):
# logger.debug('granting', amount, requested_user, admin_user, msg)
botuser = db.User.get(name=SETTINGS["_botusername"])
if admin_user == None:
admin_user = botuser
user = db.User.get(name=user)
if user:
# logger.debug(admin_user.name)
user = db.User.get(name=requested_user)
if user != None:
t = db.Transaction(
sender=botuser,
recipient=user,
Expand All @@ -323,10 +325,10 @@ def grant_points(
message=f"{admin_user.name}: {msg}",
)
db.commit()
print(f"granted {amount} points to {user.name}")
logger.debug(f"granted {amount} points to {user.name}")
return True
else:
print("invalid user")
logger.debug("invalid user", requested_user)
return False


Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies = [
"fire>=0.5.0",
"flask>=3.0.0",
"flask_cors>=4.0.0",
"PyNaCl>=1.5.0",
"pynacl>=1.5.0",
"networkx>=3.1",
"pycryptodome>=3.19.0",
"pyfiglet>=0.8.post1",
Expand All @@ -28,6 +28,7 @@ dependencies = [
"markdown2>=2.4.10",
"rich>=13.7.0",
"flask-limiter==3.3.0",
"ipython>=8.12.3",
]
readme = "README.md"
requires-python = ">= 3.8"
Expand Down
12 changes: 6 additions & 6 deletions scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,33 +197,33 @@ def grant_points():
target_user = payload.get("target_user")

if target_user == None:
return "Invalid target_user in payload"
return "Invalid target_user in payload", 405
points = payload.get("points")
if points == None:
return "points missing from payload"
return "points missing from payload", 405
points = float(points)
message = payload.get("message")
if message == None:
return "message missing from payload"
return "message missing from payload", 405
# did they present one?
api_key = payload.get("admin_api_key")
if api_key == None:
return "admin_api_key missing from payload"
return "admin_api_key missing from payload", 405
# did they present the correct one?
admin_user = db.get_user_by_api_key(api_key)
if admin_user == None:
return "invalid admin api key", 403

# seems legit...
res = db.grant_points(
user=target_user, admin_user=admin_user, amount=points, msg=message
requested_user=target_user, admin_user=admin_user, amount=points, msg=message
)

if res:
return {"status": "sucess", "orig_request": payload}

else:
return {"status": "db error", "orig_request": payload}
return {"status": "db error", "orig_request": payload}, 400


@app.get("/api/get_team/<target>")
Expand Down

0 comments on commit bc64120

Please sign in to comment.