11local QBCore = exports [' qb-core' ]:GetCoreObject ()
2+
23local Webhooks = {
34 [' default' ] = ' ' ,
45 [' testwebhook' ] = ' ' ,
@@ -58,35 +59,65 @@ local logQueue = {}
5859RegisterNetEvent (' qb-log:server:CreateLog' , function (name , title , color , message , tagEveryone )
5960 local postData = {}
6061 local tag = tagEveryone or false
61- if not Webhooks [name ] then print (' Tried to call a log that isn\' t configured with the name of ' .. name ) return end
62- local webHook = Webhooks [name ] ~= ' ' and Webhooks [name ] or Webhooks [' default' ]
63- local embedData = {
64- {
65- [' title' ] = title ,
66- [' color' ] = colors [color ] or colors [' default' ],
67- [' footer' ] = {
68- [' text' ] = os.date (' %c' ),
69- },
70- [' description' ] = message ,
71- [' author' ] = {
72- [' name' ] = ' QBCore Logs' ,
73- [' icon_url' ] = ' https://raw.githubusercontent.com/GhzGarage/qb-media-kit/main/Display%20Pictures/Logo%20-%20Display%20Picture%20-%20Stylized%20-%20Red.png' ,
74- },
62+
63+ if Config .Logging == ' discord' then
64+ if not Webhooks [name ] then
65+ print (' Tried to call a log that isn\' t configured with the name of ' .. name )
66+ return
67+ end
68+ local webHook = Webhooks [name ] ~= ' ' and Webhooks [name ] or Webhooks [' default' ]
69+ local embedData = {
70+ {
71+ [' title' ] = title ,
72+ [' color' ] = colors [color ] or colors [' default' ],
73+ [' footer' ] = {
74+ [' text' ] = os.date (' %c' ),
75+ },
76+ [' description' ] = message ,
77+ [' author' ] = {
78+ [' name' ] = ' QBCore Logs' ,
79+ [' icon_url' ] = ' https://raw.githubusercontent.com/GhzGarage/qb-media-kit/main/Display%20Pictures/Logo%20-%20Display%20Picture%20-%20Stylized%20-%20Red.png' ,
80+ },
81+ }
7582 }
76- }
7783
78- if not logQueue [name ] then logQueue [name ] = {} end
79- logQueue [name ][# logQueue [name ] + 1 ] = {webhook = webHook , data = embedData }
84+ if not logQueue [name ] then logQueue [name ] = {} end
85+ logQueue [name ][# logQueue [name ] + 1 ] = { webhook = webHook , data = embedData }
8086
81- if # logQueue [name ] >= 10 then
82- if tag then
83- postData = {username = ' QB Logs' , content = ' @everyone' , embeds = {}}
84- else
85- postData = {username = ' QB Logs' , embeds = {}}
87+ if # logQueue [name ] >= 10 then
88+ if tag then
89+ postData = { username = ' QB Logs' , content = ' @everyone' , embeds = {} }
90+ else
91+ postData = { username = ' QB Logs' , embeds = {} }
92+ end
93+ for i = 1 , # logQueue [name ] do postData .embeds [# postData .embeds + 1 ] = logQueue [name ][i ].data [1 ] end
94+ PerformHttpRequest (logQueue [name ][1 ].webhook , function () end , ' POST' , json .encode (postData ), { [' Content-Type' ] = ' application/json' })
95+ logQueue [name ] = {}
96+ end
97+ elseif Config .Logging == ' fivemanage' then
98+ local FiveManageAPIKey = GetConvar (' FIVEMANAGE_LOGS_API_KEY' , ' false' )
99+ if FiveManageAPIKey == ' false' then
100+ print (' You need to set the FiveManage API key in your server.cfg' )
101+ return
86102 end
87- for i = 1 , # logQueue [name ] do postData .embeds [# postData .embeds + 1 ] = logQueue [name ][i ].data [1 ] end
88- PerformHttpRequest (logQueue [name ][1 ].webhook , function () end , ' POST' , json .encode (postData ), { [' Content-Type' ] = ' application/json' })
89- logQueue [name ] = {}
103+ local extraData = {
104+ level = tagEveryone and ' warn' or ' info' , -- info, warn, error or debug
105+ message = title , -- any string
106+ metadata = { -- a table or object with any properties you want
107+ description = message ,
108+ playerId = source ,
109+ playerLicense = GetPlayerIdentifierByType (source , ' license' ),
110+ playerDiscord = GetPlayerIdentifierByType (source , ' discord' )
111+ },
112+ resource = GetInvokingResource (),
113+ }
114+ PerformHttpRequest (' https://api.fivemanage.com/api/logs' , function (statusCode , response , headers )
115+ -- Uncomment the following line to enable debugging
116+ -- print(statusCode, response, json.encode(headers))
117+ end , ' POST' , json .encode (extraData ), {
118+ [' Authorization' ] = FiveManageAPIKey ,
119+ [' Content-Type' ] = ' application/json' ,
120+ })
90121 end
91122end )
92123
@@ -99,11 +130,11 @@ Citizen.CreateThread(function()
99130 timer = 0
100131 for name , queue in pairs (logQueue ) do
101132 if # queue > 0 then
102- local postData = {username = ' QB Logs' , embeds = {}}
133+ local postData = { username = ' QB Logs' , embeds = {} }
103134 for i = 1 , # queue do
104135 postData .embeds [# postData .embeds + 1 ] = queue [i ].data [1 ]
105136 end
106- PerformHttpRequest (queue [1 ].webhook , function () end , ' POST' , json .encode (postData ), {[' Content-Type' ] = ' application/json' })
137+ PerformHttpRequest (queue [1 ].webhook , function () end , ' POST' , json .encode (postData ), { [' Content-Type' ] = ' application/json' })
107138 logQueue [name ] = {}
108139 end
109140 end
113144
114145QBCore .Commands .Add (' testwebhook' , ' Test Your Discord Webhook For Logs (God Only)' , {}, false , function ()
115146 TriggerEvent (' qb-log:server:CreateLog' , ' testwebhook' , ' Test Webhook' , ' default' , ' Webhook setup successfully' )
116- end , ' god' )
147+ end , ' god' )
0 commit comments