This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/plugins/gMaps.lua
topkecleon 42cda22ab6 much improved personality.lua interactions
partial localization support
2015-07-11 04:31:29 -04:00

41 lines
823 B
Lua

local PLUGIN = {}
PLUGIN.doc = [[
/loc <location>
Sends location data for query, taken from Google Maps. Works for countries, cities, landmarks, etc.
]]
PLUGIN.triggers = {
'^/loc'
}
function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
end
local url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input)
local jstr, res = HTTP.request(url)
if res ~= 200 then
return send_msg(msg, locale.conn_err)
end
local jdat = JSON.decode(jstr)
if jdat.status ~= 'OK' then
local message = locale.noresults
return send_msg(msg, message)
end
local lat = jdat.results[1].geometry.location.lat
local lng = jdat.results[1].geometry.location.lng
send_location(msg.chat.id, lat, lng, msg.message_id)
end
return PLUGIN