forked from qbcore-framework/qb-smallresources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.lua
148 lines (137 loc) · 5.13 KB
/
logs.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
local QBCore = exports['qb-core']:GetCoreObject()
local Webhooks = {
['default'] = '',
['testwebhook'] = '',
['playermoney'] = '',
['playerinventory'] = '',
['robbing'] = '',
['cuffing'] = '',
['drop'] = '',
['trunk'] = '',
['stash'] = '',
['glovebox'] = '',
['banking'] = '',
['vehicleshop'] = '',
['vehicleupgrades'] = '',
['shops'] = '',
['dealers'] = '',
['storerobbery'] = '',
['bankrobbery'] = '',
['powerplants'] = '',
['death'] = '',
['joinleave'] = '',
['ooc'] = '',
['report'] = '',
['me'] = '',
['pmelding'] = '',
['112'] = '',
['bans'] = '',
['anticheat'] = '',
['weather'] = '',
['moneysafes'] = '',
['bennys'] = '',
['bossmenu'] = '',
['robbery'] = '',
['casino'] = '',
['traphouse'] = '',
['911'] = '',
['palert'] = '',
['house'] = '',
['qbjobs'] = '',
}
local colors = { -- https://www.spycolor.com/
['default'] = 14423100,
['blue'] = 255,
['red'] = 16711680,
['green'] = 65280,
['white'] = 16777215,
['black'] = 0,
['orange'] = 16744192,
['yellow'] = 16776960,
['pink'] = 16761035,
['lightgreen'] = 65309,
}
local logQueue = {}
RegisterNetEvent('qb-log:server:CreateLog', function(name, title, color, message, tagEveryone, imageUrl)
local tag = tagEveryone or false
if Config.Logging == 'discord' then
if not Webhooks[name] then
print('Tried to call a log that isn\'t configured with the name of ' .. name)
return
end
local webHook = Webhooks[name] ~= '' and Webhooks[name] or Webhooks['default']
local embedData = {
{
['title'] = title,
['color'] = colors[color] or colors['default'],
['footer'] = {
['text'] = os.date('%c'),
},
['description'] = message,
['author'] = {
['name'] = 'QBCore Logs',
['icon_url'] = 'https://raw.githubusercontent.com/GhzGarage/qb-media-kit/main/Display%20Pictures/Logo%20-%20Display%20Picture%20-%20Stylized%20-%20Red.png',
},
['image'] = imageUrl and imageUrl ~= '' and { ['url'] = imageUrl } or nil,
}
}
if not logQueue[name] then logQueue[name] = {} end
logQueue[name][#logQueue[name] + 1] = { webhook = webHook, data = embedData }
if #logQueue[name] >= 10 then
local postData = { username = 'QB Logs', embeds = {} }
if tag then
postData.content = '@everyone'
end
for i = 1, #logQueue[name] do postData.embeds[#postData.embeds + 1] = logQueue[name][i].data[1] end
PerformHttpRequest(logQueue[name][1].webhook, function() end, 'POST', json.encode(postData), { ['Content-Type'] = 'application/json' })
logQueue[name] = {}
end
elseif Config.Logging == 'fivemanage' then
local FiveManageAPIKey = GetConvar('FIVEMANAGE_LOGS_API_KEY', 'false')
if FiveManageAPIKey == 'false' then
print('You need to set the FiveManage API key in your server.cfg')
return
end
local extraData = {
level = tagEveryone and 'warn' or 'info', -- info, warn, error or debug
message = title, -- any string
metadata = { -- a table or object with any properties you want
description = message,
playerId = source,
playerLicense = GetPlayerIdentifierByType(source, 'license'),
playerDiscord = GetPlayerIdentifierByType(source, 'discord')
},
resource = GetInvokingResource(),
}
PerformHttpRequest('https://api.fivemanage.com/api/logs', function(statusCode, response, headers)
-- Uncomment the following line to enable debugging
-- print(statusCode, response, json.encode(headers))
end, 'POST', json.encode(extraData), {
['Authorization'] = FiveManageAPIKey,
['Content-Type'] = 'application/json',
})
end
end)
Citizen.CreateThread(function()
local timer = 0
while true do
Wait(1000)
timer = timer + 1
if timer >= 60 then -- If 60 seconds have passed, post the logs
timer = 0
for name, queue in pairs(logQueue) do
if #queue > 0 then
local postData = { username = 'QB Logs', embeds = {} }
for i = 1, #queue do
postData.embeds[#postData.embeds + 1] = queue[i].data[1]
end
PerformHttpRequest(queue[1].webhook, function() end, 'POST', json.encode(postData), { ['Content-Type'] = 'application/json' })
logQueue[name] = {}
end
end
end
end
end)
QBCore.Commands.Add('testwebhook', 'Test Your Discord Webhook For Logs (God Only)', {}, false, function()
TriggerEvent('qb-log:server:CreateLog', 'testwebhook', 'Test Webhook', 'default', 'Webhook setup successfully')
end, 'god')