mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-19 23:06:04 +01:00
Compare commits
7 Commits
6166314cbf
...
6919f038ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6919f038ee | ||
|
|
47029da6ed | ||
|
|
e1d292d1bf | ||
|
|
f08638812c | ||
|
|
de5424c506 | ||
|
|
b46d734442 | ||
|
|
92ad96e435 |
71
.github/workflows/notify-release.yml
vendored
Normal file
71
.github/workflows/notify-release.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
name: Discord Release Notifier
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Manual or UI-published releases
|
||||||
|
release:
|
||||||
|
types: [published]
|
||||||
|
|
||||||
|
# Releases created by your tag-driven workflow
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Package & Release"] # must match the 'name:' in release.yml
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# 1) Handle manual / UI / non-workflow-created releases
|
||||||
|
notify-from-release:
|
||||||
|
if: github.event_name == 'release' && github.event.action == 'published'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Send release payload to Discord Bot
|
||||||
|
env:
|
||||||
|
URL: http://${{ secrets.DISCORDBOT }}:3000/github-releases
|
||||||
|
run: |
|
||||||
|
curl -sS -X POST "$URL" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
--data-binary "@$GITHUB_EVENT_PATH"
|
||||||
|
|
||||||
|
# 2) Handle releases created by your 'Package & Release' workflow
|
||||||
|
# (which won’t trigger `on: release` when using GITHUB_TOKEN)
|
||||||
|
notify-from-workflow-run:
|
||||||
|
if: >
|
||||||
|
github.event_name == 'workflow_run' &&
|
||||||
|
github.event.workflow_run.conclusion == 'success'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install jq
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y jq
|
||||||
|
|
||||||
|
- name: Fetch release JSON by tag
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
OWNER="${GITHUB_REPOSITORY%/*}"
|
||||||
|
REPO="${GITHUB_REPOSITORY#*/}"
|
||||||
|
TAG="${{ github.event.workflow_run.head_branch }}"
|
||||||
|
# head_branch is the tag name for a tag push workflow_run
|
||||||
|
curl -fsSL -H "Authorization: Bearer $GH_TOKEN" \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
"https://api.github.com/repos/$OWNER/$REPO/releases/tags/$TAG" \
|
||||||
|
> release.json
|
||||||
|
|
||||||
|
- name: Wrap as 'release' event payload & notify bot
|
||||||
|
env:
|
||||||
|
URL: http://${{ secrets.DISCORDBOT }}:3000/github-releases
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
jq -n --slurpfile rel release.json \
|
||||||
|
--arg repo "$GITHUB_REPOSITORY" \
|
||||||
|
--arg repo_url "https://github.com/$GITHUB_REPOSITORY" \
|
||||||
|
--arg action "published" '
|
||||||
|
{ action: $action,
|
||||||
|
repository: { full_name: $repo, html_url: $repo_url },
|
||||||
|
release: $rel[0],
|
||||||
|
sender: { login: "github-actions[bot]" } }' > payload.json
|
||||||
|
|
||||||
|
curl -sS -X POST "$URL" \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
--data-binary "@payload.json"
|
||||||
@@ -27,6 +27,132 @@ local function _debouncedRun(func)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local frameworkLoadFunc = {
|
||||||
|
{ framework = Exports.QBXExport,
|
||||||
|
onPlayerLoaded =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', func)
|
||||||
|
end,
|
||||||
|
onPlayerUnload =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerUnload', func)
|
||||||
|
end,
|
||||||
|
waitforLogin =
|
||||||
|
function(timeout)
|
||||||
|
local startTime = GetGameTimer()
|
||||||
|
while not LocalPlayer.state.isLoggedIn and (GetGameTimer() - startTime) < timeout do
|
||||||
|
Wait(100)
|
||||||
|
end
|
||||||
|
return LocalPlayer.state.isLoggedIn
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = Exports.QBExport,
|
||||||
|
onPlayerLoaded =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', func)
|
||||||
|
end,
|
||||||
|
onPlayerUnload =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('QBCore:Client:OnPlayerUnload', func)
|
||||||
|
end,
|
||||||
|
waitforLogin =
|
||||||
|
function(timeout)
|
||||||
|
local startTime = GetGameTimer()
|
||||||
|
while not LocalPlayer.state.isLoggedIn and (GetGameTimer() - startTime) < timeout do
|
||||||
|
Wait(100)
|
||||||
|
end
|
||||||
|
return LocalPlayer.state.isLoggedIn
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = Exports.ESXExport,
|
||||||
|
onPlayerLoaded =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent("esx:playerLoaded", function()
|
||||||
|
-- make sure shared has loaded (because sql)
|
||||||
|
if waitForSharedLoad() then func() end
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
onPlayerUnload =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent("esx:onPlayerLogout", func)
|
||||||
|
end,
|
||||||
|
waitforLogin =
|
||||||
|
function(timeout)
|
||||||
|
local startTime = GetGameTimer()
|
||||||
|
while (GetGameTimer() - startTime) < timeout do
|
||||||
|
local playerData = ESX.GetPlayerData()
|
||||||
|
if playerData and playerData.job then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
Wait(100)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = Exports.OXCoreExport,
|
||||||
|
onPlayerLoaded =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('ox:playerLoaded', func)
|
||||||
|
end,
|
||||||
|
onPlayerUnload =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('ox:playerLogout', func)
|
||||||
|
end,
|
||||||
|
waitforLogin =
|
||||||
|
function(timeout)
|
||||||
|
if OxPlayer["stateId"] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
while not OxPlayer["stateId"] do
|
||||||
|
Wait(1000)
|
||||||
|
if OxPlayer.get["stateId"] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = Exports.RSGExport,
|
||||||
|
onPlayerLoaded =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('RSGCore:Client:OnPlayerLoaded', func)
|
||||||
|
end,
|
||||||
|
onPlayerUnload =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('RSGCore:Client:OnPlayerUnload', func)
|
||||||
|
end,
|
||||||
|
waitforLogin =
|
||||||
|
function(timeout)
|
||||||
|
local startTime = GetGameTimer()
|
||||||
|
while not LocalPlayer.state.isLoggedIn and (GetGameTimer() - startTime) < timeout do
|
||||||
|
Wait(100)
|
||||||
|
end
|
||||||
|
return LocalPlayer.state.isLoggedIn
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
{ framework = Exports.VorpExport,
|
||||||
|
onPlayerLoaded =
|
||||||
|
function(func)
|
||||||
|
RegisterNetEvent('vorp_core:Client:OnPlayerSpawned', func)
|
||||||
|
end,
|
||||||
|
onPlayerUnload =
|
||||||
|
function(func)
|
||||||
|
--??
|
||||||
|
end,
|
||||||
|
waitforLogin =
|
||||||
|
function(timeout)
|
||||||
|
local startTime = GetGameTimer()
|
||||||
|
while not LocalPlayer.state.IsInSession and (GetGameTimer() - startTime) < timeout do
|
||||||
|
Wait(100)
|
||||||
|
end
|
||||||
|
return LocalPlayer.state.IsInSession
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Player Loaded and Unloaded Events
|
-- Player Loaded and Unloaded Events
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
@@ -44,9 +170,6 @@ end
|
|||||||
--- end, true)
|
--- end, true)
|
||||||
--- ```
|
--- ```
|
||||||
function onPlayerLoaded(func, onStart)
|
function onPlayerLoaded(func, onStart)
|
||||||
local onPlayerFramework = ""
|
|
||||||
local loaded = false
|
|
||||||
|
|
||||||
if onStart then
|
if onStart then
|
||||||
onResourceStart(function()
|
onResourceStart(function()
|
||||||
if not waitForLogin() then return end
|
if not waitForLogin() then return end
|
||||||
@@ -59,34 +182,16 @@ function onPlayerLoaded(func, onStart)
|
|||||||
_debouncedRun(func)
|
_debouncedRun(func)
|
||||||
end
|
end
|
||||||
|
|
||||||
if isStarted(QBExport) or isStarted(QBXExport) then
|
for i = 1, #frameworkLoadFunc do
|
||||||
onPlayerFramework = QBExport
|
local data = frameworkLoadFunc[i]
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', handler)
|
jsonPrint(data)
|
||||||
|
if isStarted(data.framework) then
|
||||||
elseif isStarted(ESXExport) then
|
debugPrint("^6Bridge^7: ^2Registering ^3"..data.framework.." ^5onPlayerLoaded^7()")
|
||||||
onPlayerFramework = ESXExport
|
data.onPlayerLoaded(handler)
|
||||||
RegisterNetEvent('esx:playerLoaded', function()
|
return
|
||||||
if waitForSharedLoad() then handler() end
|
end
|
||||||
end)
|
|
||||||
|
|
||||||
elseif isStarted(OXCoreExport) then
|
|
||||||
onPlayerFramework = OXCoreExport
|
|
||||||
RegisterNetEvent('ox:playerLoaded', handler)
|
|
||||||
|
|
||||||
elseif isStarted(RSGExport) then
|
|
||||||
onPlayerFramework = RSGExport
|
|
||||||
RegisterNetEvent('RSGCore:Client:OnPlayerLoaded', handler)
|
|
||||||
|
|
||||||
elseif isStarted(VorpExport) then
|
|
||||||
onPlayerFramework = VorpExport
|
|
||||||
RegisterNetEvent('vorp_core:Client:OnPlayerSpawned', handler)
|
|
||||||
end
|
|
||||||
|
|
||||||
if onPlayerFramework ~= "" then
|
|
||||||
debugPrint("^6Bridge^7: ^2Registering ^3onPlayerLoaded^7()^2 with ^3" .. onPlayerFramework .. "^7")
|
|
||||||
else
|
|
||||||
print("^4ERROR^7: No supported core detected for onPlayerLoaded - Check starter.lua")
|
|
||||||
end
|
end
|
||||||
|
print("^1ERROR^7: ^1No supported core detected for onPlayerLoaded - Check starter.lua^7")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Executes a function when the player character is unloaded.
|
--- Executes a function when the player character is unloaded.
|
||||||
@@ -99,15 +204,15 @@ end
|
|||||||
--- end)
|
--- end)
|
||||||
--- ```
|
--- ```
|
||||||
function onPlayerUnload(func)
|
function onPlayerUnload(func)
|
||||||
debugPrint("^6Bridge^7: ^2Registering ^3onPlayerUnload^7()")
|
for i = 1, #frameworkLoadFunc do
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function() func() end)
|
local data = frameworkLoadFunc[i]
|
||||||
|
if isStarted(data.framework) then
|
||||||
RegisterNetEvent('ox:playerLogout', function() func() end)
|
debugPrint("^6Bridge^7: ^2Registering ^3"..data.framework.." ^5onPlayerUnload^7()")
|
||||||
|
data.onPlayerUnload(func)
|
||||||
RegisterNetEvent('RSGCore:Client:OnPlayerUnload', function() func() end)
|
return
|
||||||
|
end
|
||||||
RegisterNetEvent('esx:onPlayerLogout', function() func() end)
|
end
|
||||||
|
print("^1ERROR^7: ^1No supported core detected for onPlayerUnload - Check starter.lua^7")
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
@@ -166,51 +271,18 @@ end
|
|||||||
--- @usage
|
--- @usage
|
||||||
--- waitForLogin()
|
--- waitForLogin()
|
||||||
function waitForLogin()
|
function waitForLogin()
|
||||||
local timeout = 10000 -- 10 seconds in milliseconds
|
for i = 1, #frameworkLoadFunc do
|
||||||
local startTime = GetGameTimer()
|
local data = frameworkLoadFunc[i]
|
||||||
local loggedIn = false
|
if isStarted(data.framework) then
|
||||||
|
debugPrint("^6Bridge^7: ^2Waiting for ^3"..data.framework.."^2 player login^7.")
|
||||||
if isStarted(ESXExport) then
|
local result = data.waitforLogin(10000)
|
||||||
while (GetGameTimer() - startTime) < timeout do
|
if result == true then
|
||||||
local playerData = ESX.GetPlayerData()
|
debugPrint("^6Bridge^7: ^3"..data.framework.."^2 Player Login Detected^7.")
|
||||||
if playerData and playerData.job then
|
else
|
||||||
loggedIn = true
|
print("^4Error^7: ^2Timeout reached while waiting for player login^7.")
|
||||||
break
|
|
||||||
end
|
end
|
||||||
Wait(100)
|
return result
|
||||||
end
|
end
|
||||||
elseif isStarted(OXCoreExport) then
|
|
||||||
if OxPlayer["stateId"] then
|
|
||||||
loggedIn = true
|
|
||||||
end
|
|
||||||
while not OxPlayer["stateId"] do
|
|
||||||
Wait(1000)
|
|
||||||
debugPrint("Waiting for stateId to class as logged in")
|
|
||||||
if OxPlayer.get["stateId"] then
|
|
||||||
loggedIn = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif isStarted(VorpExport) then
|
|
||||||
-- For other frameworks, use LocalPlayer.state.isLoggedIn.
|
|
||||||
while not LocalPlayer.state.IsInSession and (GetGameTimer() - startTime) < timeout do
|
|
||||||
Wait(100)
|
|
||||||
end
|
|
||||||
loggedIn = LocalPlayer.state.IsInSession
|
|
||||||
else
|
|
||||||
-- For other frameworks, use LocalPlayer.state.isLoggedIn.
|
|
||||||
while not LocalPlayer.state.isLoggedIn and (GetGameTimer() - startTime) < timeout do
|
|
||||||
Wait(100)
|
|
||||||
end
|
|
||||||
loggedIn = LocalPlayer.state.isLoggedIn
|
|
||||||
end
|
|
||||||
|
|
||||||
if not loggedIn then
|
|
||||||
print("^4Error^7: ^2Timeout reached while waiting for player login^7.")
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
debugPrint("^6Bridge^7: ^2Player Login Detected^7.")
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ local InvFunc = {
|
|||||||
local weight = 0
|
local weight = 0
|
||||||
local itemcheck = getPlayerInv(src)
|
local itemcheck = getPlayerInv(src)
|
||||||
for _, v in pairs(itemcheck) do
|
for _, v in pairs(itemcheck) do
|
||||||
weight += ((v.weight * (v.amount or v.count)) or 0)
|
weight += v.weight
|
||||||
end
|
end
|
||||||
return weight
|
return weight
|
||||||
end,
|
end,
|
||||||
@@ -341,7 +341,7 @@ local InvFunc = {
|
|||||||
local count = 0
|
local count = 0
|
||||||
for _, itemData in pairs(invCache) do
|
for _, itemData in pairs(invCache) do
|
||||||
if itemData and itemData.name == item then
|
if itemData and itemData.name == item then
|
||||||
count += (itemData.amount or itemData.count or 1)
|
count += (itemData.amount or 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return count >= amount, count
|
return count >= amount, count
|
||||||
@@ -384,7 +384,7 @@ local InvFunc = {
|
|||||||
if src then
|
if src then
|
||||||
grabInv = exports[CodeMInv]:GetInventory(getPlayer(src).citizenId, src)
|
grabInv = exports[CodeMInv]:GetInventory(getPlayer(src).citizenId, src)
|
||||||
else
|
else
|
||||||
grabInv = exports[CodeMInv]:getUserInventory()
|
grabInv = exports[CodeMInv]:GetClientPlayerInventory()
|
||||||
end
|
end
|
||||||
return grabInv
|
return grabInv
|
||||||
end,
|
end,
|
||||||
@@ -1279,6 +1279,7 @@ end
|
|||||||
function hasItem(items, amount, src)
|
function hasItem(items, amount, src)
|
||||||
local amount = amount and amount or 1
|
local amount = amount and amount or 1
|
||||||
local grabInv, foundInv = getPlayerInv(src)
|
local grabInv, foundInv = getPlayerInv(src)
|
||||||
|
|
||||||
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
|
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
|
||||||
|
|
||||||
local hasTable = {}
|
local hasTable = {}
|
||||||
@@ -2516,7 +2517,7 @@ end
|
|||||||
--- ```
|
--- ```
|
||||||
function sellAnim(data, token)
|
function sellAnim(data, token)
|
||||||
if not hasItem(data.item, 1) then
|
if not hasItem(data.item, 1) then
|
||||||
triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..getItemLabel(data.item), "error")
|
triggerNotify(nil, (Loc[Config.Lan].error["dont_have"] or "You don't have any") .." "..getItemLabel(data.item), "error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user