66
|
1 |
|
|
2 |
local lm = require 'lm' |
|
3 |
local activity = require 'activity' |
|
4 |
local pubsub = require 'pubsub' |
|
5 |
|
|
6 |
pubsub.handler ( 'http://jabber.org/protocol/activity', |
|
7 |
function ( from, node, data ) |
|
8 |
if not main.yesno ( main.option ( 'lua_pep_notification' ) ) then |
|
9 |
return true |
|
10 |
end |
|
11 |
local item = data:child () |
|
12 |
local activity, desc |
|
13 |
while item do |
|
14 |
if item:name () == 'text' then |
|
15 |
desc = item:value () |
|
16 |
else |
|
17 |
activity = item:name () |
|
18 |
local subitem = item:child () |
|
19 |
if subitem then |
|
20 |
-- here we can check for non-standard subactivity elements, |
|
21 |
-- add subactivity child elements handling |
|
22 |
activity = ("%s: %s"):format ( activity, subitem:name () ) |
|
23 |
end |
|
24 |
end |
|
25 |
item = item:next () |
|
26 |
end |
|
27 |
if activity then |
|
28 |
main.print_info ( from, ("Now %s %s"):format ( activity, desc or '' ) ) |
|
29 |
else |
|
30 |
main.print_info ( from, "Buddy hides his activity" ) |
|
31 |
end |
|
32 |
return true |
|
33 |
end ) |
|
34 |
|
|
35 |
main.command ( 'activity', |
|
36 |
function ( args ) |
|
37 |
local a, text = args[1], args[2] |
|
38 |
local act, subact = a:match ( "(.-)%-(.+)" ) |
|
39 |
if not act then |
|
40 |
act = a |
|
41 |
end |
|
42 |
activity.publish ( lm.connection.bless ( main.connection () ), |
|
43 |
function () |
|
44 |
print ( 'Activity published' ) |
|
45 |
end, |
|
46 |
function ( mesg ) |
|
47 |
print ( 'Error publishing activity: ' .. mesg ) |
|
48 |
end, act, subact, text ) |
|
49 |
end, true ) |
|
50 |
|
|
51 |
commands_help['activity'] = "[activity[-specific_activity] [text]]\n\nPublishes your activity.\nNote, that for now it does not checks for activity validity, so, see xep0108 for valid activity values." |
|
52 |
|
|
53 |
main.add_feature ( 'http://jabber.org/protocol/activity+notify' ) |
|
54 |
main.add_feature ( 'http://jabber.org/protocol/activity' ) |
|
55 |
|
|
56 |
-- vim: se ts=4: -- |