Fix race condition exception by checking badge key exists #26

Merged
jynus merged 1 commits from cache_invalid_index into master 2023-09-08 09:36:29 +02:00

View File

@ -519,11 +519,15 @@ func get_badge(badge_name : String, channel_id : String = "_global", scale : Str
return caches[RequestType.BADGE][channel_id][cachename] return caches[RequestType.BADGE][channel_id][cachename]
func get_badge_mapping(channel_id : String = "_global") -> Dictionary: func get_badge_mapping(channel_id : String = "_global") -> Dictionary:
if !caches[RequestType.BADGE_MAPPING].has(channel_id): if caches[RequestType.BADGE_MAPPING].has(channel_id):
return caches[RequestType.BADGE_MAPPING][channel_id]
var filename : String = disk_cache_path + "/" + RequestType.keys()[RequestType.BADGE_MAPPING] + "/" + channel_id + ".json" var filename : String = disk_cache_path + "/" + RequestType.keys()[RequestType.BADGE_MAPPING] + "/" + channel_id + ".json"
if (disk_cache && FileAccess.file_exists(filename)): if (disk_cache && FileAccess.file_exists(filename)):
caches[RequestType.BADGE_MAPPING][channel_id] = JSON.parse_string(FileAccess.get_file_as_string(filename))["badge_sets"] var cache = JSON.parse_string(FileAccess.get_file_as_string(filename))
else: if "badge_sets" in cache:
return cache["badge_sets"]
var request : HTTPRequest = HTTPRequest.new() var request : HTTPRequest = HTTPRequest.new()
add_child(request) add_child(request)
request.request("https://api.twitch.tv/helix/chat/badges" + ("/global" if channel_id == "_global" else "?broadcaster_id=" + channel_id), [USER_AGENT, "Authorization: Bearer " + token["access_token"], "Client-Id:" + client_id, "Content-Type: application/json"], HTTPClient.METHOD_GET) request.request("https://api.twitch.tv/helix/chat/badges" + ("/global" if channel_id == "_global" else "?broadcaster_id=" + channel_id), [USER_AGENT, "Authorization: Bearer " + token["access_token"], "Client-Id:" + client_id, "Content-Type: application/json"], HTTPClient.METHOD_GET)