-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxboxapi.ahk
320 lines (261 loc) · 7.28 KB
/
xboxapi.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
class Xbox_Account extends Xbox_API
{
__New(axuid,aparsed_profile:="")
{
base.__New()
this.xuid := axuid
if !aparsed_profile
this.parsed_profile := Json2(this.Get_Profile(this.xuid))
else
this.parsed_profile := aparsed_profile
}
__Delete()
{
}
; This lets my_account.Gamertag return the gamertag
__Get(aProperty)
{
return this.parsed_profile[aProperty]
}
; Returns any xbox live messages
Messages()
{
return this.Xbox_API_Request("messages")
}
Friends()
{
base_friends := Json2(this.Get_Friends(this.xuid))
parsed_friends := Object()
Loop % base_friends.MaxIndex()
{
this_account := base_friends[A_Index]
parsed_friends.Insert(new Xbox_Account(this_account["id"], this_account))
}
return parsed_friends
}
Display_Friends()
{
parsed_friends := this.Friends()
friends_list := ""
Loop % parsed_friends.MaxIndex()
friends_list .= parsed_friends[A_Index]["Gamertag"] . "`n"
Sort, friends_list
msgbox % "Friends List(" . parsed_friends.MaxIndex() . "): `n" friends_list
}
Display_Profile()
{
profile_list := {}
for key, value in this.parsed_profile
profile_list .= key . ": " . value . "`n"
Sort, profile_List
msgbox % "Your Profile: " profile_list
}
Display_FriendsV1()
{
parsed_friends := Json2(this.Get_FriendsV1(this.xuid))["Friends"]
online_list := ""
offline_list := ""
Loop % parsed_friends.MaxIndex()
{
this_friend := parsed_friends[A_Index]
if this_friend["isOnline"]
online_list .= this_friend["Gamertag"] . "`n"
else
offline_list .= this_friend["Gamertag"] . "`n"
}
Sort, online_list
Sort, offline_list
msgbox % "Friends ListV1(" parsed_friends.MaxIndex() "): `n"
. "`n---Online Friends ---`n" online_list
. "`n`n---Offline Friends---`n" offline_list
}
Display_ProfileV1()
{
parsed_profile := Json2(this.Get_ProfileV1(this.xuid))["Player"]
profile_list := {}
for this_key, this_value in parsed_profile
{
profile_list .= this_key . ": " . this_value . "`n"
for key, value in parsed_profile[this_key]
{
profile_list .= key . ": " . value . "`n"
for akey, avalue in parsed_profile[this_key][key]
profile_list .= akey . ": " . avalue . "`n"
}
}
Sort, profile_List
msgbox % "Your ProfileV1: " profile_list
}
}
class Xbox_API
{
__New(api_key:="defalut_can_be_placed_here")
{
this.api_key := api_key
this.base_urlv1 := "https://xboxapi.com/v1/" ;v1
this.base_urlv2 := "https://xboxapi.com/v2/" ;v2
this.WinHttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
}
__Delete()
{
; this.WinHttpRequest.Open("GET",
}
DoubleToHex(d)
{
form := A_FormatInteger
SetFormat Integer, HEX
v := DllCall("ntdll.dll\RtlLargeIntegerShiftLeft",Double,d, UChar,0, Int64)
SetFormat Integer, %form%
Return v
}
; https://xboxapi.com/documentation
Xbox_API_Request(request, xuid := "")
{
if xuid
request_url := this.base_urlv2 . xuid . "/" . request
else
request_url := this.base_urlv2 . request
try
{
this.WinHttpRequest.Open("GET", request_url)
this.WinHttpRequest.SetRequestHeader("X-AUTH", this.api_key)
this.WinHttpRequest.Send()
this.WinHttpRequest.WaitForResponse(10)
if this.WinHttpRequest.GetResponseHeader("X-RateLimit-Remaining") < 1
msgbox % "Request limit reached, please wait minutes: " this.WinHttpRequest.GetResponseHeader("X-RateLimit-Reset") / 60
}
catch e
{
Msgbox % "An exception was thrown: `nwhat: " e.what "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra
msgbox % this.WinHttpRequest.ResponseText
msgbox % this.WinHttpRequest.ResponseBody
}
return this.WinHttpRequest.ResponseText
}
; https://xboxapi.com/v1/documentation
; Only have this for the Get_FriendsV1/Get_ProfileV1 since they returns the isOnline
Xbox_API_RequestV1(request, xuid := "")
{
; if xuid
; request_url := this.base_urlv1 . xuid . "/" . request
; else
request_url := this.base_urlv1 . request
try
{
this.WinHttpRequest.Open("GET", request_url)
this.WinHttpRequest.Send()
this.WinHttpRequest.WaitForResponse(60)
}
catch e
{
Msgbox % "An exception was thrown: `nwhat: " e.what "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra
msgbox % this.WinHttpRequest.ResponseText
msgbox % this.WinHttpRequest.ResponseBody
}
; Writes binary data then goes back to begining and Reads it as text
if (this.WinHttpRequest.ResponseBody )
{
ADO := ComObjCreate("ADODB.Stream")
ADO.Type := 1 ; 1: binary 2: text
ADO.Mode := 3
ADO.Open()
ADO.Write(this.WinHttpRequest.ResponseBody)
; Part to read t he text
ADO.Position := 0
ADO.Type := 2 ; 1: binary 2: text
ADO.Charset:= "utf-8"
return ADO.ReadText()
}
else
return this.WinHttpRequest.ResponseText
}
Get_GamerTag(xuid)
{
return this.Xbox_API_Request("gamertag/" . xuid)
}
Get_GamerTag_XUID(gamer_tag)
{
StringReplace, gamer_tag, gamer_tag, %A_Space%, +, ALL
return this.Xbox_API_Request("xuid/" . gamer_tag)
}
Get_Profile(xuid)
{
return this.Xbox_API_Request("profile", xuid)
}
; Only have it since it returns the isOnline
Get_ProfileV1(xuid)
{
gamer_tag := this.Get_GamerTag(xuid)
StringReplace, gamer_tag, gamer_tag, %A_Space%, +, ALL
return this.Xbox_API_RequestV1("profile/" . gamer_tag, xuid)
}
Get_GamerCard(xuid)
{
return this.Xbox_API_Request("gamercard", xuid)
}
Get_Presence(xuid)
{
return this.Xbox_API_Request("presence", xuid)
}
Get_Activity(xuid)
{
return this.Xbox_API_Request("activity", xuid)
}
Get_Recent_Activity(xuid)
{
return this.Xbox_API_Request("activity/recent", xuid)
}
Get_Friends(xuid)
{
return this.Xbox_API_Request("friends", xuid)
}
; Only have it since it returns the isOnline
Get_FriendsV1(xuid)
{
gamer_tag := this.Get_GamerTag(xuid)
StringReplace, gamer_tag, gamer_tag, %A_Space%, +, ALL
return this.Xbox_API_RequestV1("friends/" . gamer_tag, xuid)
}
Get_Followers(xuid)
{
return this.Xbox_API_Request("followers", xuid)
}
Get_Recent_Players()
{
return this.Xbox_API_Request("recent-players")
}
Get_Game_Clips(xuid)
{
return this.Xbox_API_Request("game-clips", xuid)
}
Get_Saved_Game_Clips(xuid)
{
return this.Xbox_API_Request("game-clips/saved", xuid)
}
Get_Game_Stats(title_id, xuid)
{
return this.Xbox_API_Request("game-stats" . title_id, xuid)
}
Get_Xbox_360_Games(xuid)
{
return this.Xbox_API_Request("xbox360games", xuid)
}
Get_Xbox_One_Games(xuid)
{
return this.Xbox_API_Request("xboxonegames", xuid)
}
Get_Game_Achievements(title_id, xuid)
{
return this.Xbox_API_Request("achievements/" . title_id, xuid)
}
Xbox_Game_Information_Product_Id(product_id)
{
return this.Xbox_API_Request("game-details/" . product_id)
}
Xbox_Game_Information_Game_ID(game_id)
{
; convert game_id to hex
game_id := this.DoubleToHex(game_id)
return this.Xbox_API_Request("game-details-hex/" . game_id)
}
}