examples/mc_mood.lua
changeset 68 742878c74b8e
parent 67 d33ca5572e91
child 69 ab6d4ee8974c
equal deleted inserted replaced
67:d33ca5572e91 68:742878c74b8e
     1 
       
     2 local lm     = require 'lm'
       
     3 local mood   = require 'mood'
       
     4 local pubsub = require 'pubsub'
       
     5 
       
     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 )
       
    28 
       
    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 )
       
    39 
       
    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."
       
    41 
       
    42 main.add_feature ( 'http://jabber.org/protocol/mood+notify' )
       
    43 main.add_feature ( 'http://jabber.org/protocol/mood' )
       
    44 
       
    45 -- vim: se ts=4: --