1 |
1 |
2 -- USER MOOD (XEP-0107) |
2 local lm = require 'lm' |
|
3 local mood = require 'lm.mood' |
|
4 local pubsub = require 'lm.pubsub' |
3 |
5 |
4 -- library |
6 pubsub.handler ( 'http://jabber.org/protocol/mood', |
|
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 mood, desc |
|
13 while item do |
|
14 if item:name () == 'text' then |
|
15 desc = item:value () |
|
16 else |
|
17 mood = item:name () |
|
18 -- here we can add child elements handling (by namespace) |
|
19 end |
|
20 item = item:next () |
|
21 end |
|
22 if mood then |
|
23 main.print_info ( from, ("Buddy's mood now %s %s"):format ( mood, desc or '' ) ) |
|
24 else |
|
25 main.print_info ( from, "Buddy hides his mood" ) |
|
26 end |
|
27 end ) |
5 |
28 |
6 local pep = require 'pep' |
29 main.command ( 'mood', |
|
30 function ( args ) |
|
31 mood.publish ( lm.connection.bless ( main.connection () ), |
|
32 function () |
|
33 print ( 'Mood published' ) |
|
34 end, |
|
35 function ( mesg ) |
|
36 print ( 'Error publishing mood: ' .. mesg ) |
|
37 end, args[1], args[2] ) |
|
38 end, true ) |
7 |
39 |
8 -- |
40 commands_help['mood'] = "[mood [message]]\n\nPublishes your mood.\nNote, that for now it does not checks for mood validity, so, see xep0107 for valid moods." |
9 |
41 |
10 local F = { } |
42 main.add_feature ( 'http://jabber.org/protocol/mood+notify' ) |
11 |
43 main.add_feature ( 'http://jabber.org/protocol/mood' ) |
12 function F.publish ( conn, success, fail, mood, message ) |
|
13 local item = { xmlns = 'http://jabber.org/protocol/mood' } |
|
14 if mood then |
|
15 item[mood] = { } |
|
16 end |
|
17 if message then |
|
18 item.text = { message } |
|
19 end |
|
20 pep.publish ( conn, 'http://jabber.org/protocol/mood', { mood = item }, success, fail ) |
|
21 end |
|
22 |
|
23 return F |
|
24 |
44 |
25 -- vim: se ts=4: -- |
45 -- vim: se ts=4: -- |