Completion
* commands completion
* common hooks lua interface
* complete separation of features into modules
--- JOBS
delayed_jobs = {}
-- may fail
dopath 'saved_jobs.lua'
function save_jobs ()
local h = io.open ( main.config_file ( 'saved_jobs.lua' ), "w" )
if not h then
print ( 'Cannot open jobs file for writing!' )
return
end
h:write ( "-- This is autogenerated file, do not edit it manually\n\ndelayed_jobs = {\n" );
for jid, more in pairs ( delayed_jobs ) do
h:write ( string.format ( "\t[%q] = {\n", jid ) )
for status, action in pairs ( more ) do
if action then -- remove fired jobs
h:write ( string.format ( "\t\t[%q] = %q,\n", status, action ) )
end
end
h:write ( "\t},\n" )
end
h:write ( "}\n" )
h:close ()
end
main.command ( 'delay',
function ( args )
args = parse_args ( args )
local who
if args.t then
who = args.t
args.t = nil
else
who = main.current_buddy ()
end
local stat = args[1]
args[1] = nil
delayed_jobs[who] = { }
delayed_jobs[who][stat] = 'say_to -q ' .. who .. ' ' .. rebuild_args_string ( args )
end )
main.command ( 'job',
function ( args )
local action, jid, stat = args:match ( "(%w+)%s+(%w+)%s+(%w)" )
if action == 'del' then
delayed_jobs[jid][stat] = nil
else
print ( 'List of jobs:' )
for jid, jobs in pairs ( delayed_jobs ) do
for status, job in pairs ( jobs ) do
print ( ' - ' .. jid .. ' -> ' .. status .. ': ' .. job )
end
end
end
end, { "del" } )
commands_help['delay'] = "[-t target_jid] status_letter message\n\nDelays sending a message to target jid (or current buddy) until it switches to specified status."
commands_help['job'] = "[del jid status_letter]\n\nLists available jobs or deletes specified one."
hooks_d['hook-status-change'].jobs =
function ( args )
if delayed_jobs[args.jid] and delayed_jobs[args.jid][args.new_status] then
main.run ( delayed_jobs[args.jid][args.new_status] )
delayed_jobs[args.jid][args.new_status] = nil
end
end
hooks_d['hook-quit'].jobs = save_jobs
-- vim: se ts=4: --