LuaScripts/linkedGet.lua

41 lines
1 KiB
Lua
Raw Normal View History

2021-01-07 23:30:28 +00:00
local event = require("event")
local keyboard = require("keyboard")
local component = require("component")
2021-01-08 00:04:54 +00:00
local fs = require("filesystem")
2021-01-07 23:30:28 +00:00
local tunnel = component.tunnel
2021-01-08 01:09:46 +00:00
local success = "команда выполнена успешно"
local fail = "неизвестная команда - пиши help"
2021-01-08 00:08:54 +00:00
function os.dateRL(format)
if not fs.get("/").isReadOnly() then
local time = io.open("/tmp/.time", "w")
2021-01-08 01:09:46 +00:00
time:write()
time:close()
os.sleep(0.01)
return os.date(format, fs.lastModified("/tmp/.time") / 1002.7)
2021-01-08 00:08:54 +00:00
else
return os.date(format)
end
2021-01-08 00:04:54 +00:00
end
2021-01-08 01:09:46 +00:00
function handleMessage(msg)
if message == "help" then
return success
2021-01-08 01:10:53 +00:00
elseif message == "rain" then
2021-01-08 01:09:46 +00:00
return success
else
return fail
end
end
2021-01-07 23:30:28 +00:00
while true do
2021-01-08 01:09:46 +00:00
local _, _, from, _, _, message = event.pull("modem_message")
local log = "["..os.dateRL("%x %X").."]".." "..from..": "..message.."/n"..handleMessage(message)
2021-01-08 00:35:28 +00:00
print(log)
2021-01-08 00:40:24 +00:00
local f = io.open("logs.txt", "a")
2021-01-08 01:09:46 +00:00
f:write(log.."/n")
2021-01-08 00:35:28 +00:00
f:close()
2021-01-07 23:30:28 +00:00
tunnel.send("succes!")
end