66
|
1 |
|
|
2 |
local lm = require 'lm' |
|
3 |
local oob = require 'oob' |
|
4 |
|
|
5 |
oob.handler ( |
|
6 |
function ( from, url, desc, success, fail ) |
|
7 |
if desc then |
|
8 |
main.print_info ( from, 'Buddy wants you to download link: ' .. url .. ' (' .. desc .. ')' ) |
|
9 |
else |
|
10 |
main.print_info ( from, 'Buddy wants you to download link: ' .. url ) |
|
11 |
end |
|
12 |
success () |
|
13 |
end ) |
|
14 |
|
|
15 |
main.command ( 'oob', |
|
16 |
function ( args ) |
|
17 |
local who |
|
18 |
if args.t then |
|
19 |
who = args.t |
|
20 |
else |
|
21 |
who = main.full_jid () |
|
22 |
end |
|
23 |
-- here we can run something external to put file on server and obtain link to it |
|
24 |
oob.send ( lm.connection.bless ( main.connection () ), who, args[1], |
|
25 |
function () |
|
26 |
main.print_info ( who, 'OOB link accepted' ) |
|
27 |
end, |
|
28 |
function ( mesg ) |
|
29 |
main.print_info ( who, 'OOB link refused: ' .. mesg ) |
|
30 |
end, args[2] ) |
|
31 |
end, true ) |
|
32 |
|
|
33 |
local oob_iq_handler = lm.message_handler.new ( oob.iq_handler ) |
|
34 |
local oob_message_handler = lm.message_handler.new ( oob.message_handler ) |
|
35 |
local oob_handler_registered = false |
|
36 |
|
|
37 |
hooks_d['hook-post-connect'].oob = |
|
38 |
function ( args ) |
|
39 |
local conn = lm.connection.bless ( main.connection () ) |
|
40 |
conn:handler ( oob_iq_handler, 'iq', 'normal' ) |
|
41 |
conn:handler ( oob_message_handler, 'message', 'normal' ) |
|
42 |
conn:handler ( oob_message_handler, 'presence', 'normal' ) |
|
43 |
oob_handler_registered = true |
|
44 |
hooks_d['hook-post-connect'].oob = nil |
|
45 |
hooks_d['hook-quit'].oob = |
|
46 |
function ( args ) |
|
47 |
if oob_handler_registered then |
|
48 |
local conn = lm.connection.bless ( main.connection () ) |
|
49 |
conn:handler ( oob_iq_handler, 'iq' ) |
|
50 |
conn:handler ( oob_message_handler, 'message' ) |
|
51 |
conn:handler ( oob_message_handler, 'presence' ) |
|
52 |
end |
|
53 |
end |
|
54 |
end |
|
55 |
|
|
56 |
main.add_feature ( 'jabber:iq:oob' ) |
|
57 |
main.add_feature ( 'jabber:x:oob' ) |
|
58 |
|
|
59 |
-- vim: se ts=4: -- |