61 lines
1.3 KiB
Lua
61 lines
1.3 KiB
Lua
local fs = require "lfs"
|
|
local http = require "http"
|
|
local json = require "json"
|
|
local telegram = require "telegram"
|
|
local yaml = require "yaml"
|
|
|
|
function restore()
|
|
local fin = io.open("var/data.json", "r")
|
|
local data, err = json.decode(fin:read("*a"))
|
|
if err ~= nil then
|
|
print("cannot load data: " .. err)
|
|
return
|
|
end
|
|
|
|
vars = data
|
|
end
|
|
|
|
function save()
|
|
local fout = io.open("var/data.json", "w")
|
|
local data = json.encode(vars)
|
|
fout:write(data)
|
|
fout:write("\n")
|
|
fout:close()
|
|
end
|
|
|
|
function main()
|
|
restore()
|
|
|
|
if vars == nil then
|
|
vars = {}
|
|
end
|
|
|
|
if vars.lastowotime == nil then
|
|
vars.lastowotime = 0
|
|
end
|
|
|
|
if vars.tolearnfrom == nil then
|
|
vars.tolearnfrom = {} -- array of id's of people
|
|
end
|
|
|
|
while true do
|
|
local update = tgupdates:receive()
|
|
|
|
if update ~= nil and update.message ~= nil then
|
|
local chatid = update.message.chat.ID
|
|
local userid = tostring(update.message.from.ID)
|
|
local text = update.message.text
|
|
|
|
if string.find(string.lower(text), "notices") and math.random(100) % 15 == 0 then
|
|
if vars.lastowotime + 600 < os.time() then
|
|
local msg = telegram.newMessage(chatid, "owo what's this?")
|
|
tg:send(msg)
|
|
|
|
vars.lastowotime = os.time()
|
|
end
|
|
end
|
|
end
|
|
save()
|
|
end
|
|
end
|