Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local internet = require("internet")
- local tty = require("tty")
- local fs = require("filesystem")
- local json = require("json")
- local serial = require("serialization")
- local gpu = require("component").gpu
- local radar = component.radar
- local oldback = gpu.getBackground()
- local oldfore = gpu.getForeground()
- -- Запрашиваем у пользователя данные для Telegram
- print("Enter your Telegram Bot Token:")
- local botToken = io.read()
- print("Enter your Telegram Chat ID:")
- local chatID = io.read()
- tty.clear()
- io.write([===[
- .-_; ;_-.
- / / \ \
- | | | |
- \ \.---./ /
- .-"~ .---. ~"-.
- ,`.-~/ .'`---`'. \~-.`,
- '` | | \(_)/ | | `'
- , \ \ | | / / ,
- ;`'.,_\ `-'-' /_,.'`;
- '-._ _.-'^'-._ _.-'
- `` ``
- ]===])
- print("Primitive radar tracking program v2.0")
- print("By HappyWindinkg")
- print("Radar detection radius: ", radar.getRange())
- print()
- print("List of offenders:")
- -- Функция для кодирования URL
- local function urlencode(str)
- if (str) then
- str = string.gsub(str, "\n", "\r\n")
- str = string.gsub(str, "([^%w ])",
- function (c) return string.format("%%%02X", string.byte(c)) end)
- str = string.gsub(str, " ", "+")
- end
- return str
- end
- -- Функция для отправки данных в Telegram
- local function telegramGET(chatid, text)
- local result, reason = internet.request("https://api.telegram.org/bot" .. botToken .. "/sendMessage?chat_id=" .. chatID .. "&text=" .. urlencode(text))
- local info = ""
- if result then
- for chunk in result do
- info = info .. chunk
- end
- return info
- else
- return "Error: " .. (reason or "unknown error")
- end
- end
- -- Функция для записи никнеймов в файл
- local function saveToFile(filename, text)
- local file, err = io.open(filename, "a")
- if not file then
- print("Error opening file: " .. (err or "unknown error"))
- return
- end
- file:write(text .. "\n")
- file:close()
- end
- --(установить для своего часового пояса, -12 : +13, например: -2 или 6)
- local TIME_ZONE = 3
- --(не изменять!)
- local t_correction = TIME_ZONE * 3600
- function os.dateRL(format)
- if not fs.get("/").isReadOnly() then
- local time = io.open("/tmp/.time", "w")
- time:write()
- time:close()
- os.sleep(0.01)
- local currentTime = fs.lastModified("/tmp/.time") / 1000
- currentTime = currentTime + 3 * 3600
- return os.date(format, currentTime)
- else
- local currentTime = os.time()
- currentTime = currentTime + 3 * 3600
- return os.date(format, currentTime)
- end
- end
- -- Основной цикл программы
- local whiteList = {"cloud", "LeShyj", "entity.Cat.name", "reload", "karnel"}
- local function checkRadar()
- local detectedPlayers = radar.getPlayers()
- for _, player in ipairs(detectedPlayers) do
- local name = player.name
- local unauthorized = true
- for i = 1, #whiteList do
- if whiteList[i] == name then
- unauthorized = false
- break
- end
- end
- if unauthorized then
- local alertMessage = "Unauthorized visitor detected: " .. name .. " " .. os.dateRL("%x %X")
- local alert2Message = "All the user details namely, IP Address, Nickname, Identification Number and Residence have been successfully sent [OK];"
- local alertErrorMessage = "Something prevented the data from being sent [ERR];\nSaving a local copy of the file [OK];"
- print(alertMessage)
- local telegramSuccess, telegramResponse = pcall(telegramGET, chatID, alertMessage)
- if telegramSuccess then
- gpu.setForeground(0x00FF00)
- print("Data sent to Telegram: " .. alert2Message)
- saveToFile("/home/1.txt", name .. " " .. os.dateRL("%x %X"))
- gpu.setForeground(oldfore)
- print(" ")
- else
- gpu.setForeground(0xFF0000)
- print("Error sending to Telegram: " .. alertErrorMessage)
- saveToFile("/home/1.txt", name .. " " .. os.dateRL("%x %X"))
- gpu.setForeground(oldfore)
- print(" ")
- end
- end
- end
- end
- while true do
- checkRadar()
- os.sleep(60) -- Пауза на 1 минуту перед следующей проверкой
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement