23 attention = { xmlns = 'urn:xmpp:attention:0' }, |
25 attention = { xmlns = 'urn:xmpp:attention:0' }, |
24 body = body, |
26 body = body, |
25 } ) |
27 } ) |
26 end |
28 end |
27 |
29 |
28 -- private |
30 function F.handler ( handler ) |
|
31 O.handler = handler |
|
32 end |
29 |
33 |
30 local attention_incoming_message_handler = lm.message_handler.new ( |
34 function F.message_handler ( conn, mess ) |
31 function ( conn, mess ) |
35 local a = mess:child ( 'attention' ) |
32 local a = mess:child ( 'attention' ) |
36 if a and a:attribute ( 'xmlns' ) == 'urn:xmpp:attention:0' then |
33 if a and a:attribute ( 'xmlns' ) == 'urn:xmpp:attention:0' then |
37 local body = mess:child ( 'body' ) |
34 local body = mess:child ( 'body' ) |
38 if body then |
35 if body then |
39 body = body:value () |
36 body = body:value () |
|
37 end |
|
38 attention.handler ( body ) |
|
39 end |
40 end |
40 return false |
41 O.handler ( body ) |
41 end ) |
42 end |
|
43 return false |
|
44 end |
42 |
45 |
43 -- mcabber |
46 return F |
44 |
|
45 attention.handler = |
|
46 function ( mesg ) |
|
47 local times = 0 |
|
48 main.timer ( 1, |
|
49 function () |
|
50 if times < 6 then |
|
51 main.beep () |
|
52 times = times + 1 |
|
53 return true |
|
54 end |
|
55 return false |
|
56 end ) |
|
57 end |
|
58 |
|
59 main.command ( 'attention', |
|
60 function ( args ) |
|
61 local who |
|
62 if args.t then |
|
63 who = args.t |
|
64 else |
|
65 who = main.full_jid () |
|
66 end |
|
67 attention.send ( lm.connection.bless ( main.connection () ), who, args[1] ) |
|
68 end, true, 'jid' ) |
|
69 |
|
70 commands_help['attention'] = "[-t to] [message]\n\nTries to get buddy's attention." |
|
71 |
|
72 local attention_handler_registered = false |
|
73 |
|
74 hooks_d['hook-post-connect'].attention = |
|
75 function ( args ) |
|
76 lm.connection.bless( main.connection () ):handler ( attention_incoming_message_handler, 'message', 'normal' ) |
|
77 attention_handler_registered = true |
|
78 hooks_d['hook-post-connect'].attention = nil |
|
79 hooks_d['hook-quit'].attention = |
|
80 function ( args ) |
|
81 if attention_handler_registered then |
|
82 lm.connection.bless( main.connection () ):handler ( attention_incoming_message_handler, 'message' ) |
|
83 end |
|
84 end |
|
85 end |
|
86 |
|
87 main.add_feature ( 'urn:xmpp:attention:0' ) |
|
88 |
47 |
89 -- vim: se ts=4: -- |
48 -- vim: se ts=4: -- |