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/time.lua
topkecleon 60570e90f3 added cron jobs for plugins
added example plugin with documentation
added liberbot-compliant flood control
	see Liberbot Support for details on getting compliant
added Kickass Torrent plugin
various bugfixes
all files seem to have been marked changed due to a shift in platform
	I will do a clean clone and testing to ensure there is no issue.
2015-08-28 23:15:01 -07:00

49 lines
1.1 KiB
Lua
Executable File

-- time_offset is the number of seconds necessary to correct your system clock to UTC.
local PLUGIN = {}
PLUGIN.doc = [[
/time <location>
Sends the time and timezone for a given location.
]]
PLUGIN.triggers = {
'^/time'
}
function PLUGIN.action(msg)
local input = get_input(msg.text)
if not input then
return send_msg(msg, PLUGIN.doc)
end
local coords = get_coords(input)
if not coords then
return send_msg(msg, config.locale.errors.results)
end
local url = 'https://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '&timestamp='..os.time()
local jstr, res = HTTPS.request(url)
if res ~= 200 then
return send_msg(msg, config.locale.errors.connection)
end
local jdat = JSON.decode(jstr)
local timestamp = os.time() + jdat.rawOffset + jdat.dstOffset + config.time_offset
local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600
if utcoff == math.abs(utcoff) then
utcoff = '+' .. utcoff
end
local message = os.date('%I:%M %p\n', timestamp) .. os.date('%A, %B %d, %Y\n', timestamp) .. jdat.timeZoneName .. ' (UTC' .. utcoff .. ')'
send_msg(msg, message)
end
return PLUGIN