mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 06:16:02 +01:00
update: discord function to core object func
This commit is contained in:
@@ -50,6 +50,38 @@ function NDCore.loadSQL(fileLocation, resource)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function NDCore.getDiscordInfo(discordUserId)
|
||||||
|
local done = false
|
||||||
|
local data
|
||||||
|
local discordErrors = {
|
||||||
|
[400] = "Improper HTTP request",
|
||||||
|
[401] = "Discord bot token might be missing or incorrect",
|
||||||
|
[404] = "User might not be in the server",
|
||||||
|
[429] = "Discord bot rate limited"
|
||||||
|
}
|
||||||
|
|
||||||
|
if not discordUserId then return end
|
||||||
|
if type(discordUserId) == "string" and discordUserId:find("discord:") then discordUserId:gsub("discord:", "") end
|
||||||
|
|
||||||
|
PerformHttpRequest(("https://discordapp.com/api/guilds/%s/members/%s"):format(Config.discordGuildId, discordUserId), function(errorCode, resultData, resultHeaders)
|
||||||
|
if errorCode ~= 200 then
|
||||||
|
done = true
|
||||||
|
return print(("^3Warning: %d %s"):format(errorCode, discordErrors[errorCode]))
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = json.decode(resultData)
|
||||||
|
data = {
|
||||||
|
nickname = result.nick or result.user.username,
|
||||||
|
user = result.user,
|
||||||
|
roles = result.roles
|
||||||
|
}
|
||||||
|
done = true
|
||||||
|
end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = ("Bot %s"):format(Config.discordBotToken)})
|
||||||
|
|
||||||
|
while not done do Wait(50) end
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
for name, func in pairs(NDCore) do
|
for name, func in pairs(NDCore) do
|
||||||
if type(func) == "function" then
|
if type(func) == "function" then
|
||||||
exports(name, func)
|
exports(name, func)
|
||||||
|
|||||||
@@ -3,12 +3,6 @@ NDCore.players = {}
|
|||||||
PlayersInfo = {}
|
PlayersInfo = {}
|
||||||
local resourceName = GetCurrentResourceName()
|
local resourceName = GetCurrentResourceName()
|
||||||
local tempPlayersInfo = {}
|
local tempPlayersInfo = {}
|
||||||
local discordErrors = {
|
|
||||||
[400] = "Improper HTTP request",
|
|
||||||
[401] = "Discord bot token might be missing or incorrect",
|
|
||||||
[404] = "User might not be in the server",
|
|
||||||
[429] = "Discord bot rate limited"
|
|
||||||
}
|
|
||||||
|
|
||||||
Config = {
|
Config = {
|
||||||
serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"),
|
serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"),
|
||||||
@@ -45,29 +39,6 @@ local function getIdentifierList(src)
|
|||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getDiscordInfo(discordUserId)
|
|
||||||
local done = false
|
|
||||||
local data
|
|
||||||
|
|
||||||
PerformHttpRequest(("https://discordapp.com/api/guilds/%s/members/%s"):format(Config.discordGuildId, discordUserId), function(errorCode, resultData, resultHeaders)
|
|
||||||
if errorCode ~= 200 then
|
|
||||||
done = true
|
|
||||||
return print(("^3Warning: %d %s"):format(errorCode, discordErrors[errorCode]))
|
|
||||||
end
|
|
||||||
|
|
||||||
local result = json.decode(resultData)
|
|
||||||
data = {
|
|
||||||
nickname = result.nick or result.user.username,
|
|
||||||
user = result.user,
|
|
||||||
roles = result.roles
|
|
||||||
}
|
|
||||||
done = true
|
|
||||||
end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = ("Bot %s"):format(Config.discordBotToken)})
|
|
||||||
|
|
||||||
while not done do Wait(500) end
|
|
||||||
return data
|
|
||||||
end
|
|
||||||
|
|
||||||
AddEventHandler("playerJoining", function(oldId)
|
AddEventHandler("playerJoining", function(oldId)
|
||||||
local src = source
|
local src = source
|
||||||
PlayersInfo[src] = tempPlayersInfo[oldId]
|
PlayersInfo[src] = tempPlayersInfo[oldId]
|
||||||
|
|||||||
Reference in New Issue
Block a user