examples/mc_geoloc.lua
changeset 66 542f61e113cb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/mc_geoloc.lua	Fri Mar 27 12:06:19 2009 +0200
@@ -0,0 +1,42 @@
+
+local lm     = require 'lm'
+local geoloc = require 'geoloc'
+local pubsub = require 'pubsub'
+
+pubsub.handler ( 'http://jabber.org/protocol/geoloc',
+	function ( from, node, data )
+		if not main.yesno ( main.option ( 'lua_pep_notification' ) ) then
+			return true
+		end
+		local item = data:child ()
+		local text = ''
+		while item do
+			text = ("%s\n- %s: %s"):format ( text, item:name (), item:value () or '' )
+			item = item:next ()
+		end
+		if text ~= '' then
+			text = 'Now at:' .. text
+		else
+			text = 'Now in unknown location'
+		end
+		main.print_info ( from, text )
+		return true
+	end )
+
+main.command ( 'location',
+	function ( args )
+		geoloc.publish ( lm.connection.bless ( main.connection () ),
+			function ()
+				print ( 'Geolocation published' )
+			end,
+			function ( mesg )
+				print ( 'Error geolocation publishing: ' .. mesg )
+			end, args )
+	end, true )
+
+commands_help['location'] = "[-key value [-key value ...]]\n\nPublishes your current geolocation.\nValid keys are accuracy, alt, area, bearing, building, country, datum, description, error, floor, lat, locality, lon, postalcode, region, room, speed, street, text, timestamp and uri, according to xep0080."
+
+main.add_feature ( 'http://jabber.org/protocol/geoloc+notify' )
+main.add_feature ( 'http://jabber.org/protocol/geoloc' )
+
+-- vim: se ts=4: --