11local json = require (" serializer.json" )
2- local http = require (" socket.http " )
2+ local web = require (" web " )
33function grabUserStats (userCode )
44 -- userCode: 'xxx#123'
5- local response_body = {}
6- local request_body = {
5+ local body = json .encode ({
76 operationName = " AccountManagementPageQuery" ,
87 variables = {
98 cc = string.format (" %s" , userCode ),
109 uid = string.format (" %s" , userCode )
1110 },
1211 query = " fragment userProfilePage on User {\n fbUid\n displayName\n connectCode {\n code\n __typename\n }\n status\n activeSubscription {\n level\n hasGiftSub\n __typename\n }\n rankedNetplayProfile {\n id\n ratingOrdinal\n ratingUpdateCount\n wins\n losses\n dailyGlobalPlacement\n dailyRegionalPlacement\n continent\n characters {\n id\n character\n gameCount\n __typename\n }\n __typename\n }\n __typename\n }\n\n query AccountManagementPageQuery($cc: String!, $uid: String!) {\n getUser(fbUid: $uid) {\n ...userProfilePage\n __typename\n }\n getConnectCode(code: $cc) {\n user {\n ...userProfilePage\n __typename\n }\n __typename\n }\n }\n "
13- }
14- request_body = json .encode (request_body )
15- print (request_body )
12+ })
13+ print (body )
1614
17- local res = http . request ({
18- url = ' https://gql-gateway-dot-slippi.uc.r.appspot.com/graphql' ,
19- method = " POST " ,
20- headers = {
15+ local res = web . post (
16+ ' https://gql-gateway-dot-slippi.uc.r.appspot.com/graphql' ,
17+ body ,
18+ {
2119 [" Content-Type" ] = " application/json" ,
22- [" Content-Length" ] = string.len (request_body )
20+ [" Content-Length" ] = string.len (body )
2321 },
24- source = ltn12 .source .string (request_body ),
25- sink = ltn12 .sink .table (response_body )
26- })
27- response_body = json .decode (response_body [1 ])
28-
29- if not response_body .data or not response_body .data .getConnectCode then return {' ' , ' ' } end
30- return {response_body .data .getConnectCode .user .displayName , math.floor (response_body .data .getConnectCode .user .rankedNetplayProfile .ratingOrdinal )}
22+ function (event )
23+ data = json .decode (event .response )
24+ if data .data and data .data .getConnectCode .user .displayName then
25+ return {data .data .getConnectCode .user .displayName , math.floor (data .data .getConnectCode .user .rankedNetplayProfile .ratingOrdinal )}
26+ end
27+ return {' ' , ' ' }
28+ end )
29+ -- if not response_body.data or not response_body.data.getConnectCode then return {'', ''} end
30+ -- return {response_body.data.getConnectCode.user.displayName, math.floor(response_body.data.getConnectCode.user.rankedNetplayProfile.ratingOrdinal)}
3131end
0 commit comments