Уведа в тг о звонке в игре | RODINA RP

Helix999

Известный
Автор темы
15
1
Версия MoonLoader
.026-beta
Есть такой скрипт на аризону "Уведы звонка в тг":
Код:
function onReceivePacket(id, bs)
   if jsonConfig['notifications'].logCalls then
      if id == 220 then
         raknetBitStreamReadInt8(bs);
         if raknetBitStreamReadInt8(bs) == 17 then
            raknetBitStreamReadInt32(bs);
            local lenCall, textCall = raknetBitStreamReadInt32(bs), '';
            if lenCall > 0 then
               textCall = raknetBitStreamReadString(bs, lenCall)
               local eventCall, dataCall = textCall:match('window%.executeEvent%(\'([%w.]+)\',%s*\'(.+)\'%)');
               if eventCall == 'event.call.InitializeCaller' then
                  local okCall, jsonCall = pcall(decodeJson, dataCall)
                  if okCall and jsonCall[1] and (lastCall + 2) < os.clock() then
                     lastCall = os.clock()
                     sendTelegramNotification('Входящий вызов!\nВам звонит '..jsonCall[1])
                  end
               end
            end
         end
      end
   end
Мне нужно его переделать под Родину, как я понял, ивенты там разные, через cefmonitoring нашел это:
Ь9window.executeEvent('event.phone.selectApp', '[ call ]')
В скриптинге я полный ноль, могу ток чет поменять какието строчки и чуть чуть переделать под себя.
Вообщем господа скриптеры, помогите пожалуйста переделать скрипт уведы звонка на арз, под родину рп пожалуйста.
 

kitsad

Участник
56
12
 

Helix999

Известный
Автор темы
15
1
Честно говоря не хочется платить за то чтобы я получал тупо уведу в тг о звонке)), почему "Тупо уведу о звонке", мне другой функционал не интересует.
 

- |2347| -

Известный
387
148
код:
local effil = require("effil")
local encoding = require("encoding")
encoding.default = 'CP1251'
u8 = encoding.UTF8

chat_id = '' -- чат ID юзера
token = '' -- токен бота


addEventHandler('onReceivePacket', function (id, bs)
    if id ~= 220 then return end
    raknetBitStreamIgnoreBits(bs, 8)
    if raknetBitStreamReadInt8(bs) ~= 17 then return end
    raknetBitStreamIgnoreBits(bs, 32)
    local length = raknetBitStreamReadInt16(bs)
    local encoded = raknetBitStreamReadInt8(bs)
    local str = (encoded ~= 0) and raknetBitStreamDecodeString(bs, length + encoded) or raknetBitStreamReadString(bs, length)
    if not str then return end

    if str:find("event.call.InitializeCaller") then
        local json = str:match('window.executeEvent%(\'event.call.InitializeCaller\', `(.+)`%)')
        local data = decodeJson(json)
        nick = data[1]
    end
    if str:find("event.call.InitializeNumber") then
        local json = str:match('window.executeEvent%(\'event.call.InitializeNumber\', `(.+)`%)')
        local data = decodeJson(json)
        number = data[1]
        sampAddChatMessage(nick..' '..number, -1)
        sendTelegramNotification('Входящий вызов! '..nick..' Номер: '..number)
    end
end)

local updateid

function threadHandle(runner, url, args, resolve, reject)
    local t = runner(url, args)
    local r = t:get(0)
    while not r do
        r = t:get(0)
        wait(0)
    end
    local status = t:status()
    if status == 'completed' then
        local ok, result = r[1], r[2]
        if ok then resolve(result) else reject(result) end
    elseif err then
        reject(err)
    elseif status == 'canceled' then
        reject(status)
    end
    t:cancel(0)
end

function requestRunner()
    return effil.thread(function(u, a)
        local https = require 'ssl.https'
        local ok, result = pcall(https.request, u, a)
        if ok then
            return {true, result}
        else
            return {false, result}
        end
    end)
end

function async_http_request(url, args, resolve, reject)
    local runner = requestRunner()
    if not reject then reject = function() end end
    lua_thread.create(function()
        threadHandle(runner, url, args, resolve, reject)
    end)
end

function encodeUrl(str)
    str = str:gsub(' ', '%+')
    str = str:gsub('\n', '%%0A')
    return u8:encode(str, 'CP1251')
end

