From 66c8487a4a58aec0fc26fe6e103108a29c5e695f Mon Sep 17 00:00:00 2001 From: Abomasnow <7785022+exurd@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:03:07 +0000 Subject: [PATCH] api_reqs: use inventory api for asset badges --- modules/api_reqs.py | 22 ++++++++++++++-------- modules/rbx_types.py | 2 +- modules/script_loop.py | 32 ++++++++++++++++---------------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/modules/api_reqs.py b/modules/api_reqs.py index 0d17856..599cac9 100755 --- a/modules/api_reqs.py +++ b/modules/api_reqs.py @@ -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 @@ -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: diff --git a/modules/rbx_types.py b/modules/rbx_types.py index a961251..d9e6c77 100755 --- a/modules/rbx_types.py +++ b/modules/rbx_types.py @@ -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) diff --git a/modules/script_loop.py b/modules/script_loop.py index 8483e77..2a0edc0 100644 --- a/modules/script_loop.py +++ b/modules/script_loop.py @@ -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) @@ -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 @@ -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 @@ -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