Skip to content

Commit

Permalink
Added support for Fivemerr Image Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyWhisper committed Jul 8, 2024
1 parent 28599f6 commit fd0662b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 21 deletions.
32 changes: 23 additions & 9 deletions client/cl_mugshot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -212,4 +226,4 @@ RegisterNUICallback("sendToJail", function(data, cb)
end
end
end)
end)
end)
50 changes: 38 additions & 12 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fd0662b

Please sign in to comment.