function sendTelegramNotification(msg)
    msg = msg:gsub('{......}', '')
    msg = encodeUrl(msg)
    async_http_request('https://api.telegram.org/bot' .. token .. '/sendMessage?chat_id=' .. chat_id .. '&text='..msg,'', function(result) end) -- а тут уже отправка
end

function getLastUpdate()
    async_http_request('https://api.telegram.org/bot'..token..'/getUpdates?chat_id='..chat_id..'&offset=-1','',function(result)
        if result then
            local proc_table = decodeJson(result)
            if proc_table.ok then
                if #proc_table.result > 0 then
                    local res_table = proc_table.result[1]
                    if res_table then
                        updateid = res_table.update_id
                    end
                else
                    updateid = 1
                end
            end
        end
    end)
end

function main()
    while not isSampAvailable() do wait(0) end
    getLastUpdate()
    while true do
        wait(0)
    end
end
 

Helix999

Известный
Автор темы
15
1
код:
local effil = require("effil")
local encoding = require("encoding")
encoding.default = 'CP1251'
u8 = encoding.UTF8

chat_id = '' -- чат ID юзера
token = '' -- токен бота


addEventHandler('onReceivePacket', function (id, bs)
    if id ~= 220 then return end
    raknetBitStreamIgnoreBits(bs, 8)
    if raknetBitStreamReadInt8(bs) ~= 17 then return end
    raknetBitStreamIgnoreBits(bs, 32)
    local length = raknetBitStreamReadInt16(bs)
    local encoded = raknetBitStreamReadInt8(bs)
    local str = (encoded ~= 0) and raknetBitStreamDecodeString(bs, length + encoded) or raknetBitStreamReadString(bs, length)
    if not str then return end

    if str:find("event.call.InitializeCaller") then
        local json = str:match('window.executeEvent%(\'event.call.InitializeCaller\', `(.+)`%)')
        local data = decodeJson(json)
        nick = data[1]
    end
    if str:find("event.call.InitializeNumber") then
        local json = str:match('window.executeEvent%(\'event.call.InitializeNumber\', `(.+)`%)')
        local data = decodeJson(json)
        number = data[1]
        sampAddChatMessage(nick..' '..number, -1)
        sendTelegramNotification('Входящий вызов! '..nick..' Номер: '..number)
    end
end)

local updateid

function threadHandle(runner, url, args, resolve, reject)
    local t = runner(url, args)
    local r = t:get(0)
    while not r do
        r = t:get(0)
        wait(0)
    end
    local status = t:status()
    if status == 'completed' then
        local ok, result = r[1], r[2]
        if ok then resolve(result) else reject(result) end
    elseif err then
        reject(err)
    elseif status == 'canceled' then
        reject(status)
    end
    t:cancel(0)
end

function requestRunner()
    return effil.thread(function(u, a)
        local https = require 'ssl.https'
        local ok, result = pcall(https.request, u, a)
        if ok then
            return {true, result}
        else
            return {false, result}
        end
    end)
end

function async_http_request(url, args, resolve, reject)
    local runner = requestRunner()
    if not reject then reject = function() end end
    lua_thread.create(function()
        threadHandle(runner, url, args, resolve, reject)
    end)
end

function encodeUrl(str)
    str = str:gsub(' ', '%+')
    str = str:gsub('\n', '%%0A')
    return u8:encode(str, 'CP1251')
end

function sendTelegramNotification(msg)
    msg = msg:gsub('{......}', '')
    msg = encodeUrl(msg)
    async_http_request('https://api.telegram.org/bot' .. token .. '/sendMessage?chat_id=' .. chat_id .. '&text='..msg,'', function(result) end) -- а тут уже отправка
end

function getLastUpdate()
    async_http_request('https://api.telegram.org/bot'..token..'/getUpdates?chat_id='..chat_id..'&offset=-1','',function(result)
        if result then
            local proc_table = decodeJson(result)
            if proc_table.ok then
                if #proc_table.result > 0 then
                    local res_table = proc_table.result[1]
                    if res_table then
                        updateid = res_table.update_id
                    end
                else
                    updateid = 1
                end
            end
        end
    end)
end

function main()
    while not isSampAvailable() do wait(0) end
    getLastUpdate()
    while true do
        wait(0)
    end
end
Спасибо добрый человек <3

Спасибо добрый человек <3
я же могу туда приветствие при загрузке\перезагрузке скрипта? А то чет я пихнул, а оно не выводит в чат ничего.
 
Последнее редактирование:
  • Нравится
Реакции: - |2347| -