LuaScripts/linkedGet.lua
2021-01-08 19:50:11 +03:00

57 lines
1.5 KiB
Lua

local event = require("event")
local keyboard = require("keyboard")
local component = require("component")
local internet = require("internet")
local tunnel = component.tunnel
local success = "console: команда выполнена успешно"
local erius = "b7585fb7-1ea4-4f94-b1a2-05e1cef76a1f"
local DummyWalrus = "0952a2dd-23fa-4dd2-aefe-92e7cd6c77ce"
function getTime()
local handle = internet.request("http://api.timezonedb.com/v2.1/get-time-zone?key=INWE0H77BDN6&by=zone&zone=Europe/Moscow&format=json")
local result = ""
for chunk in handle do
result = result..chunk
end
local f = io.open("time.txt", "w")
f:write(result)
f:close()
f = io.open("time.txt", "r")
f:seek("set", 245)
local time = f:read(19)
f:close()
return time
end
function handleMessage(msg)
if msg == "help" or msg == "exit" or msg == "near" or msg == "update" then
return success
elseif msg == "rain" then
return success
end
return nil
end
function getUser(from)
if from == erius then
return "erius"
elseif from == DummyWalrus then
return "DummyWalrus"
else
return "???"
end
end
while true do
local _, _, from, _, _, message = event.pull("modem_message")
local result = handleMessage(tostring(message))
local time = getTime()
local user = getUser(tostring(from))
local log = "["..time.."] "..user..": "..message.."\n".."["..time.."] "..result
print(log)
local f = io.open("logs.txt", "a")
f:write(log.."\n")
f:close()
end