From fd0662b5918a409e73642652bd4c9b055f2b9d68 Mon Sep 17 00:00:00 2001 From: MonkeyWhisper <82112471+MonkeyWhisper@users.noreply.github.com> Date: Mon, 8 Jul 2024 00:53:51 -0400 Subject: [PATCH] Added support for Fivemerr Image Integration --- client/cl_mugshot.lua | 32 +++++++++++++++++++-------- server/main.lua | 50 ++++++++++++++++++++++++++++++++----------- shared/config.lua | 8 +++++++ 3 files changed, 69 insertions(+), 21 deletions(-) diff --git a/client/cl_mugshot.lua b/client/cl_mugshot.lua index 8217bc2e..69fe41a9 100644 --- a/client/cl_mugshot.lua +++ b/client/cl_mugshot.lua @@ -17,11 +17,24 @@ local MugShots = {} -- Mugshot functions local function TakeMugShot() - QBCore.Functions.TriggerCallback('ps-mdt:server:MugShotWebhook', function(MugShotWebhook) - exports['screenshot-basic']:requestScreenshotUpload(MugShotWebhook, 'files[]', {encoding = 'jpg'}, function(data) - local resp = json.decode(data) - table.insert(MugshotArray, resp.attachments[1].url) - end) + QBCore.Functions.TriggerCallback('ps-mdt:server:MugShotWebhook', function(webhookUrl, apiKey) + if Config.MugShotWebhook then + exports['screenshot-basic']:requestScreenshotUpload(webhookUrl, 'files[]', {encoding = 'jpg'}, function(data) + local resp = json.decode(data) + table.insert(MugshotArray, resp.attachments[1].url) + end) + elseif Config.FivemerrMugShot then + exports['screenshot-basic']:requestScreenshotUpload('https://api.fivemerr.com/v1/media/images', 'file', { + headers = { + Authorization = apiKey + }, + encoding = 'png' + }, function(data) + local resp = json.decode(data) + local link = (resp and resp.url) or 'invalid_url' + print(link) + end) + end end) end @@ -190,8 +203,9 @@ RegisterNetEvent('cqc-mugshot:client:trigger', function() end) RegisterNUICallback("sendToJail", function(data, cb) - QBCore.Functions.TriggerCallback('ps-mdt:server:MugShotWebhook', function(MugShotWebhook) - if MugShotWebhook ~= '' then + QBCore.Functions.TriggerCallback('ps-mdt:server:MugShotWebhook', function(webhookUrl, apiKey) + local webhookUrl = Config.MugShotWebhook and webhookUrl or 'https://api.fivemerr.com/v1/media/images' + if webhookUrl ~= '' then local citizenId, sentence = data.citizenId, data.sentence -- Gets the player id from the citizenId @@ -203,7 +217,7 @@ RegisterNUICallback("sendToJail", function(data, cb) local targetSourceId = Citizen.Await(p) if sentence > 0 then - if Config.UseCQCMugshot then + if Config.UseCQCMugshot then TriggerServerEvent('cqc-mugshot:server:triggerSuspect', targetSourceId) end Citizen.Wait(5000) @@ -212,4 +226,4 @@ RegisterNUICallback("sendToJail", function(data, cb) end end end) -end) +end) \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 1f9ae310..44029235 100644 --- a/server/main.lua +++ b/server/main.lua @@ -11,6 +11,15 @@ local antiSpam = false local calls = {} -------------------------------- +-- SET YOUR FIVEMERR API HERE. +-- Look at their docs below for more info. +-- https://docs.fivemerr.com/integrations/mdt-scripts/ps-mdt +-- Images for mug shots will be uploaded here and will not expire. +local FivemerrMugShot = 'https://api.fivemerr.com/v1/media/images' +local FivemerrApiKey = 'YOUR API KEY HERE' + +-------------------------------- +-- NOT RECOMMENDED. WE RECOMMEND USING Fivemerr. -- SET YOUR WEHBOOKS IN HERE -- Images for mug shots will be uploaded here. Add a Discord webhook. local MugShotWebhook = '' @@ -25,13 +34,27 @@ local IncidentWebhook = '' -------------------------------- QBCore.Functions.CreateCallback('ps-mdt:server:MugShotWebhook', function(source, cb) - if MugShotWebhook == '' then - print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 16)\27[0m") + if Config.MugShotWebhook then + if MugShotWebhook == '' then + print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 18)\27[0m") + cb('', '') + else + cb(MugShotWebhook, '') + end + elseif Config.FivemerrMugShot then + if FivemerrMugShot == '' then + print("\27[31mFivemerr setup is missing in: FivemerrMugShot (server > main.lua > line 19)\27[0m") + cb('', '') + else + cb(FivemerrMugShot, FivemerrApiKey) + end else - cb(MugShotWebhook) + print("\27[31mNo valid webhook configuration found.\27[0m") + cb('', '') end end) + local function GetActiveData(cid) local player = type(cid) == "string" and cid or tostring(cid) if player then @@ -89,17 +112,20 @@ end AddEventHandler('onResourceStart', function(resourceName) if GetCurrentResourceName() ~= resourceName then return end - Wait(3000) - if MugShotWebhook == '' then - print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 16)\27[0m") + Wait(3000) + if Config.MugShotWebhook and MugShotWebhook == '' then + print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 16)\27[0m") + end + if Config.FivemerrMugShot and FivemerrMugShot == '' then + print("\27[31mFivemerr setup is missing in: FivemerrMugShot (server > main.lua > line 19)\27[0m") end if ClockinWebhook == '' then - print("\27[31mA webhook is missing in: ClockinWebhook (server > main.lua > line 20)\27[0m") - end - if GetResourceState('ps-dispatch') == 'started' then - local calls = exports['ps-dispatch']:GetDispatchCalls() - return calls - end + print("\27[31mA webhook is missing in: ClockinWebhook (server > main.lua > line 24)\27[0m") + end + if GetResourceState('ps-dispatch') == 'started' then + local calls = exports['ps-dispatch']:GetDispatchCalls() + return calls + end end) RegisterNetEvent("ps-mdt:server:OnPlayerUnload", function() diff --git a/shared/config.lua b/shared/config.lua index 50abaf41..e8b35e9d 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -3,6 +3,14 @@ Config = Config or {} Config.UsingPsHousing = false Config.UsingDefaultQBApartments = true Config.OnlyShowOnDuty = true + +-- RECOMMENDED Fivemerr Images. DOES NOT EXPIRE. +-- YOU NEED TO SET THIS UP FOLLOW INSTRUCTIONS BELOW. +-- Documents: https://docs.fivemerr.com/integrations/mdt-scripts/ps-mdt +Config.FivemerrMugShot = true + +-- Discord webhook for images. NOT RECOMMENDED, IMAGES EXPIRE. +Config.MugShotWebhook = false Config.UseCQCMugshot = true -- Front, Back Side. Use 4 for both sides, we recommend leaving at 1 for default.