Basic cron version
This commit is contained in:
parent
198f700f86
commit
8b04aefd45
20
bot/bot.lua
20
bot/bot.lua
@ -59,6 +59,7 @@ function do_action(msg)
|
|||||||
matches = { string.match(text, pattern) }
|
matches = { string.match(text, pattern) }
|
||||||
if matches[1] then
|
if matches[1] then
|
||||||
print(" matches",pattern)
|
print(" matches",pattern)
|
||||||
|
if desc.run ~= nil then
|
||||||
result = desc.run(msg, matches)
|
result = desc.run(msg, matches)
|
||||||
print(" sending", result)
|
print(" sending", result)
|
||||||
if (result) then
|
if (result) then
|
||||||
@ -69,6 +70,7 @@ function do_action(msg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- If text is longer than 4096 chars, send multiple msg.
|
-- If text is longer than 4096 chars, send multiple msg.
|
||||||
-- https://core.telegram.org/method/messages.sendMessage
|
-- https://core.telegram.org/method/messages.sendMessage
|
||||||
@ -182,6 +184,10 @@ end
|
|||||||
|
|
||||||
function on_binlog_replay_end ()
|
function on_binlog_replay_end ()
|
||||||
started = 1
|
started = 1
|
||||||
|
load_plugins()
|
||||||
|
-- Uncomment the line to enable cron plugins.
|
||||||
|
-- cron_plugins()
|
||||||
|
-- See plugins/ping.lua as an example for cron
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Start and load values
|
-- Start and load values
|
||||||
@ -195,7 +201,6 @@ plugins = {}
|
|||||||
|
|
||||||
-- load all plugins in the plugins/ directory
|
-- load all plugins in the plugins/ directory
|
||||||
function load_plugins()
|
function load_plugins()
|
||||||
plugins = {}
|
|
||||||
for k, v in pairs(scandir("plugins")) do
|
for k, v in pairs(scandir("plugins")) do
|
||||||
-- Load only lua files
|
-- Load only lua files
|
||||||
if (v:match(".lua$")) then
|
if (v:match(".lua$")) then
|
||||||
@ -206,5 +211,16 @@ function load_plugins()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
load_plugins()
|
-- Cron all the enabled plugins
|
||||||
|
function cron_plugins()
|
||||||
|
|
||||||
|
for name, desc in pairs(plugins) do
|
||||||
|
if desc.cron ~= nil then
|
||||||
|
print("croned!"..desc.description)
|
||||||
|
desc.cron()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Called again in 5 mins
|
||||||
|
postpone (cron_plugins, false, 5*60.0)
|
||||||
|
end
|
@ -1,12 +1,21 @@
|
|||||||
function run(msg, matches)
|
socket = require("socket")
|
||||||
local receiver = get_receiver(msg)
|
|
||||||
print('receiver: '..receiver)
|
function cron()
|
||||||
return "pong"
|
-- Checks a TCP connexion
|
||||||
|
-- Use yours desired web and id
|
||||||
|
local addr = "your.web.site"
|
||||||
|
local dest = "user#id"..our_id
|
||||||
|
if not socket.connect(addr, 80) then
|
||||||
|
local text = "ALERT: "..addr.." is offline"
|
||||||
|
print (text)
|
||||||
|
send_msg(dest, text, ok_cb, false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "bot sends pong",
|
description = "If domain is offline, send msg to peer",
|
||||||
usage = "!ping",
|
usage = "",
|
||||||
patterns = {"^!ping$"},
|
patterns = {},
|
||||||
run = run
|
run = nil,
|
||||||
|
cron = cron
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user