50
|
1 |
|
|
2 |
-- ATTENTION (XEP-0224) |
|
3 |
|
|
4 |
-- library |
|
5 |
|
|
6 |
require 'lm' |
|
7 |
|
|
8 |
-- public |
|
9 |
|
|
10 |
attention = { |
|
11 |
handler = |
|
12 |
function ( mesg ) |
|
13 |
end, |
|
14 |
} |
|
15 |
|
|
16 |
function attention.send ( conn, to, message ) |
|
17 |
local body = nil |
|
18 |
if message then |
|
19 |
body = { message } |
|
20 |
end |
|
21 |
conn:send ( |
|
22 |
lm.message.create { mtype = 'message-headline', to = to, |
|
23 |
attention = { xmlns = 'urn:xmpp:attention:0' }, |
|
24 |
body = body, |
|
25 |
} ) |
|
26 |
end |
|
27 |
|
|
28 |
-- private |
|
29 |
|
|
30 |
local attention_incoming_message_handler = lm.message_handler.new ( |
|
31 |
function ( conn, mess ) |
|
32 |
local a = mess:child ( 'attention' ) |
|
33 |
if a and a:attribute ( 'xmlns' ) == 'urn:xmpp:attention:0' then |
|
34 |
local body = mess:child ( 'body' ) |
|
35 |
if body then |
|
36 |
body = body:value () |
|
37 |
end |
|
38 |
attention.handler ( body ) |
|
39 |
end |
|
40 |
return false |
|
41 |
end ) |
|
42 |
|
|
43 |
-- mcabber |
|
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 |
|
|
89 |
-- vim: se ts=4: -- |