Skip to content

Commit

Permalink
feat: add mods to player.last_np (#526)
Browse files Browse the repository at this point in the history
* Add mods to playr.last_np

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove debug print

* Add typing of mods to LastNp

* Make LastNp.mods noneable

* Make mods parsing consistent

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
minisbett and pre-commit-ci[bot] authored Feb 12, 2024
1 parent e0c0fdd commit 3b2c046
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/api/domains/cho.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,14 @@ async def handle(self, player: Player) -> None:
# use player mode if not specified
mode_vn = player.status.mode.as_vanilla

# parse the mods from regex
mods = None
if r_match["mods"] is not None:
mods = Mods.from_np(r_match["mods"][1:], mode_vn)

player.last_np = {
"bmap": bmap,
"mods": mods,
"mode_vn": mode_vn,
"timeout": time.time() + 300, # /np's last 5mins
}
Expand Down Expand Up @@ -1246,9 +1252,15 @@ async def handle(self, player: Player) -> None:
# use player mode if not specified
mode_vn = player.status.mode.as_vanilla

# parse the mods from regex
mods = None
if r_match["mods"] is not None:
mods = Mods.from_np(r_match["mods"][1:], mode_vn)

player.last_np = {
"bmap": bmap,
"mode_vn": mode_vn,
"mods": mods,
"timeout": time.time() + 300, # /np's last 5mins
}

Expand All @@ -1268,12 +1280,11 @@ async def handle(self, player: Player) -> None:
# calculate pp for common generic values
pp_calc_st = time.time_ns()

mods = None
if r_match["mods"] is not None:
# [1:] to remove leading whitespace
mods_str = r_match["mods"][1:]
mods = Mods.from_np(mods_str, mode_vn)
else:
mods = None

scores = [
ScoreParams(
Expand Down
1 change: 1 addition & 0 deletions app/objects/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Status:
class LastNp(TypedDict):
bmap: Beatmap
mode_vn: int
mods: Mods | None
timeout: float


Expand Down

0 comments on commit 3b2c046

Please sign in to comment.