diff --git a/fxmanifest.lua b/fxmanifest.lua index 0823ee2..70b218b 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ game "gta5" name "DiscordAPI" description "An all one in solution for Discord API, that controls chat tags, permissions." author "ricky" -version "v2.2.1" +version "v2.2.2" lua54 "yes" @@ -14,7 +14,11 @@ client_scripts { server_scripts { "sv_config.lua", - "**/sv_*.lua" + "sv_utility.lua", + "sv_discord_api.lua", + "sv_ace_perms.lua", + "sv_chat_tags.lua", + "sv_deferrals.lua" } server_exports { diff --git a/sv_ace_perms.lua b/sv_ace_perms.lua index 949d39d..5e992ee 100644 --- a/sv_ace_perms.lua +++ b/sv_ace_perms.lua @@ -3,8 +3,11 @@ if not Config.AcePermsEnabled then return end local pairs = pairs local tostring = tostring +local _GetIdentifiersTable = GetIdentifiersTable +local _getRoles = getRoles local _ExecuteCommand = ExecuteCommand local _GetPlayerName = GetPlayerName +local _Log = Log local groups = Config.Groups local permissions = Config.Permissions @@ -18,7 +21,7 @@ local permissionAdd = "add_ace identifier.%s \"%s\" allow" local permissionRemove = "remove_ace identifier.%s \"%s\" allow" local function applyPermissions(source) - local identifiers = GetIdentifiersTable(source) + local identifiers = _GetIdentifiersTable(source) local license, discord = identifiers.license, identifiers.discord for _, v in pairs(groupsToRemove) do @@ -31,7 +34,7 @@ local function applyPermissions(source) if not discord then return end - local roles = getRoles(source) + local roles = _getRoles(source) if roles == nil then return end local name = _GetPlayerName(source) or "" @@ -41,15 +44,15 @@ local function applyPermissions(source) local permissionInformation = permissions[tostring(v)] if not groupInformation then goto skipGroupInformation end - ExecuteCommand(groupAdd:format(license, groupInformation)) - Log("Granted \"" .. groupInformation.. "\" to " .. name .. " (" .. license .. ").") + _ExecuteCommand(groupAdd:format(license, groupInformation)) + _Log("Granted \"" .. groupInformation.. "\" to " .. name .. " (" .. license .. ").") ::skipGroupInformation:: if not permissionInformation then goto skipPermissionInformation end - Log("Granting permission set for role ID: " .. v .. ".") + _Log("Granting permission set for role ID: " .. v .. ".") for _, v2 in pairs(permissionInformation) do - ExecuteCommand(permissionAdd:format(license, v2)) - Log("Granted \"" .. v2.. "\" to " .. name .. " (" .. license .. ") due to them having the role ID: " .. v .. ".") + _ExecuteCommand(permissionAdd:format(license, v2)) + _Log("Granted \"" .. v2.. "\" to " .. name .. " (" .. license .. ") due to them having the role ID: " .. v .. ".") end ::skipPermissionInformation:: end diff --git a/sv_chat_tags.lua b/sv_chat_tags.lua index 982d9a9..117e059 100644 --- a/sv_chat_tags.lua +++ b/sv_chat_tags.lua @@ -6,6 +6,8 @@ local tonumber = tonumber local find = string.find local insert = table.insert +local _GetIdentifiersTable = GetIdentifiersTable +local _getRoles = getRoles local _IsPlayerAceAllowed = IsPlayerAceAllowed local _TriggerClientEvent = TriggerClientEvent @@ -17,14 +19,14 @@ local playerSelectedRole = {} local playerStaffChatStatus = {} local function syncTags(source) - local identifiers = GetIdentifiersTable(source) + local identifiers = _GetIdentifiersTable(source) local rolesAllowed = {} local highestRole, highestRoleIndex = nil, nil local roles = nil if identifiers.discord then - roles = getRoles(source) + roles = _getRoles(source) end for i = 1, #RoleList do @@ -48,7 +50,7 @@ local function syncTags(source) end local function sendMessage(source, message) - TriggerClientEvent("chat:addMessage", source, { + _TriggerClientEvent("chat:addMessage", source, { color = {255, 0, 0}, multiline = true, args = {"Server", tostring(message)} diff --git a/sv_deferrals.lua b/sv_deferrals.lua index abf71cd..992218d 100644 --- a/sv_deferrals.lua +++ b/sv_deferrals.lua @@ -1,12 +1,15 @@ if not Config.DiscordRequired then return end +local _GetIdentifiersTable = GetIdentifiersTable +local _isInGuild = isInGuild + local GuildRequired = Config.GuildRequired AddEventHandler("playerConnecting", function(_, _, deferrals) deferrals.defer() Wait(0) - local identifiers = GetIdentifiersTable(source) + local identifiers = _GetIdentifiersTable(source) local discord = identifiers.discord if not discord then @@ -14,7 +17,7 @@ AddEventHandler("playerConnecting", function(_, _, deferrals) return end - if GuildRequired and not isInGuild(source) then + if GuildRequired and not _isInGuild(source) then deferrals.done("You must be in the Discord server to join this server.") return end diff --git a/sv_discord_api.lua b/sv_discord_api.lua index efda5a3..b32dbfd 100644 --- a/sv_discord_api.lua +++ b/sv_discord_api.lua @@ -5,6 +5,7 @@ local tostring = tostring local encode = json.encode local decode = json.decode +local _GetIdentifiersTable = GetIdentifiersTable local _PerformHttpRequest = PerformHttpRequest local _Wait = Citizen.Wait @@ -34,7 +35,7 @@ local function DiscordRequest(endpoint, method, jsondata) end function isInGuild(user) - local identifiers = GetIdentifiersTable(user) + local identifiers = _GetIdentifiersTable(user) if not identifiers.discord then return false end local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord) @@ -44,7 +45,7 @@ function isInGuild(user) end function getRoles(user) - local identifiers = GetIdentifiersTable(user) + local identifiers = _GetIdentifiersTable(user) if not identifiers.discord then return {} end local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord) @@ -56,7 +57,7 @@ function getRoles(user) end function isRolePresent(user, role) - local identifiers = GetIdentifiersTable(user) + local identifiers = _GetIdentifiersTable(user) if not identifiers.discord then return false end local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord) diff --git a/sv_utility.lua b/sv_utility.lua index 707d2ee..2dcb322 100644 --- a/sv_utility.lua +++ b/sv_utility.lua @@ -7,6 +7,8 @@ local gsub = string.gsub local gmatch = string.gmatch local insert = table.insert +local _GetPlayerIdentifiers = GetPlayerIdentifiers + cachedIdentifiers = {} function Log(message) @@ -17,7 +19,7 @@ function GetIdentifiersTable(player) if cachedIdentifiers[player] then return cachedIdentifiers[player] end local data = {} - for _, v in pairs(GetPlayerIdentifiers(player))do + for _, v in pairs(_GetPlayerIdentifiers(player))do if sub(v, 1, len("license:")) == "license:" then data.license = v elseif sub(v, 1, len("discord:")) == "discord:" then