59
|
1 |
|
|
2 |
-- USER LOCATION (XEP-0080) |
|
3 |
|
|
4 |
-- library |
|
5 |
|
|
6 |
require 'lm' |
|
7 |
require 'pep' |
|
8 |
|
|
9 |
-- public |
|
10 |
|
|
11 |
geoloc = { } |
|
12 |
|
|
13 |
function geoloc.publish ( conn, success, fail, data ) |
|
14 |
local sdata = { xmlns = 'http://jabber.org/protocol/geoloc' } |
|
15 |
if data then |
|
16 |
for key, value in pairs ( data ) do |
|
17 |
sdata[key] = { value } |
|
18 |
end |
|
19 |
end |
|
20 |
pep.publish ( conn, 'http://jabber.org/protocol/geoloc', { geoloc = sdata }, success, fail ) |
|
21 |
end |
|
22 |
|
|
23 |
-- mcabber |
|
24 |
|
|
25 |
pep.handlers['http://jabber.org/protocol/geoloc'] = |
|
26 |
function ( from, node, data ) |
|
27 |
if not main.yesno ( main.option ( 'lua_pep_notification' ) ) then |
|
28 |
return true |
|
29 |
end |
|
30 |
local item = data:children () |
|
31 |
local text = '' |
|
32 |
while item do |
|
33 |
text = ("%s\n- %s: %s"):format ( text, item:name (), item:value () or '' ) |
|
34 |
item = item:next () |
|
35 |
end |
|
36 |
if text ~= '' then |
|
37 |
text = 'Now at:' .. text |
|
38 |
else |
|
39 |
text = 'Now in unknown location' |
|
40 |
end |
|
41 |
main.print_info ( from, text ) |
|
42 |
return true |
|
43 |
end |
|
44 |
|
|
45 |
main.command ( 'location', |
|
46 |
function ( args ) |
|
47 |
geoloc.publish ( lm.connection.bless ( main.connection () ), |
|
48 |
function () |
|
49 |
print ( 'Geolocation published' ) |
|
50 |
end, |
|
51 |
function ( mesg ) |
|
52 |
print ( 'Error geolocation publishing: ' .. mesg ) |
|
53 |
end, args ) |
|
54 |
end, true ) |
|
55 |
|
|
56 |
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." |
|
57 |
|
|
58 |
main.add_feature ( 'http://jabber.org/protocol/geoloc+notify' ) |
|
59 |
main.add_feature ( 'http://jabber.org/protocol/geoloc' ) |
|
60 |
|
|
61 |
-- vim: se ts=4: -- |