examples/mc_geoloc.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 geoloc = require 'geoloc'
       
     4 local pubsub = require 'pubsub'
       
     5 
       
     6 pubsub.handler ( 'http://jabber.org/protocol/geoloc',
       
     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 text = ''
       
    13 		while item do
       
    14 			text = ("%s\n- %s: %s"):format ( text, item:name (), item:value () or '' )
       
    15 			item = item:next ()
       
    16 		end
       
    17 		if text ~= '' then
       
    18 			text = 'Now at:' .. text
       
    19 		else
       
    20 			text = 'Now in unknown location'
       
    21 		end
       
    22 		main.print_info ( from, text )
       
    23 		return true
       
    24 	end )
       
    25 
       
    26 main.command ( 'location',
       
    27 	function ( args )
       
    28 		geoloc.publish ( lm.connection.bless ( main.connection () ),
       
    29 			function ()
       
    30 				print ( 'Geolocation published' )
       
    31 			end,
       
    32 			function ( mesg )
       
    33 				print ( 'Error geolocation publishing: ' .. mesg )
       
    34 			end, args )
       
    35 	end, true )
       
    36 
       
    37 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."
       
    38 
       
    39 main.add_feature ( 'http://jabber.org/protocol/geoloc+notify' )
       
    40 main.add_feature ( 'http://jabber.org/protocol/geoloc' )
       
    41 
       
    42 -- vim: se ts=4: --