Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions sv_ace_perms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 ""
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions sv_chat_tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)}
Expand Down
7 changes: 5 additions & 2 deletions sv_deferrals.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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
deferrals.done("You must have Discord open to join this server.")
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
Expand Down
7 changes: 4 additions & 3 deletions sv_discord_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion sv_utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ local gsub = string.gsub
local gmatch = string.gmatch
local insert = table.insert

local _GetPlayerIdentifiers = GetPlayerIdentifiers

cachedIdentifiers = {}

function Log(message)
Expand All @@ -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
Expand Down
Loading