Advertisement
Ewgeniy

other signalka

Jan 22nd, 2025 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.75 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local internet = require("internet")
  4. local tty = require("tty")
  5. local fs = require("filesystem")
  6. local json = require("json")
  7. local serial = require("serialization")
  8. local gpu = require("component").gpu
  9.  
  10. local radar = component.radar
  11. local oldback = gpu.getBackground()
  12. local oldfore = gpu.getForeground()
  13.  
  14. -- Запрашиваем у пользователя данные для Telegram
  15. print("Enter your Telegram Bot Token:")
  16. local botToken = io.read()
  17. print("Enter your Telegram Chat ID:")
  18. local chatID = io.read()
  19.  
  20. tty.clear()
  21.  
  22. io.write([===[
  23.                  .-_; ;_-.
  24.                 / /     \ \
  25.                | |       | |
  26.                 \ \.---./ /
  27.             .-"~   .---.   ~"-.
  28.           ,`.-~/ .'`---`'. \~-.`,
  29.           '`   | | \(_)/ | |   `'
  30.           ,    \  \ | | /  /    ,
  31.           ;`'.,_\  `-'-'  /_,.'`;
  32.            '-._  _.-'^'-._  _.-'
  33.                ``         ``  
  34. ]===])
  35. print("Primitive radar tracking program v2.0")
  36. print("By HappyWindinkg")
  37. print("Radar detection radius: ", radar.getRange())
  38. print()
  39. print("List of offenders:")
  40.  
  41. -- Функция для кодирования URL
  42. local function urlencode(str)
  43.    if (str) then
  44.       str = string.gsub(str, "\n", "\r\n")
  45.       str = string.gsub(str, "([^%w ])",
  46.          function (c) return string.format("%%%02X", string.byte(c)) end)
  47.       str = string.gsub(str, " ", "+")
  48.    end
  49.    return str    
  50. end
  51.  
  52. -- Функция для отправки данных в Telegram
  53. local function telegramGET(chatid, text)
  54.     local result, reason = internet.request("https://api.telegram.org/bot" .. botToken .. "/sendMessage?chat_id=" .. chatID .. "&text=" .. urlencode(text))
  55.     local info = ""
  56.     if result then
  57.         for chunk in result do
  58.             info = info .. chunk
  59.         end
  60.         return info
  61.     else
  62.         return "Error: " .. (reason or "unknown error")
  63.     end
  64. end
  65.  
  66. -- Функция для записи никнеймов в файл
  67. local function saveToFile(filename, text)
  68.     local file, err = io.open(filename, "a")
  69.     if not file then
  70.         print("Error opening file: " .. (err or "unknown error"))
  71.         return
  72.     end
  73.     file:write(text .. "\n")
  74.     file:close()
  75. end
  76.  
  77. --(установить для своего часового пояса, -12 : +13, например: -2 или 6)
  78. local TIME_ZONE = 3  
  79.  
  80. --(не изменять!)
  81. local t_correction = TIME_ZONE * 3600
  82.  
  83. function os.dateRL(format)
  84.     if not fs.get("/").isReadOnly() then
  85.         local time = io.open("/tmp/.time", "w")
  86.         time:write()
  87.         time:close()
  88.         os.sleep(0.01)
  89.         local currentTime = fs.lastModified("/tmp/.time") / 1000
  90.         currentTime = currentTime + 3 * 3600
  91.         return os.date(format, currentTime)
  92.     else
  93.         local currentTime = os.time()
  94.         currentTime = currentTime + 3 * 3600
  95.         return os.date(format, currentTime)
  96.     end
  97. end
  98.  
  99. -- Основной цикл программы
  100. local whiteList = {"cloud", "LeShyj", "entity.Cat.name", "reload", "karnel"}
  101.  
  102. local function checkRadar()
  103.     local detectedPlayers = radar.getPlayers()
  104.     for _, player in ipairs(detectedPlayers) do
  105.         local name = player.name
  106.         local unauthorized = true
  107.         for i = 1, #whiteList do
  108.             if whiteList[i] == name then
  109.                 unauthorized = false
  110.                 break
  111.             end
  112.         end
  113.         if unauthorized then
  114.             local alertMessage = "Unauthorized visitor detected: " .. name .. " " .. os.dateRL("%x %X")
  115.             local alert2Message = "All the user details namely, IP Address, Nickname, Identification Number and Residence have been successfully sent [OK];"
  116.             local alertErrorMessage = "Something prevented the data from being sent [ERR];\nSaving a local copy of the file [OK];"
  117.  
  118.             print(alertMessage)
  119.  
  120.             local telegramSuccess, telegramResponse = pcall(telegramGET, chatID, alertMessage)
  121.             if telegramSuccess then
  122.                 gpu.setForeground(0x00FF00)
  123.                 print("Data sent to Telegram: " .. alert2Message)
  124.                 saveToFile("/home/1.txt", name .. " " .. os.dateRL("%x %X"))
  125.                 gpu.setForeground(oldfore)
  126.                 print(" ")
  127.             else
  128.                 gpu.setForeground(0xFF0000)
  129.                 print("Error sending to Telegram: " .. alertErrorMessage)  
  130.                 saveToFile("/home/1.txt", name .. " " .. os.dateRL("%x %X"))
  131.                 gpu.setForeground(oldfore)
  132.                 print(" ")
  133.             end
  134.         end
  135.     end
  136. end
  137.  
  138. while true do
  139.     checkRadar()
  140.     os.sleep(60) -- Пауза на 1 минуту перед следующей проверкой
  141. end
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement