From 70199ea3106785d2a54b2cee19b866040572bcf0 Mon Sep 17 00:00:00 2001 From: Luxu <122475744+luxu-gg@users.noreply.github.com> Date: Mon, 5 May 2025 18:11:58 +0100 Subject: [PATCH] okokPhone integration --- modules/phone/okokPhone/client.lua | 16 +++++++++ modules/phone/okokPhone/server.lua | 55 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 modules/phone/okokPhone/client.lua create mode 100644 modules/phone/okokPhone/server.lua diff --git a/modules/phone/okokPhone/client.lua b/modules/phone/okokPhone/client.lua new file mode 100644 index 0000000..623b01a --- /dev/null +++ b/modules/phone/okokPhone/client.lua @@ -0,0 +1,16 @@ +local resourceName = "okokPhone" +local configValue = BridgeSharedConfig.Phone +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +Phone = Phone or {} + +---comment +---@param email string +---@param title string +---@param message string +---@return boolean +---@diagnostic disable-next-line: duplicate-set-field +Phone.SendEmail = function(email, title, message) + local success = lib.callback.await('community_bridge:Callback:okokPhone:sendEmail', false, email, title, message) --[[ @as boolean ]] + return success +end diff --git a/modules/phone/okokPhone/server.lua b/modules/phone/okokPhone/server.lua new file mode 100644 index 0000000..67643cb --- /dev/null +++ b/modules/phone/okokPhone/server.lua @@ -0,0 +1,55 @@ +---@class NewEmail +---@field sender string +---@field recipients string[] +---@field subject string +---@field actions? EmailAction[] +---@field body string + +---@class EmailAction +---@field id string +---@field label string +---@field event string? +---@field exports string? +---@field server boolean +---@field data any + +local resourceName = "okokPhone" +local configValue = BridgeSharedConfig.Phone +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end +Phone = Phone or {} + +---comment +---@param src number +---@return number| boolean +---@diagnostic disable-next-line: duplicate-set-field +Phone.GetPlayerPhone = function(src) + return exports.okokPhone:getPhoneNumberFromSource(src) or false +end + +---comment +---@param src number +---@param email string +---@param title string +---@param message string +---@return boolean +---@diagnostic disable-next-line: duplicate-set-field +Phone.SendEmail = function(src, email, title, message) + local senderAddress = exports.okokPhone:getEmailAddressFromSource(src) --[[ @as string? ]] + if not senderAddress then return false end + + ---@type NewEmail + local data = { + sender = senderAddress, + recipients = { email }, + subject = title, + body = message, + } + + local success = exports.okokPhone:sendEmail(data) --[[ @as boolean ]] + return success +end + + +lib.callback.registry('community_bridge:Callback:okokPhone:sendEmail', function(src, email, title, message) + return Phone.SendEmail(src, email, title, message) +end)