Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed webhooks to server #357

Merged
merged 4 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions client/cl_mugshot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ local MugShots = {}
-- Mugshot functions

local function TakeMugShot()
if Config.MugShotWebhook == '' then
print("^1A webhook is missing in: Config.MugShotWebhook")
else
exports['screenshot-basic']:requestScreenshotUpload(Config.MugShotWebhook, 'files[]', {encoding = 'jpg'}, function(data)
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)
end
end)
end

local function PhotoProcess(ped)
Expand Down Expand Up @@ -192,22 +190,26 @@ RegisterNetEvent('cqc-mugshot:client:trigger', function()
end)

RegisterNUICallback("sendToJail", function(data, cb)
local citizenId, sentence = data.citizenId, data.sentence

-- Gets the player id from the citizenId
local p = promise.new()
QBCore.Functions.TriggerCallback('mdt:server:GetPlayerSourceId', function(result)
p:resolve(result)
end, citizenId)

local targetSourceId = Citizen.Await(p)

if sentence > 0 then
if Config.UseCQCMugshot then
TriggerServerEvent('cqc-mugshot:server:triggerSuspect', targetSourceId)
QBCore.Functions.TriggerCallback('ps-mdt:server:MugShotWebhook', function(MugShotWebhook)
if MugShotWebhook ~= '' then
local citizenId, sentence = data.citizenId, data.sentence

-- Gets the player id from the citizenId
local p = promise.new()
QBCore.Functions.TriggerCallback('mdt:server:GetPlayerSourceId', function(result)
p:resolve(result)
end, citizenId)

local targetSourceId = Citizen.Await(p)

if sentence > 0 then
if Config.UseCQCMugshot then
TriggerServerEvent('cqc-mugshot:server:triggerSuspect', targetSourceId)
end
Citizen.Wait(5000)
-- Uses qb-policejob JailPlayer event
TriggerServerEvent("police:server:JailPlayer", targetSourceId, sentence)
end
end
Citizen.Wait(5000)
-- Uses qb-policejob JailPlayer event
TriggerServerEvent("police:server:JailPlayer", targetSourceId, sentence)
end
end)
end)
end)
33 changes: 26 additions & 7 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ local dispatchMessages = {}
local isDispatchRunning = false
local antiSpam = false


--------------------------------
-- SET YOUR WEHBOOKS IN HERE
-- Images for mug shots will be uploaded here. Add a Discord webhook.
local MugShotWebhook = ''

-- Clock-in notifications for duty. Add a Discord webhook.
-- Command /mdtleaderboard, will display top players per clock-in hours.
local ClockinWebhook = ''
--------------------------------

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")
else
cb(MugShotWebhook)
end
end)

local function GetActiveData(cid)
local player = type(cid) == "string" and cid or tostring(cid)
if player then
Expand Down Expand Up @@ -67,11 +86,11 @@ end
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
Wait(3000)
if Config.MugShotWebhook == '' then
print("\27[31mA webhook is missing in: Config.MugShotWebhook\27[0m")
if MugShotWebhook == '' then
print("\27[31mA webhook is missing in: MugShotWebhook (server > main.lua > line 16)\27[0m")
end
if Config.ClockinWebhook == '' then
print("\27[31mA webhook is missing in: Config.ClockinWebhook\27[0m")
if ClockinWebhook == '' then
print("\27[31mA webhook is missing in: ClockinWebhook (server > main.lua > line 20)\27[0m")
end
end)

Expand Down Expand Up @@ -1828,8 +1847,8 @@ AddEventHandler("mdt:requestOfficerData", function()
end)

function sendToDiscord(color, name, message, footer)
if Config.ClockinWebhook == '' then
print("\27[31mA webhook is missing in: Config.ClockinWebhook\27[0m")
if ClockinWebhook == '' then
print("\27[31mA webhook is missing in: ClockinWebhook (server > main.lua > line 20)\27[0m")
else
local embed = {
{
Expand All @@ -1842,7 +1861,7 @@ function sendToDiscord(color, name, message, footer)
}
}

PerformHttpRequest(Config.ClockinWebhook, function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
PerformHttpRequest(ClockinWebhook, function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
end
end

Expand Down
7 changes: 0 additions & 7 deletions shared/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ Config.UseCQCMugshot = true
-- Front, Back Side. Use 4 for both sides, we recommend leaving at 1 for default.
Config.MugPhotos = 1

-- Images for mug shots will be uploaded here. Add a Discord webhook.
Config.MugShotWebhook = ''

-- Clock-in notifications for duty. Add a Discord webhook.
-- Command /mdtleaderboard, will display top players per clock-in hours.
Config.ClockinWebhook = ''

-- If set to true = Fine gets automatically removed from bank automatically charging the player.
-- If set to false = The fine gets sent as an Invoice to their phone and it us to the player to pay for it, can remain unpaid and ignored.
Config.BillVariation = true
Expand Down