gMaps.lua -> location.lua

Also moved some stuff from where it shouldn't be.
This commit is contained in:
topkecleon
2016-10-04 13:30:22 -04:00
parent 9f760114bd
commit 4e0d717adc
5 changed files with 33 additions and 28 deletions

View File

@@ -23,15 +23,19 @@ function gMaps:action(msg, config)
return
end
local coords = utilities.get_coords(input, config)
if type(coords) == 'string' then
utilities.send_reply(msg, coords)
local lat, lon = utilities.get_coords(input)
if lat == nil then
utilities.send_reply(msg, config.errors.connection)
return
elseif lat == false then
utilities.send_reply(msg, config.errors.results)
return
end
bindings.sendLocation{
chat_id = msg.chat.id,
latitude = coords.lat,
longitude = coords.lon,
latitude = lat,
longitude = lon,
reply_to_message_id = msg.message_id
}
end

View File

@@ -20,15 +20,18 @@ function time:action(msg, config)
return
end
local coords = utilities.get_coords(input, config)
if type(coords) == 'string' then
utilities.send_reply(msg, coords)
local lat, lon = utilities.get_coords(input)
if lat == nil then
utilities.send_reply(msg, config.errors.connection)
return
elseif lat == false then
utilities.send_reply(msg, config.errors.results)
return
end
local now = os.time()
local utc = os.time(os.date('!*t', now))
local url = time.base_url:format(coords.lat, coords.lon, utc)
local url = time.base_url:format(lat, lon, utc)
local jstr, code = HTTPS.request(url)
if code ~= 200 then
utilities.send_reply(msg, config.errors.connection)

View File

@@ -25,13 +25,16 @@ function weather:action(msg, config)
return
end
local coords = utilities.get_coords(input, config)
if type(coords) == 'string' then
utilities.send_reply(msg, coords)
local lat, lon = utilities.get_coords(input)
if lat == nil then
utilities.send_reply(msg, config.errors.connection)
return
elseif lat == false then
utilities.send_reply(msg, config.errors.results)
return
end
local url = 'http://api.openweathermap.org/data/2.5/weather?APPID=' .. config.owm_api_key .. '&lat=' .. coords.lat .. '&lon=' .. coords.lon
local url = 'http://api.openweathermap.org/data/2.5/weather?APPID=' .. config.owm_api_key .. '&lat=' .. lat .. '&lon=' .. lon
local jstr, res = HTTP.request(url)
if res ~= 200 then