examples/mood.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 28 Nov 2012 20:17:53 +0200
changeset 146 04d19c9c1196
parent 68 742878c74b8e
permissions -rw-r--r--
Fix module loading problem


local lm     = require 'lm'
local mood   = require 'lm.mood'
local pubsub = require 'lm.pubsub'

pubsub.handler ( 'http://jabber.org/protocol/mood',
	function ( from, node, data )
		if not main.yesno ( main.option ( 'lua_pep_notification' ) ) then
			return true
		end
		local item = data:child ()
		local mood, desc
		while item do
			if item:name () == 'text' then
				desc = item:value ()
			else
				mood = item:name ()
				-- here we can add child elements handling (by namespace)
			end
			item = item:next ()
		end
		if mood then
			main.print_info ( from, ("Buddy's mood now %s %s"):format ( mood, desc or '' ) )
		else
			main.print_info ( from, "Buddy hides his mood" )
		end
	end )

main.command ( 'mood',
	function ( args )
		mood.publish ( lm.connection.bless ( main.connection () ),
			function ()
				print ( 'Mood published' )
			end,
			function ( mesg )
				print ( 'Error publishing mood: ' .. mesg )
			end, args[1], args[2] )
	end, true )

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."

main.add_feature ( 'http://jabber.org/protocol/mood+notify' )
main.add_feature ( 'http://jabber.org/protocol/mood' )

-- vim: se ts=4: --