-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
61 lines (53 loc) · 1.83 KB
/
server.lua
File metadata and controls
61 lines (53 loc) · 1.83 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
-- ### Framework ###
if Config.Framework == "esx" then
if Config.ESXExport ~= "" then
ESX = exports[Config.ESXExport]:getSharedObject()
else
TriggerEvent(Config.Core, function(obj)
ESX = obj
end)
end
elseif Config.Framework == "qb" then
QBCore = exports[Config.Core]:GetCoreObject()
else
print("Unrecognized framework")
end
if Config.Framework == "esx" then
ESX.RegisterServerCallback("balla-1:requestData", function(source, cb)
getUserInfo(source, cb)
end)
else
QBCore.Functions.CreateCallback("balla-1:requestData", function(source, cb)
getUserInfo(source, cb)
end)
end
function getUserInfo(source, cb)
local player = source
local discordIdentifier = nil
for _, id in ipairs(GetPlayerIdentifiers(player)) do
if string.match(id, "discord:") then
discordIdentifier = string.gsub(id, "discord:", "")
break
end
end
if discordIdentifier then
local endpoint = "https://discord.com/api/v10/users/" .. discordIdentifier
local requestHeaders = {
["Authorization"] = "Bot " .. Config.BotToken
}
PerformHttpRequest(endpoint, function(errorCode, resultData, resultHeaders)
if errorCode == 200 then
local userInfo = json.decode(resultData)
local discordName = userInfo.username
local discordAvatar = "https://cdn.discordapp.com/avatars/" .. discordIdentifier .. "/" .. userInfo.avatar .. ".png?size=128"
cb(discordAvatar, discordName)
else
print(errorCode)
cb(nil, nil)
end
end, "GET", nil, requestHeaders)
else
print("Discord id == nil")
cb(nil, nil)
end
end