forked from Simnation/Main
74 lines
2.6 KiB
Lua
74 lines
2.6 KiB
Lua
![]() |
local WEBHOOK_URL = 'https://discord.com/api/webhooks/1404878934486814820/lGE3-nhiBaT_btVevr9gPGr1zpjS8ycDQP4NqWOFqaNrbTHsib_AH6tcVIKyQzN-jfOS'
|
||
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||
|
|
||
|
function tableHasValue(table, value)
|
||
|
if table == nil or value == nil then
|
||
|
return
|
||
|
end
|
||
|
for _, v in ipairs(table) do
|
||
|
if v == value then
|
||
|
return true
|
||
|
end
|
||
|
end
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
function generateRandomNumber(length)
|
||
|
math.randomseed(os.time())
|
||
|
local randomNumber = ""
|
||
|
for i = 1, length do
|
||
|
local rand = math.random(0, 9)
|
||
|
randomNumber = randomNumber .. rand
|
||
|
end
|
||
|
return tonumber(randomNumber)
|
||
|
end
|
||
|
|
||
|
function SendWebhook(source, msg)
|
||
|
local Player = QBCore.Functions.GetPlayer(source)
|
||
|
local playerCoords = GetEntityCoords(GetPlayerPed(source))
|
||
|
local playerId = Player.PlayerData.citizenid
|
||
|
local playerName = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname
|
||
|
|
||
|
local timestamp = os.time()
|
||
|
-- Check if there are any admins online
|
||
|
local adminCount = 0
|
||
|
local players = QBCore.Functions.GetPlayers()
|
||
|
for _, v in pairs(players) do
|
||
|
local targetPlayer = QBCore.Functions.GetPlayer(v)
|
||
|
if targetPlayer and QBCore.Functions.HasPermission(v, 'admin') then
|
||
|
adminCount = adminCount + 1
|
||
|
end
|
||
|
end
|
||
|
|
||
|
local color = (adminCount <= 0) and 15548997 or 5763719
|
||
|
|
||
|
local embed = {
|
||
|
{
|
||
|
["color"] = color,
|
||
|
["author"] = {
|
||
|
name = 'SIM IC Support',
|
||
|
icon_url = 'https://cdn.discordapp.com/attachments/1374237889759674470/1404881799036801024/ffffffffffffffffffffff.png?ex=689ccda2&is=689b7c22&hm=2d34de549aeefceb84bc8a0b56649330c61caad2bd2ea4118650b82e92842dc8&'
|
||
|
},
|
||
|
["title"] = '??? NEW TICKET',
|
||
|
["description"] = table.concat({
|
||
|
'**' .. playerName .. '** requested an admin for: ' .. msg,
|
||
|
'',
|
||
|
'**Server ID:** ' .. source,
|
||
|
'**Username:** ' .. GetPlayerName(source),
|
||
|
'**Identifier:** ' .. playerId,
|
||
|
'**Coords:** ' .. tostring(playerCoords),
|
||
|
'',
|
||
|
'<t:' .. timestamp .. ':R>'
|
||
|
}, '\n'),
|
||
|
["footer"] = {
|
||
|
text = "SimNation - Logger"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-- HTTP-Anfrage senden
|
||
|
PerformHttpRequest(WEBHOOK_URL, function(err, text, headers)
|
||
|
if err ~= 200 then print("Webhook Error: " .. (text or "Unknown error")) end
|
||
|
end, 'POST', json.encode({username = "SIM Logger", embeds = embed}), { ['Content-Type'] = 'application/json' })
|
||
|
end
|