Merge pull request #24 from nik0-3d/main

fix(ND_Core) fixed departments not showing for players in discord
This commit is contained in:
Niko
2022-08-04 22:49:13 -04:00
committed by GitHub
5 changed files with 26 additions and 14 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,5 @@
ND_Blackjack/ ND_Blackjack/
ND_Blips/ ND_Blips/
ND_Laser/
ND_Inventory/ ND_Inventory/
ND_Laser/

View File

@@ -2,7 +2,7 @@
author "Andyyy#7666, N1K0#0001" author "Andyyy#7666, N1K0#0001"
description "ND Character Selection (DOJ Based)" description "ND Character Selection (DOJ Based)"
version "2.1.0" version "2.2.0"
fx_version "cerulean" fx_version "cerulean"
game "gta5" game "gta5"

View File

@@ -50,14 +50,16 @@ end)
RegisterNetEvent("ND_CharacterSelection:checkPerms") RegisterNetEvent("ND_CharacterSelection:checkPerms")
AddEventHandler("ND_CharacterSelection:checkPerms", function() AddEventHandler("ND_CharacterSelection:checkPerms", function()
local player = source local player = source
local discordUserId = string.gsub(NDCore.Functions.GetPlayerIdentifierFromType("discord", player), "discord:", "") local discordUserId = NDCore.Functions.GetPlayerIdentifierFromType("discord", player):gsub("discord:", "")
local allowedRoles = {} local allowedRoles = {}
local roles = NDCore.Functions.GetUserDiscordInfo(discordUserId).roles print("test")
local discordInfo = NDCore.Functions.GetUserDiscordInfo(discordUserId)
print(discordInfo)
-- Check if the players discord roles will grant them permission to the department. -- Check if the players discord roles will grant them permission to the department.
for dept, roleTable in pairs(config.departments) do for dept, roleTable in pairs(config.departments) do
for _, roleId in pairs(roleTable) do for _, roleId in pairs(roleTable) do
if roles[roleId] or roleId == 0 or roleId == "0" then print(roleId)
if roleId == 0 or roleId == "0" or (discordInfo and discordInfo.roles[roleId]) then
table.insert(allowedRoles, dept) table.insert(allowedRoles, dept)
end end
end end

View File

@@ -2,7 +2,7 @@
author "Andyyy#7666, N1K0#0001" author "Andyyy#7666, N1K0#0001"
description "ND Framework Core" description "ND Framework Core"
version "3.0.1" version "3.1.1"
fx_version "cerulean" fx_version "cerulean"
game "gta5" game "gta5"

View File

@@ -6,13 +6,21 @@ function NDCore.Functions.GetPlayers(players)
cb(NDCore.Players) cb(NDCore.Players)
end end
local discordErrors = {
[400] = "improper http request",
[401] = "Discord bot token might be missing or incorrect",
[404] = "user might not be in server.",
[429] = "Discord bot rate limited.",
}
-- Used to retrive the players discord server nickname, discord name and tag, and the roles. -- Used to retrive the players discord server nickname, discord name and tag, and the roles.
function NDCore.Functions.GetUserDiscordInfo(discordUserId) function NDCore.Functions.GetUserDiscordInfo(discordUserId)
local data local data
PerformHttpRequest("https://discordapp.com/api/guilds/" .. server_config.guildId .. "/members/" .. discordUserId, function(errorCode, resultData, resultHeaders) local request = PerformHttpRequest("https://discordapp.com/api/guilds/" .. server_config.guildId .. "/members/" .. discordUserId, function(errorCode, resultData, resultHeaders)
if errorCode ~= 200 then if errorCode ~= 200 then
print("Error: " .. errorCode .. ", discord token might be missing.") print("Error: " .. errorCode .. " " .. discordErrors[errorCode])
return return false
end end
local result = json.decode(resultData) local result = json.decode(resultData)
local roles = {} local roles = {}
@@ -24,11 +32,13 @@ function NDCore.Functions.GetUserDiscordInfo(discordUserId)
discordTag = tostring(result.user.username) .. "#" .. tostring(result.user.discriminator), discordTag = tostring(result.user.username) .. "#" .. tostring(result.user.discriminator),
roles = roles roles = roles
} }
return true
end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = "Bot " .. server_config.discordServerToken}) end, "GET", "", {["Content-Type"] = "application/json", ["Authorization"] = "Bot " .. server_config.discordServerToken})
while not data do if request then
Citizen.Wait(0) return data
else
return false
end end
return data
end end
-- Get player any identifier, available types: steam, license, xbl, ip, discord, live. -- Get player any identifier, available types: steam, license, xbl, ip, discord, live.