-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.lua
More file actions
1051 lines (908 loc) · 24.5 KB
/
Copy pathinit.lua
File metadata and controls
1051 lines (908 loc) · 24.5 KB
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local http = require("coro-http")
local json = require("json")
local timer = require("timer")
local uv = require("uv")
local ropi = {
cache = {
users = {},
weakUsers = {},
avatars = {},
groups = {}
},
cookie = nil,
Requests = {},
Ratelimits = {},
ActiveBuckets = {},
RequestOrigins = {},
Domains = {
{
name = "roblox",
parse = function(api)
return api .. ".roblox.com"
end
},
{
name = "RoProxy",
parse = function(api)
return api .. ".RoProxy.com"
end
},
{
name = "ropiproxy",
parse = function(api)
return "ropiproxy.vercel.app/" .. api
end
},
{
name = "ropiproxytwo",
parse = function(api)
return "ropiproxytwo.vercel.app/" .. api
end
},
{
name = "ropiproxythree",
parse = function(api)
return "ropiproxythree.vercel.app/" .. api
end
}
}
}
-- general utilities
local function split(str, delim)
local ret = {}
if not str then
return ret
end
if not delim or delim == "" then
for c in string.gmatch(str, ".") do
table.insert(ret, c)
end
return ret
end
local n = 1
while true do
local i, j = find(str, delim, n)
if not i then
break
end
table.insert(ret, sub(str, n, i - 1))
n = j + 1
end
table.insert(ret, sub(str, n))
return ret
end
local function hasHeader(headers, name)
for _, header in pairs(headers) do
if header[1]:lower() == name:lower() then
return true
end
end
return false
end
local function fromISO(iso)
if not iso then
return
end
local year, month, day, hour, min, sec, ms = iso:match("(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+).(%d+)Z")
if not year or not month or not day or not hour or not min or not sec or not ms then
return
end
local epoch = os.time({
year = tonumber(year),
month = tonumber(month),
day = tonumber(day),
hour = tonumber(hour),
min = tonumber(min),
sec = tonumber(sec),
isdst = false
})
return epoch + (tonumber(ms) / 1000)
end
local function realtime()
local seconds, microseconds = uv.gettimeofday()
return seconds + (microseconds / 1000000)
end
local function safeResume(co, ...)
if type(co) ~= "thread" then
return false, "Invalid coroutine"
end
if coroutine.status(co) ~= "suspended" then
return false, "Coroutine not suspended"
end
local ok, result = coroutine.resume(co, ...)
if not ok then
return false, result
end
return true, result
end
-- cache utilities
local maxCacheSize = 250
local function intoCache(item, category)
for i = #ropi.cache[category], 1, -1 do
local u = ropi.cache[category][i]
if u.id == item.id then
table.remove(ropi.cache[category], i)
end
end
table.insert(ropi.cache[category], item)
if #ropi.cache[category] > maxCacheSize then
table.remove(ropi.cache[category], 1)
end
return item
end
local function fromCache(query, category)
for _, item in pairs(ropi.cache[category]) do
if (tostring(query):lower() == item.name:lower()) or (tonumber(query) == item.id) then
return item
end
end
end
-- objects
local function User(data)
return {
name = data.name,
displayName = data.displayName,
id = data.id,
description = data.description,
avatar = ropi.GetAvatarHeadShot(data.id) or "https://duckybot.xyz/images/icons/RobloxConfused.png",
verified = not not data.hasVerifiedBadge,
banned = not not data.isBanned,
created = fromISO(data.created),
profile = "https://roblox.com/users/" .. data.id .. "/profile",
hyperlink = "[" .. data.name .. "](<https://roblox.com/users/" .. data.id .. "/profile>)"
}
end
local function WeakUser(data)
return {
displayName = data.displayName,
name = data.name,
id = data.id,
avatar = data.avatar or "https://duckybot.xyz/images/icons/RobloxConfused.png",
verified = not not data.hasVerifiedBadge,
profile = "https://roblox.com/users/" .. data.id .. "/profile",
hyperlink = "[" .. data.name .. "](<https://roblox.com/users/" .. data.id .. "/profile>)"
}
end
local function GroupUser(data)
return {
name = data.username,
displayName = data.displayName,
id = data.userId,
verified = not not data.hasVerifiedBadge,
profile = "https://roblox.com/users/" .. data.userId .. "/profile",
hyperlink = "[" .. data.username .. "](<https://roblox.com/users/" .. data.userId .. "/profile>)"
}
end
local function Group(data)
return {
name = data.name,
id = data.id,
description = data.description,
owner = ropi.GetUser(data.owner.userId),
members = data.memberCount,
shout = data.shout,
verified = not not data.hasVerifiedBadge,
public = not not data.publicEntryAllowed,
link = "https://www.roblox.com/communities/" .. data.id,
hyperlink = "[" .. data.name .. "](<https://www.roblox.com/communities/" .. data.id .. ">)"
}
end
local function Transaction(data, loadUser)
return {
hash = data.idHash,
created = fromISO(data.created),
pending = data.isPending,
user = (loadUser and ropi.GetUser(data.agent.id)) or {
id = data.agent.id
},
item = {
name = data.details.name,
id = data.details.id,
type = data.details.type,
place = (data.details.place and {
name = data.details.place.name,
id = data.details.place.placeId,
game = data.details.place.universeId
}) or nil
},
price = math.floor((data.currency.amount / 0.7) + 0.5),
taxed = math.floor(data.currency.amount + 0.5),
token = data.purchaseToken
}
end
local function Error(code, message)
if _G.Client then
_G.Client:error("[ROPI] | " .. tostring(message))
end
return {
code = code,
message = message
}
end
-- request handler
function ropi:queue(request)
request.timestamp = os.time()
local co, main = coroutine.running()
if not co or main or not coroutine.isyieldable(co) then
return "ropi:queue must be called from inside a yieldable coroutine"
end
request.co = co
local b = request.api
ropi.Requests[b] = ropi.Requests[b] or {}
table.insert(ropi.Requests[b], request)
if request.origin then
ropi.RequestOrigins[request.origin] = (ropi.RequestOrigins[request.origin] and ropi.RequestOrigins[request.origin] + 1) or 0
end
return coroutine.yield()
end
function ropi:dump()
local now = realtime()
for bucket, list in pairs(ropi.Requests) do
ropi.Ratelimits[bucket] = ropi.Ratelimits[bucket] or {}
local bucketRatelimit = ropi.Ratelimits[bucket]
if not ropi.ActiveBuckets[bucket] and #list > 0 and (not bucketRatelimit.retryAt or now >= bucketRatelimit.retryAt) then
ropi.ActiveBuckets[bucket] = true
local timeoutTimer = uv.new_timer()
uv.timer_start(timeoutTimer, 10000, 0, function()
if ropi.ActiveBuckets[bucket] then
Error("Timeout: Forcing unlock of bucket " .. tostring(bucket))
ropi.ActiveBuckets[bucket] = nil
end
uv.close(timeoutTimer)
end)
coroutine.wrap(function()
local ok, err = pcall(function()
table.sort(list, function(a, b)
return a.timestamp < b.timestamp
end)
local req = list[1]
if not req then
return
end
local domainsToTry = {}
if req.domains == true or req.domains == nil then
domainsToTry = ropi.Domains
elseif type(req.domains) == "table" then
for _, domainName in ipairs(req.domains) do
for _, domainDef in ipairs(ropi.Domains) do
if domainDef.name == domainName then
table.insert(domainsToTry, domainDef)
break
end
end
end
end
if #domainsToTry == 0 then
domainsToTry = ropi.Domains
end
bucketRatelimit.lastDomainIndex = bucketRatelimit.lastDomainIndex or 0
local chosenDomain
local start_index = bucketRatelimit.lastDomainIndex % #domainsToTry + 1
for i = 1, #domainsToTry do
local index = (start_index + i - 2) % #domainsToTry + 1
local domain = domainsToTry[index]
local domainRatelimit = bucketRatelimit[domain.name]
if not domainRatelimit or not domainRatelimit.retry or now >= (domainRatelimit.updated + domainRatelimit.retry) then
chosenDomain = domain
bucketRatelimit.lastDomainIndex = index
break
end
end
if chosenDomain then
bucketRatelimit.retryAt = nil
local okReq, response, result = ropi:request(req.api, req.method, req.endpoint, req.headers, req.body, chosenDomain, req.expectedCode, req.version)
if not okReq and type(result) == "table" and result.code == 429 then
local retryAfter = 1
for _, header in pairs(result) do
if type(header) == "table" and type(header[1]) == "string" and header[1]:lower() == "retry-after" then
retryAfter = tonumber(header[2]) or 1
end
end
Error("The " .. (bucket or "unknown") .. " bucket on domain " .. chosenDomain.name .. " was ratelimited, requeueing for " .. retryAfter .. "s.")
bucketRatelimit[chosenDomain.name] = {
updated = realtime(),
retry = retryAfter
}
else
table.remove(list, 1)
if #list == 0 then
ropi.Requests[bucket] = nil
end
safeResume(req.co, okReq, response, result)
end
else
local soonestRetryAt
for _, domain in ipairs(domainsToTry) do
local domainRatelimit = bucketRatelimit[domain.name]
if domainRatelimit and domainRatelimit.retry then
local retryAt = domainRatelimit.updated + domainRatelimit.retry
if now < retryAt then
if not soonestRetryAt or retryAt < soonestRetryAt then
soonestRetryAt = retryAt
end
end
end
end
if soonestRetryAt then
bucketRatelimit.retryAt = soonestRetryAt
end
end
end)
ropi.ActiveBuckets[bucket] = nil
if not uv.is_closing(timeoutTimer) then
uv.close(timeoutTimer)
end
if not ok then
Error("Error during bucket dump:", err)
end
end)()
end
end
end
function ropi:request(api, method, endpoint, headers, body, domain, expectedCode, version)
local url = "https://" .. domain.parse(api) .. "/" .. (version or "v1") .. "/" .. endpoint
headers = type(headers) == "table" and headers or {}
if not hasHeader(headers, "Content-Type") then
table.insert(headers, {
"Content-Type",
"application/json"
})
end
body = (body and type(body) == "table" and json.encode(body)) or (type(body) == "string" and body) or nil
local success, result, response = pcall(http.request, method, url, headers, body, {
timeout = 5000
})
response = (response and type(response) == "string" and json.decode(response)) or nil
if not success then
return false, Error(500, "An unknown error occurred."), result
end
if result.code ~= 200 then
print("ROPI NON 200: " .. tostring(result.code) .. " : " .. tostring(method) .. " : " .. tostring(url) .. " : " .. tostring(expectedCode))
end
if result.code == 200 then
return true, response, result
elseif expectedCode and result.code == expectedCode then
return true, response, result
else
local err = (response and response.errors and response.errors[1] and Error(response.errors[1].code, response.errors[1].message)) or Error(result.code, result.reason)
return false, err, result
end
end
-- api functions
function ropi.SetCookie(token)
ropi.cookie = ".ROBLOSECURITY=" .. token
return true
end
function ropi.GetToken()
local success, response, result = ropi:queue({
api = "itemconfiguration",
method = "PATCH",
endpoint = "collectibles/xcsrftoken",
domains = {
"roblox"
},
expectedCode = 403,
headers = {
{
"Cookie",
ropi.cookie
}
}
})
if not success or not result or result.code ~= 403 then
return false, response
end
for _, header in pairs(result) do
if type(header) == "table" and type(header[1]) == "string" and header[1]:lower() == "x-csrf-token" then
return true, header[2]
end
end
return false, Error(500, "A token was not provided by the server.")
end
function ropi.GetAvatarHeadShots(ids, opts, refresh)
local debugInfo
for i = 1, 10 do
debugInfo = debug.getinfo(i, "Sl")
if (debugInfo) and (not debugInfo.short_src:lower():find("ropi")) and (debugInfo.what ~= "C") then
break
end
end
local origin = (debugInfo and (debugInfo.short_src .. ":" .. debugInfo.currentline)) or nil
if type(ids) ~= "table" then
return nil, Error(400, "An invalid ids table was provided to SearchUsers.")
end
for i, id in pairs(ids) do
if type(id) == "string" then
ids[i] = tonumber(id)
end
end
opts = opts or {}
local options = {
size = opts.size or 720,
format = opts.format or "Png",
isCircular = not not opts.isCircular
}
local avatars = {}
if not refresh then
for i = #ids, 1, -1 do
local id = ids[i]
local cachedUrl
for _, item in ipairs(ropi.cache.avatars) do
if item.id == id then
cachedUrl = item.url
break
end
end
if cachedUrl then
avatars[id] = cachedUrl
table.remove(ids, i)
end
end
end
local errorResponse
if next(ids) then
local success, response = ropi:queue({
api = "thumbnails",
method = "GET",
domains = true,
endpoint = "users/avatar-headshot?userIds=" .. table.concat(ids, ",") .. "&size=" .. options.size .. "x" .. options.size .. "&format=Png&isCircular=" .. tostring(options.isCircular),
origin = origin
})
if success and type(response) == "table" and type(response.data) == "table" and next(response.data) then
for _, avatarData in pairs(response.data) do
if type(avatarData) == "table" and avatarData.targetId and avatarData.state == "Completed" and avatarData.imageUrl then
intoCache({
id = avatarData.targetId,
url = avatarData.imageUrl
}, "avatars")
avatars[avatarData.targetId] = avatarData.imageUrl
end
end
else
errorResponse = response
end
end
if not next(avatars) and errorResponse then
return nil, errorResponse
else
return avatars
end
end
function ropi.GetAvatarHeadShot(id, opts, refresh)
if type(id) ~= "string" and type(id) ~= "number" then
return nil, Error(400, "An invalid ID was provided to GetAvatarHeadShot.")
end
local avatars, error = ropi.GetAvatarHeadShots({
id
}, opts, refresh)
if not error and type(avatars) == "table" and avatars[id] then
return avatars[id]
else
return nil, error or "Failed to get avatar headshot"
end
end
function ropi.GetUsers(ids, opts, refresh)
local debugInfo
for i = 1, 10 do
debugInfo = debug.getinfo(i, "Sl")
if (debugInfo) and (not debugInfo.short_src:lower():find("ropi")) and (debugInfo.what ~= "C") then
break
end
end
local origin = (debugInfo and (debugInfo.short_src .. ":" .. debugInfo.currentline)) or nil
if type(ids) ~= "table" then
return nil, Error(400, "An invalid ids table was provided to SearchUsers.")
end
for i, id in pairs(ids) do
if type(id) == "string" then
ids[i] = tonumber(id)
end
end
opts = opts or {}
local options = {
fullObject = opts.fullObject,
avatars = opts.avatars,
dictionary = opts.dictionary,
fillUnknown = opts.fillUnknown
}
local users = {}
if not refresh then
for i = #ids, 1, -1 do
local id = ids[i]
if type(id) == "string" then
local cached = fromCache(id, "users") or (not options.fullObject and fromCache(id, "weakUsers"))
if cached then
table.insert(users, cached)
table.remove(ids, i)
end
end
end
end
local errorResponse
if next(ids) then
local success, response = ropi:queue({
api = "users",
method = "POST",
domains = {
"roblox",
"RoProxy",
"ropiproxy",
"ropiproxytwo",
"ropiproxythree"
},
endpoint = "users",
body = {
userIds = ids,
excludeBannedUsers = true
},
origin = origin
})
if success and type(response) == "table" and type(response.data) == "table" and next(response.data) then
local avatars
if options.avatars and not options.fullObject then
local userIds = {}
for _, userData in pairs(response.data) do
if type(userData) == "table" and userData.id then
table.insert(userIds, userData.id)
end
end
if #userIds > 0 then
avatars = ropi.GetAvatarHeadShots(userIds, opts, refresh)
end
end
for _, userData in pairs(response.data) do
if type(userData) == "table" and userData.id then
if options.fullObject then
local user = ropi.GetUser(userData.id)
if type(user) == "table" then
if options.dictionary then
users[user.id] = user
else
table.insert(users, user)
end
end
else
if avatars and avatars[userData.id] then
userData.avatar = avatars[userData.id]
end
if options.dictionary then
users[userData.id] = intoCache(WeakUser(userData), "weakUsers")
else
table.insert(users, intoCache(WeakUser(userData), "weakUsers"))
end
end
end
end
else
errorResponse = response
end
end
if options.fillUnknown then
for _, id in pairs(ids) do
local found
for _, user in pairs(users) do
if user.id == id then
found = true
break
end
end
if not found then
local user = {
id = id,
displayName = "UnknownUser",
name = "UnknownUser",
avatar = "https://duckybot.xyz/images/icons/RobloxConfused.png",
profile = "https://roblox.com/users/" .. id .. "/profile",
verified = false,
hyperlink = "[UnknownUser](<https://roblox.com/users/" .. id .. "/profile>)"
}
if options.dictionary then
users[user.id] = user
else
table.insert(users, user)
end
end
end
end
if not next(users) and errorResponse then
return nil, errorResponse
else
return users
end
end
function ropi.GetUser(id, refresh)
local debugInfo
for i = 1, 10 do
debugInfo = debug.getinfo(i, "Sl")
if (debugInfo) and (not debugInfo.short_src:lower():find("ropi")) and (debugInfo.what ~= "C") then
break
end
end
local origin = (debugInfo and (debugInfo.short_src .. ":" .. debugInfo.currentline)) or nil
if type(id) ~= "string" and type(id) ~= "number" then
return nil, Error(400, "An invalid ID was provided to GetUser.")
end
if not refresh then
local cached = fromCache(id, "users")
if cached then
return cached
end
end
local success, user = ropi:queue({
api = "users",
method = "GET",
domains = true,
endpoint = "users/" .. id,
origin = origin
})
if success and user and user.name and user.displayName and user.id then
return intoCache(User(user), "users")
else
return nil, user
end
end
function ropi.SearchUsers(usernames, opts, refresh)
local debugInfo
for i = 1, 10 do
debugInfo = debug.getinfo(i, "Sl")
if (debugInfo) and (not debugInfo.short_src:lower():find("ropi")) and (debugInfo.what ~= "C") then
break
end
end
local origin = (debugInfo and (debugInfo.short_src .. ":" .. debugInfo.currentline)) or nil
if type(usernames) ~= "table" then
return nil, Error(400, "An invalid username table was provided to SearchUsers.")
end
opts = opts or {}
local options = {
fullObject = opts.fullObject,
avatars = opts.avatars,
dictionary = opts.dictionary
}
local users = {}
if not refresh then
for i = #usernames, 1, -1 do
local username = usernames[i]
if type(username) == "string" then
local cached = fromCache(username, "users") or (not options.fullObject and fromCache(username, "weakUsers"))
if cached then
table.insert(users, cached)
table.remove(usernames, i)
end
end
end
end
local errorResponse
if next(usernames) then
local success, response = ropi:queue({
api = "users",
method = "POST",
domains = {
"roblox",
"RoProxy",
"ropiproxy",
"ropiproxytwo",
"ropiproxythree"
},
endpoint = "usernames/users",
body = {
usernames = usernames,
excludeBannedUsers = true
},
origin = origin
})
if success and type(response) == "table" and type(response.data) == "table" and next(response.data) then
local avatars
if options.avatars and not options.fullObject then
local userIds = {}
for _, userData in pairs(response.data) do
if type(userData) == "table" and userData.id then
table.insert(userIds, userData.id)
end
end
if #userIds > 0 then
avatars = ropi.GetAvatarHeadShots(userIds, opts, refresh)
end
end
for _, userData in pairs(response.data) do
if type(userData) == "table" and userData.id then
if options.fullObject then
local user = ropi.GetUser(userData.id)
if type(user) == "table" then
if options.dictionary then
users[user.id] = user
else
table.insert(users, user)
end
end
else
if avatars and avatars[userData.id] then
userData.avatar = avatars[userData.id]
end
if options.dictionary then
users[userData.id] = intoCache(WeakUser(userData), "weakUsers")
else
table.insert(users, intoCache(WeakUser(userData), "weakUsers"))
end
end
end
end
else
errorResponse = response
end
end
if not next(users) and errorResponse then
return nil, errorResponse
else
return users
end
end
function ropi.SearchUser(name, refresh)
if type(name) ~= "string" and type(name) ~= "number" then
return nil, Error(400, "An invalid name/ID was provided to SearchUser.")
end
if tonumber(name) then
return ropi.GetUser(name, refresh)
end
local users = ropi.SearchUsers({
name
}, {
fullObject = true
}, refresh)
if type(users) == "table" and users[1] then
return users[1]
else
return nil, users
end
end
function ropi.GetGroup(id, refresh)
if type(id) ~= "string" and type(id) ~= "number" then
return nil, Error(400, "An invalid ID was provided to GetGroup.")
end
if not refresh then
local cached = fromCache(id, "groups")
if cached then
return cached
end
end
local success, group = ropi:queue({
api = "groups",
method = "GET",
proxy = true,
endpoint = "groups/" .. id
})
if success and group and group.name and group.id then
return intoCache(Group(group), "groups")
else
return nil, group
end
end
function ropi.GetGroupMembers(id, full)
local members = {}
local cursor = nil
repeat
local url = "groups/" .. id .. "/users?limit=100" .. ((cursor and "&cursor=" .. cursor) or "")
local success, response = ropi:queue({
api = "groups",
method = "GET",
proxy = true,
endpoint = url
})
if success and response then
for _, userdata in pairs(response.data or {}) do
table.insert(members, (full and ropi.GetUser(userdata.user.userId)) or GroupUser(userdata.user))
end
cursor = response.nextPageCursor
else
break
end
until not cursor
return true, members
end
function ropi.GetGroupTransactions(id, pages, loadUsers) -- pass true for pages to get all pages
if not ropi.cookie then
return nil, Error(400, ".ROBLOSECURITY cookie has not yet been set.")
end
local success, token = ropi.GetToken()
if not success then
return token
end
local transactions = {}
local cursor = nil
local pagesFetched = 0
repeat
local url = "groups/" .. id .. "/transactions?limit=100&transactionType=Sale" .. ((cursor and "&cursor=" .. cursor) or "")
local success, response, result = ropi:queue({
api = "economy",
method = "GET",
endpoint = url,
domains = {
"roblox"
},
headers = {
{
"Cookie",
ropi.cookie
},
{
"X-Csrf-Token",
token
}
},
version = "v2"
})
if success and response then
for _, transactionData in pairs(response.data or {}) do
table.insert(transactions, Transaction(transactionData, loadUsers))
end
cursor = response.nextPageCursor
pagesFetched = pagesFetched + 1
else
break
end
until not cursor or (not pages) or (type(pages) == "number" and pagesFetched >= pages)
table.sort(transactions, function(a, b)
if type(a.created) ~= "number" or type(b.created) ~= "number" then
return false
else
return a.created > b.created
end
end)
return transactions
end
function ropi.SetAssetPrice(collectibleID, price)
if not ropi.cookie then
return nil, Error(400, ".ROBLOSECURITY cookie has not yet been set.")
end
local success, token = ropi.GetToken()
if not success then
return token
end
if (not collectibleID) or type(collectibleID) ~= "string" then