66
|
1 |
|
|
2 |
local lm = require 'lm' |
|
3 |
local pubsub = require 'pubsub' |
|
4 |
local avatar = require 'avatar' |
|
5 |
|
|
6 |
pubsub.handler ( 'urn:xmpp:avatar:metadata', |
|
7 |
function ( from, node, data, id ) |
|
8 |
if not main.yesno ( main.option ( 'lua_pep_notification' ) ) then |
|
9 |
return true |
|
10 |
end |
|
11 |
local item = data:child () |
|
12 |
while item do |
|
13 |
main.print_info ( from, ('Avatar: %s [%s] %s bytes, %sx%s %s'):format ( |
|
14 |
item:attribute ( 'id' ), |
|
15 |
item:attribute ( 'type' ), |
|
16 |
item:attribute ( 'bytes' ), |
|
17 |
item:attribute ( 'width' ) or '?', |
|
18 |
item:attribute ( 'height' ) or '?', |
|
19 |
item:attribute ( 'url' ) or '' ) ) |
|
20 |
item = item:next () |
|
21 |
end |
|
22 |
end ) |
|
23 |
|
|
24 |
main.command ( 'avatar', |
|
25 |
function ( args ) |
|
26 |
local action = args[1] |
|
27 |
if action == 'get' then |
|
28 |
local who |
|
29 |
if args.t then |
|
30 |
who = args.t |
|
31 |
else |
|
32 |
who = main.current_buddy () |
|
33 |
end |
|
34 |
avatar.get ( lm.connection.bless ( main.connection () ), who, args[2], |
|
35 |
function ( data ) |
|
36 |
local h = io.open ( args[3], 'w' ) |
|
37 |
if h then |
|
38 |
h:write ( data ) |
|
39 |
h:close () |
|
40 |
main.print_info ( who, 'Avatar saved to ' .. args[3] ) |
|
41 |
else |
|
42 |
print ( 'Cannot open file for writing ' .. args[3] ) |
|
43 |
end |
|
44 |
end, |
|
45 |
function ( mesg ) |
|
46 |
main.print_info ( who, 'Error obtaining avatar: ' .. mesg ) |
|
47 |
end ) |
|
48 |
else |
|
49 |
local file = action |
|
50 |
if action == 'set' then |
|
51 |
file = args[2] |
|
52 |
end |
|
53 |
local h = io.open ( file ) |
|
54 |
if h then |
|
55 |
data = h:read ( '*a' ) |
|
56 |
h:close () |
|
57 |
avatar.publish ( lm.connection.bless ( main.connection () ), data, |
|
58 |
function () |
|
59 |
print ( 'Avatar published' ) |
|
60 |
end, |
|
61 |
function ( mesg ) |
|
62 |
print ( 'Avatar publishing error: ' .. mesg ) |
|
63 |
end ) |
|
64 |
else |
|
65 |
print ( 'Cannot open file ' .. file ) |
|
66 |
end |
|
67 |
end |
|
68 |
end, true, 'file' ) |
|
69 |
|
|
70 |
commands_help['avatar'] = '[-t jid] get id filename | [set] filename\n\nGet action tries to get from server avatar with specified id and save it to \'filename\'.\nSet action publishes avatar to server. File must be a PNG image.' |
|
71 |
|
|
72 |
main.add_feature ( 'urn:xmpp:avatar:metadata+notify' ) |
|
73 |
|
|
74 |
-- vim: se ts=4: -- |