Start after on_binlog_replay_end. Check msg.service. Updated version

This commit is contained in:
Akamaru 2015-04-19 20:12:54 +02:00
parent 94d7d20415
commit c58d9117d4

View File

@ -4,7 +4,13 @@ VERSION = '2.5-reloaded'
-- This function is called when tg receive a msg -- This function is called when tg receive a msg
function on_msg_receive (msg) function on_msg_receive (msg)
if not started then
return
end
local receiver = get_receiver(msg) local receiver = get_receiver(msg)
-- vardump(msg) -- vardump(msg)
if msg_valid(msg) then if msg_valid(msg) then
msg = pre_process_msg(msg) msg = pre_process_msg(msg)
@ -17,7 +23,7 @@ function ok_cb(extra, success, result)
end end
function on_binlog_replay_end() function on_binlog_replay_end()
started = 1 started = true
postpone (cron_plugins, false, 60*5.0) postpone (cron_plugins, false, 60*5.0)
-- See plugins/ping.lua as an example for cron -- See plugins/ping.lua as an example for cron
@ -31,18 +37,23 @@ end
function msg_valid(msg) function msg_valid(msg)
-- Dont process outgoing messages -- Dont process outgoing messages
if msg.out then if msg.out then
print("Not valid, msg from us") print("Not valid: msg from us")
return false return false
end end
-- Before bot was started -- Before bot was started
if msg.date < now then if msg.date < now then
print("Not valid, old msg") print("Not valid: old msg")
return false return false
end end
if msg.unread == 0 then if msg.unread == 0 then
print("Not valid, readed") print("Not valid: readed")
return false
end
if msg.service then
print("Not valid: service")
return false return false
end end
@ -222,3 +233,4 @@ end
our_id = 0 our_id = 0
now = os.time() now = os.time()
math.randomseed(now) math.randomseed(now)
started = false