|
| 1 | +--[[——————————————————————————————————————————————-- |
| 2 | + Developer: [INC]Be1zebub |
| 3 | +
|
| 4 | + Website: incredible-gmod.ru/owner |
| 5 | + EMail: beelzebub@incredible-gmod.ru |
| 6 | + Discord: discord.incredible-gmod.ru |
| 7 | +--——————————————————————————————————————————————]]-- |
| 8 | + |
| 9 | +local isstr, pairs = isstring, pairs |
| 10 | + |
| 11 | +local APIModule = {} |
| 12 | +APIModule.Name = "SteamIsInGroup" |
| 13 | +APIModule.ApiURL = "https://api.steampowered.com/ISteamUser/GetUserGroupList/v1/?key=%s&steamid=%s" |
| 14 | +function APIModule:Call(target, steamapi_key, group_id, callback) |
| 15 | + target = self:RequestSteamID64(target) |
| 16 | + if not isstr(target) then return end |
| 17 | + |
| 18 | + local cache_uid = target.."_"..group_id |
| 19 | + local cache = self:GetCache(cache_uid) |
| 20 | + if cache and callback then |
| 21 | + callback(cache) |
| 22 | + return |
| 23 | + end |
| 24 | + |
| 25 | + self:FetchURL(self.ApiURL:format(steamapi_key, target), function(body) |
| 26 | + if not body or body == "" then return end |
| 27 | + local tbl = self:HandleJson(body, "response", "groups") |
| 28 | + if not tbl then return end |
| 29 | + |
| 30 | + local result |
| 31 | + for k, v in pairs(tbl) do |
| 32 | + if v.gid == group_id then |
| 33 | + result = true |
| 34 | + break |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + self:DoCache(cache_uid, result) |
| 39 | + if callback then |
| 40 | + callback(result) |
| 41 | + end |
| 42 | + end) |
| 43 | +end |
| 44 | + |
| 45 | +return APIModule |
0 commit comments