glitchdetector icon

FiveM vRP User 3rd Party Data

glitchdetector | PRO | 02/06/19 05:13:06 PM UTC | 0 ⭐ | 1123 👁️ | Never ⏰ | []
Lua |

4.5 KB

|

None

|

0 👍

/

0 👎

local FormattedToken = "Bot " .. config.discordBotToken
function vRP.DiscordRequest(method, endpoint, jsondata)
    local data = nil
    PerformHttpRequest("https://discordapp.com/api/"..endpoint, function(errorCode, resultData, resultHeaders)
        data = {data=resultData, code=errorCode, headers=resultHeaders}
    end, method, #jsondata > 0 and json.encode(jsondata) or "", {["Content-Type"] = "application/json", ["Authorization"] = FormattedToken})
 
    while data == nil do
        Citizen.Wait(0)
    end
 
    return data
end
 
function vRP.loadUserDiscordData(source, user_id, cbr)
    local callback = false
    local function cb(ret)
        if not callback then
            callback = true
            cbr(ret)
        end
    end
 
    local discordId = nil
    for _, id in ipairs(GetPlayerIdentifiers(source)) do
        if string.match(id, "discord:") then
            discordId = string.gsub(id, "discord:", "")
            break
        end
    end
 
    if discordId then
        local result = vRP.DiscordRequest("GET", "users/" .. discordId, {})
        local data = json.decode(result.data)
        if data then
            if data['avatar'] then
                vRP.user_tmp_tables[user_id].avatar_hash = data['avatar']
                if string.sub(data['avatar'], 1, 2) == "a_" then
                    vRP.user_tmp_tables[user_id].avatar = "https://cdn.discordapp.com/avatars/" .. discordId .. "/" .. data['avatar'] .. ".gif"
                else
                    vRP.user_tmp_tables[user_id].avatar = "https://cdn.discordapp.com/avatars/" .. discordId .. "/" .. data['avatar'] .. ".png"
                end
            end
            if data['id'] then
                vRP.user_tmp_tables[user_id].discord_id = data['id']
            end
            if data['username'] then
                vRP.user_tmp_tables[user_id].discord_username = data['username']
            end
            if data['discriminator'] then
                vRP.user_tmp_tables[user_id].discord_discriminator = data['discriminator']
            end
            if data['username'] and data['discriminator'] then
                vRP.user_tmp_tables[user_id].discord = data['username'] .. "#" .. data['discriminator']
            end
        end
        cb(true)
    else
        cb(false)
    end
    Wait(500)
    if not callback then
        cb(false)
    end
end
 
function vRP.initializeUserData(source, user_id, cbr)
    local callback = false
    local function cb(ret)
        if not callback then
            callback = true
            cbr(ret)
        end
    end
 
    vRP.user_tmp_tables[user_id].connected = os.time()
 
    cb(true)
end
 
-- Complicated spaghet that fetches the users Steam Avatar
local SAK = config.steamApiKey
function vRP.loadUserSteamData(source, user_id, cbr)
    local callback = false
    local function cb(ret)
        if not callback then
            callback = true
            cbr(ret)
        end
    end
    local function validResponse(text, statusCode)
        return (text ~= nil and statusCode ~= nil and tonumber(statusCode) == 200)
    end
    local steamid = GetPlayerIdentifier(source, 0)
    if not steamid then
        cb(true)
        return true
    end
    if not string.find(steamid, "steam:") then
        cb(true)
        return true
    end
    local steam64 = tonumber(string.gsub(steamid,"steam:", ""),16)
    if not steam64 then
        cb(true)
        return true
    end
    PerformHttpRequest('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='..SAK..'&steamids='..steam64..'', function(statusCode, text, headers)
        if text then
            if validResponse(text, statusCode) then
                local info = json.decode(text)
                if info['response']['players'][1]['avatarmedium'] then
                    vRP.user_tmp_tables[user_id].avatar = info['response']['players'][1]['avatarmedium']
                end
                if info['response']['players'][1]['steamid'] then
                    vRP.user_tmp_tables[user_id].steamid = info['response']['players'][1]['steamid']
                end
                if info['response']['players'][1]['profileurl'] then
                    vRP.user_tmp_tables[user_id].profileurl = info['response']['players'][1]['profileurl']
                end
            else
 
            end
        end
        cb(true)
    end, 'GET', json.encode({}), { ["Content-Type"] = 'application/json' })
    Wait(500)
    if not callback then
        cb(false)
    end
end
 
function vRP.getAvatar(user_id)
    if not vRP.user_tmp_tables[user_id] then return nil end
    return vRP.user_tmp_tables[user_id].avatar
end

Comments