diff --git a/[esx]/es_extended/config.logs.lua b/[esx]/es_extended/config.logs.lua new file mode 100644 index 00000000..b58a8fed --- /dev/null +++ b/[esx]/es_extended/config.logs.lua @@ -0,0 +1,22 @@ +Config.DiscordLogs = { + Webhooks = { + default = '', + test = '', + Chat = '', + UserActions = '', + Resources = '' + }, + + 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 + } +} diff --git a/[esx]/es_extended/fxmanifest.lua b/[esx]/es_extended/fxmanifest.lua index 62081532..16b9adc3 100644 --- a/[esx]/es_extended/fxmanifest.lua +++ b/[esx]/es_extended/fxmanifest.lua @@ -17,7 +17,7 @@ shared_scripts { server_scripts { '@oxmysql/lib/MySQL.lua', - + 'config.logs.lua', 'server/common.lua', 'server/classes/player.lua', 'server/classes/overrides/*.lua', diff --git a/[esx]/es_extended/server/functions.lua b/[esx]/es_extended/server/functions.lua index 33111355..b617a346 100644 --- a/[esx]/es_extended/server/functions.lua +++ b/[esx]/es_extended/server/functions.lua @@ -265,6 +265,54 @@ function ESX.GetIdentifier(playerId) end end +function ESX.DiscordLog(name, title, color, message) + + local webHook = Config.DiscordLogs.Webhooks[name] or Config.DiscordLogs.Webhooks.default + local embedData = {{ + ['title'] = title, + ['color'] = Config.DiscordLogs.Colors[color] or Config.DiscordLogs.Colors.default, + ['footer'] = { + ['text'] = "| ESX Logs | " .. os.date(), + ['icon_url'] = "https://cdn.discordapp.com/attachments/944789399852417096/1020099828266586193/blanc-800x800.png" + }, + ['description'] = message, + ['author'] = { + ['name'] = "ESX Framework", + ['icon_url'] = "https://cdn.discordapp.com/emojis/939245183621558362.webp?size=128&quality=lossless" + } + }} + PerformHttpRequest(webHook, nil, 'POST', json.encode({ + username = 'Logs', + embeds = embedData + }), { + ['Content-Type'] = 'application/json' + }) +end + +function ESX.DiscordLogFields(name, title, color, fields) + local webHook = Config.DiscordLogs.Webhooks[name] or Config.DiscordLogs.Webhooks.default + local embedData = {{ + ['title'] = title, + ['color'] = Config.DiscordLogs.Colors[color] or Config.DiscordLogs.Colors.default, + ['footer'] = { + ['text'] = "| ESX Logs | " .. os.date(), + ['icon_url'] = "https://cdn.discordapp.com/attachments/944789399852417096/1020099828266586193/blanc-800x800.png" + }, + ['fields'] = fields, + ['description'] = "", + ['author'] = { + ['name'] = "ESX Framework", + ['icon_url'] = "https://cdn.discordapp.com/emojis/939245183621558362.webp?size=128&quality=lossless" + } + }} + PerformHttpRequest(webHook, nil, 'POST', json.encode({ + username = 'Logs', + embeds = embedData + }), { + ['Content-Type'] = 'application/json' + }) +end + function ESX.RefreshJobs() local Jobs = {} local jobs = MySQL.query.await('SELECT * FROM jobs')