author | Myhailo Danylenko <isbear@ukrpost.net> |
Wed, 07 Apr 2010 21:40:52 +0300 | |
changeset 107 | 1ed8491ae1b4 |
parent 99 | ed4676536ed9 |
permissions | -rw-r--r-- |
58
aa3376776cf2
Cosmetic comment changes
Myhailo Danylenko <isbear@ukrpost.net>
parents:
34
diff
changeset
|
1 |
|
8 | 2 |
--- JOBS |
3 |
||
4 |
delayed_jobs = {} |
|
5 |
||
6 |
-- may fail |
|
33 | 7 |
dofile ( main.fileoption 'lua_jobs_file' ) |
8 | 8 |
|
9 |
function save_jobs () |
|
33 | 10 |
local h = io.open ( main.fileoption 'lua_jobs_file', "w" ) |
8 | 11 |
if not h then |
12 |
print ( 'Cannot open jobs file for writing!' ) |
|
13 |
return |
|
14 |
end |
|
15 |
h:write ( "-- This is autogenerated file, do not edit it manually\n\ndelayed_jobs = {\n" ); |
|
16 |
for jid, more in pairs ( delayed_jobs ) do |
|
17 |
h:write ( string.format ( "\t[%q] = {\n", jid ) ) |
|
18 |
for status, action in pairs ( more ) do |
|
19 |
if action then -- remove fired jobs |
|
20 |
h:write ( string.format ( "\t\t[%q] = %q,\n", status, action ) ) |
|
21 |
end |
|
22 |
end |
|
23 |
h:write ( "\t},\n" ) |
|
24 |
end |
|
25 |
h:write ( "}\n" ) |
|
26 |
h:close () |
|
27 |
end |
|
28 |
||
29 |
main.command ( 'delay', |
|
30 |
function ( args ) |
|
31 |
local who |
|
32 |
if args.t then |
|
33 |
who = args.t |
|
34 |
else |
|
35 |
who = main.current_buddy () |
|
36 |
end |
|
37 |
local stat = args[1] |
|
24 | 38 |
local mess = args[2] |
8 | 39 |
delayed_jobs[who] = { } |
24 | 40 |
delayed_jobs[who][stat] = 'say_to -q ' .. who .. ' ' .. mess |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
41 |
end, true ) |
8 | 42 |
|
43 |
main.command ( 'job', |
|
44 |
function ( args ) |
|
24 | 45 |
local action, jid, stat = args[1], args[2], args[3] |
8 | 46 |
if action == 'del' then |
47 |
delayed_jobs[jid][stat] = nil |
|
48 |
else |
|
24 | 49 |
local text = '' |
8 | 50 |
for jid, jobs in pairs ( delayed_jobs ) do |
51 |
for status, job in pairs ( jobs ) do |
|
24 | 52 |
text = text .. '\n - ' .. jid .. ' -> ' .. status .. ': ' .. job |
8 | 53 |
end |
54 |
end |
|
24 | 55 |
if text ~= '' then |
56 |
print ( 'List of jobs:' .. text ) |
|
57 |
else |
|
58 |
print ( 'No jobs' ) |
|
59 |
end |
|
8 | 60 |
end |
34
8206d7cb1447
Args auto-parsing, use main.binding
Myhailo Danylenko <isbear@ukrpost.net>
parents:
33
diff
changeset
|
61 |
end, true, { "del" } ) |
8 | 62 |
|
63 |
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." |
|
64 |
commands_help['job'] = "[del jid status_letter]\n\nLists available jobs or deletes specified one." |
|
65 |
||
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
58
diff
changeset
|
66 |
main.hook ( 'hook-status-change', |
8 | 67 |
function ( args ) |
68 |
if delayed_jobs[args.jid] and delayed_jobs[args.jid][args.new_status] then |
|
69 |
main.run ( delayed_jobs[args.jid][args.new_status] ) |
|
70 |
delayed_jobs[args.jid][args.new_status] = nil |
|
71 |
end |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
58
diff
changeset
|
72 |
end ) |
8 | 73 |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
58
diff
changeset
|
74 |
main.hook ( 'hook-lua-quit', save_jobs ) |
8 | 75 |
|
99
ed4676536ed9
Update most useful scripts
Myhailo Danylenko <isbear@ukrpost.net>
parents:
58
diff
changeset
|
76 |
-- vim: se ts=4 sw=4: -- |