Skip to content

Commit

Permalink
api_reqs: use inventory api for asset badges
Browse files Browse the repository at this point in the history
  • Loading branch information
exurd committed Nov 24, 2024
1 parent b6aef88 commit 66c8487
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
22 changes: 14 additions & 8 deletions modules/api_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,13 @@ def get_universe_votes(universe_id) -> dict:
return False


def check_user_inv_for_asset(user_id=0, asset_id=0) -> bool:
def check_user_inv_with_inventory_api(user_id=0, asset_id=0) -> bool:
"""
Checks if user has an *ASSET* in their inventory.
Results are not cached.
DO NOT USE THIS TO CHECK FOR BADGES! (Specifically, any new badges)
Technically deprecated, might become useful in the future.
DO NOT USE THIS TO CHECK FOR BADGES ABOVE 2124421088!
See checkUserInvForBadge for info.
(TODO: find last asset-badge id, create hybrid function using both apis)
"""
if user_id != 0 and user_id is not None and asset_id != 0:
# inventory_api outputs just "true" or "false" in lowercase
Expand All @@ -377,12 +374,21 @@ def check_user_inv_for_badge(user_id=0, badge_id=0) -> bool:
Badge IDs and Asset IDs use different ID systems.
Badges split off from assets in July 2018,
using the above function looks like it will work for
the above function looks like it will work for
every badge until you get to those newer badges.
This function uses the correct API to check for badges.
Only downside is that it's more rate limited than the inventory API.
This function uses the Badges API, which
will check the newer badges as intended.
The only downside is that it's more rate
limited than the inventory API.
So, if the specifed badge ID is below 2124421087 (the first badge ID - 1),
the function will call check_user_inv_with_inventory_api to utilise
the better rate limit api.
"""
if badge_id <= 2124421087: # should be before the first badge id
return check_user_inv_with_inventory_api(user_id=user_id, asset_id=badge_id)

if user_id != 0 and user_id is not None and badge_id != 0:
userbadge_check = get_request_url(f"https://badges.roblox.com/v1/users/{str(user_id)}/badges/awarded-dates?badgeIds={str(badge_id)}", cache_results=False)
if userbadge_check.ok:
Expand Down
2 changes: 1 addition & 1 deletion modules/rbx_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def detect_string_type(self, string: str):
vPrint("Setting type to rbxType.UNKNOWN")
id_type = RbxType.UNKNOWN

self.id = roblox_id
self.id = int(roblox_id)
self.type = id_type
vPrint(self)

Expand Down
32 changes: 16 additions & 16 deletions modules/script_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def deal_with_badge(badge_rbxinstance: RbxInstance, user_id=None, awarded_thresh
return RbxReason.NOT_ENABLED

if user_id is not None:
check_inventory = api_reqs.check_user_inv_for_asset(user_id, badge_rbxinstance.id)
check_inventory = api_reqs.check_user_inv_for_badge(user_id, badge_rbxinstance.id)
if check_inventory:
print("Badge has already been collected, skipping!")
data_save.GOTTEN_BADGES.append(badge_rbxinstance.id)
Expand Down Expand Up @@ -71,11 +71,11 @@ def deal_with_badge(badge_rbxinstance: RbxInstance, user_id=None, awarded_thresh
process_handle.open_place_in_browser(root_place_id)

process_handle.open_roblox_place(root_place_id,
name=badge_info["awardingUniverse"]["name"],
use_bloxstrap=use_bloxstrap,
use_sober=use_sober,
sober_opts=sober_opts
)
name=badge_info["awardingUniverse"]["name"],
use_bloxstrap=use_bloxstrap,
use_sober=use_sober,
sober_opts=sober_opts
)
return RbxReason.PROCESS_OPENED


Expand Down Expand Up @@ -108,11 +108,11 @@ def deal_with_place(place_rbxinstance: RbxInstance, vote_threshold=-1.0, check_i
process_handle.open_place_in_browser(place_rbxinstance.id)

process_handle.open_roblox_place(place_rbxinstance.id,
name=place_info["name"],
use_bloxstrap=use_bloxstrap,
use_sober=use_sober,
sober_opts=sober_opts
)
name=place_info["name"],
use_bloxstrap=use_bloxstrap,
use_sober=use_sober,
sober_opts=sober_opts
)
return RbxReason.PROCESS_OPENED


Expand Down Expand Up @@ -148,11 +148,11 @@ def deal_with_universe(universe_rbxinstance: RbxInstance, vote_threshold=-1.0, c
process_handle.open_place_in_browser(root_place_id)

process_handle.open_roblox_place(root_place_id,
name=universe_info["name"],
use_bloxstrap=use_bloxstrap,
use_sober=use_sober,
sober_opts=sober_opts
)
name=universe_info["name"],
use_bloxstrap=use_bloxstrap,
use_sober=use_sober,
sober_opts=sober_opts
)
return RbxReason.PROCESS_OPENED


Expand Down

0 comments on commit 66c8487

Please sign in to comment.