2 files changed
+90
-99
No files matched your search
+86
-98
@@ -1,115 +1,103 @@
|
|||||||
Logs = Logs or {}
|
Logs = Logs or {}
|
||||||
|
local BridgeServerConfig = BridgeServerConfig or Require('settings/serverConfig.lua')
|
||||||
local WebhookURL = "" -- Add webhook URL here if using built-in logging system
|
|
||||||
local LogoForEmbed = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024"
|
|
||||||
local LogSystem = "built-in" -- Default log system, can be "built-in", "qb", or "ox_lib"
|
|
||||||
|
|
||||||
|
|
||||||
---This will send a log to the configured webhook or log system.
|
local pendingLogs = {}
|
||||||
---@param src number
|
local sendTimer = nil
|
||||||
---@param message string
|
|
||||||
---@return nil
|
local function sendBufferedLogsToDiscord()
|
||||||
Logs.Send = function(src, message)
|
if #pendingLogs == 0 then
|
||||||
if not src or not message then return end
|
sendTimer = nil
|
||||||
local logType = LogSystem or "built-in"
|
return
|
||||||
if logType == "built-in" then
|
|
||||||
PerformHttpRequest(WebhookURL, function(err, text, headers) end, 'POST', json.encode(
|
|
||||||
{
|
|
||||||
username = "Community_Bridge's Logger",
|
|
||||||
avatar_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
|
|
||||||
embeds = {
|
|
||||||
{
|
|
||||||
color = "15769093",
|
|
||||||
title = GetCurrentResourceName(),
|
|
||||||
url = 'https://discord.gg/Gm6rYEXUsn',
|
|
||||||
thumbnail = { url = LogoForEmbed },
|
|
||||||
fields = {
|
|
||||||
{
|
|
||||||
name = '**Player ID**',
|
|
||||||
value = src,
|
|
||||||
inline = true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = '**Player Identifier**',
|
|
||||||
value = Framework.GetPlayerIdentifier(src),
|
|
||||||
inline = true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = 'Log Message',
|
|
||||||
value = "```"..message.."```",
|
|
||||||
inline = false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
timestamp = os.date('!%Y-%m-%dT%H:%M:%S'),
|
|
||||||
footer = {
|
|
||||||
text = "Community_Bridge | ",
|
|
||||||
icon_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}), { ['Content-Type']= 'application/json' })
|
|
||||||
elseif logType == "qb" then
|
|
||||||
return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message)
|
|
||||||
elseif logType == "ox_lib" then
|
|
||||||
return lib.logger(src, GetCurrentResourceName(), message)
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local embeds = {}
|
local embeds = {}
|
||||||
Logs.Notify = function(src, url, image, message)
|
for _, log in ipairs(pendingLogs) do
|
||||||
if not src or not message then return end
|
table.insert(embeds, {
|
||||||
local logType = LogSystem or "built-in"
|
color = '15769093',
|
||||||
if logType == "built-in" then
|
title = log.resource,
|
||||||
embeds[url] = embeds[url] or {}
|
thumbnail = { url = BridgeServerConfig.EmbedLogo },
|
||||||
local embed = embeds[url].embed or {}
|
|
||||||
local firstName, lastName = Framework.GetPlayerName(src)
|
|
||||||
|
|
||||||
table.insert(embed, {
|
|
||||||
color = "15769093",
|
|
||||||
title = GetInvokingResource(),
|
|
||||||
-- url = 'https://discord.gg/Gm6rYEXUsn',
|
|
||||||
thumbnail = { url = LogoForEmbed },
|
|
||||||
fields = {
|
fields = {
|
||||||
{
|
|
||||||
name = '**Player ID**',
|
|
||||||
value = src,
|
|
||||||
inline = true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name = '**Player Identifier**',
|
|
||||||
value = Framework.GetPlayerIdentifier(src),
|
|
||||||
inline = true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name = 'Log Message',
|
name = 'Log Message',
|
||||||
value = "```"..message.."```",
|
value = '```' .. log.message .. '```',
|
||||||
inline = false,
|
inline = false,
|
||||||
},
|
}
|
||||||
},
|
|
||||||
timestamp = os.date('!%Y-%m-%dT%H:%M:%S'),
|
|
||||||
footer = {
|
|
||||||
text = "Community_Bridge | ",
|
|
||||||
icon_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
|
|
||||||
},
|
},
|
||||||
|
timestamp = log.timestamp,
|
||||||
})
|
})
|
||||||
embeds[url].embed = embed
|
end
|
||||||
if embeds[url].inProgress then return end
|
|
||||||
embeds[url].inProgress = true
|
PerformHttpRequest(BridgeServerConfig.WebhookURL, function(err, text, headers) end, 'POST', json.encode({
|
||||||
SetTimeout(5000, function()
|
username = 'Community_Bridge Logger',
|
||||||
PerformHttpRequest(url, function(err, text, headers) end, 'POST', json.encode({
|
avatar_url = 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
|
||||||
username = string.format("%s %s", firstName, lastName),
|
embeds = embeds
|
||||||
avatar_url = image or 'https://avatars.githubusercontent.com/u/192999457?s=400&u=da632e8f64c85def390cfd1a73c3b664d6882b38&v=4',
|
}), { ['Content-Type'] = 'application/json' })
|
||||||
embeds = embeds[url].embed
|
|
||||||
}), { ['Content-Type']= 'application/json' })
|
pendingLogs = {}
|
||||||
embeds[url].inProgress = false
|
sendTimer = nil
|
||||||
end)
|
end
|
||||||
elseif logType == "qb" then
|
|
||||||
return TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetCurrentResourceName(), 'green', message)
|
local function queueLogForDiscord(message)
|
||||||
elseif logType == "ox_lib" then
|
table.insert(pendingLogs, {
|
||||||
return lib.logger(src, GetCurrentResourceName(), message)
|
message = tostring(message),
|
||||||
|
resource = GetInvokingResource() or GetCurrentResourceName(),
|
||||||
|
timestamp = os.date('!%Y-%m-%dT%H:%M:%S')
|
||||||
|
})
|
||||||
|
|
||||||
|
if not sendTimer then
|
||||||
|
sendTimer = true
|
||||||
|
SetTimeout(3000, sendBufferedLogsToDiscord)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local logHandlers = {
|
||||||
|
fivemerr = function(logData)
|
||||||
|
local fivemerrData = {
|
||||||
|
level = 'info',
|
||||||
|
message = tostring(logData),
|
||||||
|
resource = GetInvokingResource() or GetCurrentResourceName(),
|
||||||
|
|
||||||
|
}
|
||||||
|
PerformHttpRequest('https://api.fivemerr.com/v1/logs', function(code, text, headers)
|
||||||
|
if code ~= 200 then
|
||||||
|
print(('Failed to send log to Fivemerr API (HTTP %d): Please verify your API key is correct and the service is available.'):format(code))
|
||||||
|
end
|
||||||
|
end, 'POST', json.encode(fivemerrData), {
|
||||||
|
['Content-Type'] = 'application/json',
|
||||||
|
['Authorization'] = BridgeServerConfig.FivemerrApiKey
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
|
||||||
|
qb = function(message)
|
||||||
|
TriggerEvent('qb-log:server:CreateLog', GetCurrentResourceName(), GetInvokingResource(), 'green', message, false)
|
||||||
|
end,
|
||||||
|
|
||||||
|
ox_lib = function(message)
|
||||||
|
lib.logger(GetInvokingResource(), GetCurrentResourceName(), message)
|
||||||
|
end,
|
||||||
|
|
||||||
|
['built-in'] = function(message)
|
||||||
|
queueLogForDiscord(message)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
---@deprecated Use Logs.CreateLog instead (deprecated 9/1/25)
|
||||||
|
Logs.Send = function(src, message)
|
||||||
|
print('^1Deprecated^0 function Logs.Send called. Please use Logs.CreateLog instead.')
|
||||||
|
Logs.CreateLog(message)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@deprecated Use Logs.CreateLog instead (deprecated 9/1/25)
|
||||||
|
Logs.Notify = function(src, url, image, message)
|
||||||
|
print('^1Deprecated^0 function Logs.Notify called. Please use Logs.CreateLog instead.')
|
||||||
|
Logs.CreateLog(message)
|
||||||
|
end
|
||||||
|
|
||||||
|
Logs.CreateLog = function(logData)
|
||||||
|
local handler = logHandlers[BridgeServerConfig.LogSystem]
|
||||||
|
if handler then handler(logData) end
|
||||||
|
end
|
||||||
|
|
||||||
exports('Logs', Logs)
|
exports('Logs', Logs)
|
||||||
return Logs
|
return Logs
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
BridgeServerConfig = {}
|
BridgeServerConfig = {}
|
||||||
BridgeServerConfig.MaxInventorySlots = 50
|
BridgeServerConfig.MaxInventorySlots = 50
|
||||||
|
BridgeServerConfig.LogSystem = "built-in" -- can be "none", "built-in", "qb", "fivemerr" or "ox_lib"
|
||||||
|
BridgeServerConfig.WebhookURL = "" -- Add webhook URL here if using built-in logging system
|
||||||
|
BridgeServerConfig.FivemerrApiKey = "" -- Add Fivemerr API key here if using fiveMerr
|
||||||
|
BridgeServerConfig.EmbedLogo = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024"
|
||||||
return BridgeServerConfig
|
return BridgeServerConfig
|
||||||
Reference in new issue
Block a user