LuaScripts/linkedGet.lua

46 lines
1.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")
local tunnel = component.tunnel
2021-01-08 01:09:46 +00:00
2021-01-08 01:44:49 +00:00
local success = "console: команда выполнена успешно"
local fail = "console: неизвестная команда - пиши help"
2021-01-08 01:09:46 +00:00
2021-01-08 14:09:44 +00:00
function getTime()
local _, _, _, _, _, time = event.pull("modem_message")
return time
2021-01-08 00:04:54 +00:00
end
2021-01-08 01:09:46 +00:00
function handleMessage(msg)
2021-01-08 01:24:12 +00:00
if msg == "help" then
2021-01-08 01:09:46 +00:00
return success
2021-01-08 01:24:12 +00:00
elseif msg == "rain" then
2021-01-08 01:09:46 +00:00
return success
else
return fail
end
end
2021-01-08 01:24:12 +00:00
function getUser(from)
2021-01-08 01:49:59 +00:00
if from == "b7585fb7-1ea4-4f94-b1a2-05e1cef76a1f" then
2021-01-08 01:24:12 +00:00
return "erius"
elseif from == "0952a2dd-23fa-4dd2-aefe-92e7cd6c77ce" then
return "DummyWalrus"
else
return "???"
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")
2021-01-08 01:46:09 +00:00
local answer = handleMessage(tostring(message))
2021-01-08 14:09:44 +00:00
local time = getTime()
local user = getUser(tostring(from))
local log = "["..time.."] "..user..": "..message.."\n".."["..time.."] "..answer
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:24:12 +00:00
f:write(log.."\n")
2021-01-08 00:35:28 +00:00
f:close()
2021-01-08 01:44:49 +00:00
tunnel.send(answer)
2021-01-07 23:30:28 +00:00
end