Skip to content

Commit 5106fed

Browse files
authored
Merge dd079b6 into 46e9f74
2 parents 46e9f74 + dd079b6 commit 5106fed

6 files changed

Lines changed: 33 additions & 18 deletions

File tree

fxmanifest.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ game "gta5"
44
name "DiscordAPI"
55
description "An all one in solution for Discord API, that controls chat tags, permissions."
66
author "ricky"
7-
version "v2.2.1"
7+
version "v2.2.2"
88

99
lua54 "yes"
1010

@@ -14,7 +14,11 @@ client_scripts {
1414

1515
server_scripts {
1616
"sv_config.lua",
17-
"**/sv_*.lua"
17+
"sv_utility.lua",
18+
"sv_discord_api.lua",
19+
"sv_ace_perms.lua",
20+
"sv_chat_tags.lua",
21+
"sv_deferrals.lua"
1822
}
1923

2024
server_exports {

sv_ace_perms.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ if not Config.AcePermsEnabled then return end
33
local pairs = pairs
44
local tostring = tostring
55

6+
local _GetIdentifiersTable = GetIdentifiersTable
7+
local _getRoles = getRoles
68
local _ExecuteCommand = ExecuteCommand
79
local _GetPlayerName = GetPlayerName
10+
local _Log = Log
811

912
local groups = Config.Groups
1013
local permissions = Config.Permissions
@@ -18,7 +21,7 @@ local permissionAdd = "add_ace identifier.%s \"%s\" allow"
1821
local permissionRemove = "remove_ace identifier.%s \"%s\" allow"
1922

2023
local function applyPermissions(source)
21-
local identifiers = GetIdentifiersTable(source)
24+
local identifiers = _GetIdentifiersTable(source)
2225
local license, discord = identifiers.license, identifiers.discord
2326

2427
for _, v in pairs(groupsToRemove) do
@@ -31,7 +34,7 @@ local function applyPermissions(source)
3134

3235
if not discord then return end
3336

34-
local roles = getRoles(source)
37+
local roles = _getRoles(source)
3538
if roles == nil then return end
3639

3740
local name = _GetPlayerName(source) or ""
@@ -41,15 +44,15 @@ local function applyPermissions(source)
4144
local permissionInformation = permissions[tostring(v)]
4245

4346
if not groupInformation then goto skipGroupInformation end
44-
ExecuteCommand(groupAdd:format(license, groupInformation))
45-
Log("Granted \"" .. groupInformation.. "\" to " .. name .. " (" .. license .. ").")
47+
_ExecuteCommand(groupAdd:format(license, groupInformation))
48+
_Log("Granted \"" .. groupInformation.. "\" to " .. name .. " (" .. license .. ").")
4649
::skipGroupInformation::
4750

4851
if not permissionInformation then goto skipPermissionInformation end
49-
Log("Granting permission set for role ID: " .. v .. ".")
52+
_Log("Granting permission set for role ID: " .. v .. ".")
5053
for _, v2 in pairs(permissionInformation) do
51-
ExecuteCommand(permissionAdd:format(license, v2))
52-
Log("Granted \"" .. v2.. "\" to " .. name .. " (" .. license .. ") due to them having the role ID: " .. v .. ".")
54+
_ExecuteCommand(permissionAdd:format(license, v2))
55+
_Log("Granted \"" .. v2.. "\" to " .. name .. " (" .. license .. ") due to them having the role ID: " .. v .. ".")
5356
end
5457
::skipPermissionInformation::
5558
end

sv_chat_tags.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local tonumber = tonumber
66
local find = string.find
77
local insert = table.insert
88

9+
local _GetIdentifiersTable = GetIdentifiersTable
10+
local _getRoles = getRoles
911
local _IsPlayerAceAllowed = IsPlayerAceAllowed
1012
local _TriggerClientEvent = TriggerClientEvent
1113

@@ -17,14 +19,14 @@ local playerSelectedRole = {}
1719
local playerStaffChatStatus = {}
1820

1921
local function syncTags(source)
20-
local identifiers = GetIdentifiersTable(source)
22+
local identifiers = _GetIdentifiersTable(source)
2123

2224
local rolesAllowed = {}
2325
local highestRole, highestRoleIndex = nil, nil
2426
local roles = nil
2527

2628
if identifiers.discord then
27-
roles = getRoles(source)
29+
roles = _getRoles(source)
2830
end
2931

3032
for i = 1, #RoleList do
@@ -48,7 +50,7 @@ local function syncTags(source)
4850
end
4951

5052
local function sendMessage(source, message)
51-
TriggerClientEvent("chat:addMessage", source, {
53+
_TriggerClientEvent("chat:addMessage", source, {
5254
color = {255, 0, 0},
5355
multiline = true,
5456
args = {"Server", tostring(message)}

sv_deferrals.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
if not Config.DiscordRequired then return end
22

3+
local _GetIdentifiersTable = GetIdentifiersTable
4+
local _isInGuild = isInGuild
5+
36
local GuildRequired = Config.GuildRequired
47

58
AddEventHandler("playerConnecting", function(_, _, deferrals)
69
deferrals.defer()
710
Wait(0)
811

9-
local identifiers = GetIdentifiersTable(source)
12+
local identifiers = _GetIdentifiersTable(source)
1013
local discord = identifiers.discord
1114

1215
if not discord then
1316
deferrals.done("You must have Discord open to join this server.")
1417
return
1518
end
1619

17-
if GuildRequired and not isInGuild(source) then
20+
if GuildRequired and not _isInGuild(source) then
1821
deferrals.done("You must be in the Discord server to join this server.")
1922
return
2023
end

sv_discord_api.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local tostring = tostring
55
local encode = json.encode
66
local decode = json.decode
77

8+
local _GetIdentifiersTable = GetIdentifiersTable
89
local _PerformHttpRequest = PerformHttpRequest
910
local _Wait = Citizen.Wait
1011

@@ -34,7 +35,7 @@ local function DiscordRequest(endpoint, method, jsondata)
3435
end
3536

3637
function isInGuild(user)
37-
local identifiers = GetIdentifiersTable(user)
38+
local identifiers = _GetIdentifiersTable(user)
3839
if not identifiers.discord then return false end
3940

4041
local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord)
@@ -44,7 +45,7 @@ function isInGuild(user)
4445
end
4546

4647
function getRoles(user)
47-
local identifiers = GetIdentifiersTable(user)
48+
local identifiers = _GetIdentifiersTable(user)
4849
if not identifiers.discord then return {} end
4950

5051
local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord)
@@ -56,7 +57,7 @@ function getRoles(user)
5657
end
5758

5859
function isRolePresent(user, role)
59-
local identifiers = GetIdentifiersTable(user)
60+
local identifiers = _GetIdentifiersTable(user)
6061
if not identifiers.discord then return false end
6162

6263
local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord)

sv_utility.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ local gsub = string.gsub
77
local gmatch = string.gmatch
88
local insert = table.insert
99

10+
local _GetPlayerIdentifiers = GetPlayerIdentifiers
11+
1012
cachedIdentifiers = {}
1113

1214
function Log(message)
@@ -17,7 +19,7 @@ function GetIdentifiersTable(player)
1719
if cachedIdentifiers[player] then return cachedIdentifiers[player] end
1820
local data = {}
1921

20-
for _, v in pairs(GetPlayerIdentifiers(player))do
22+
for _, v in pairs(_GetPlayerIdentifiers(player))do
2123
if sub(v, 1, len("license:")) == "license:" then
2224
data.license = v
2325
elseif sub(v, 1, len("discord:")) == "discord:" then

0 commit comments

Comments
 (0)