From e5b17fc2bd1501ef7ebc4e5758d5c6c492288b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mun=CC=83oz?= Date: Mon, 1 Dec 2014 17:12:22 +0100 Subject: [PATCH] Added gps and location plugins --- plugins/gps.lua | 32 ++++++++++++++++++++++++++++++++ plugins/location.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 plugins/gps.lua create mode 100644 plugins/location.lua diff --git a/plugins/gps.lua b/plugins/gps.lua new file mode 100644 index 0000000..f26a211 --- /dev/null +++ b/plugins/gps.lua @@ -0,0 +1,32 @@ + +function delay_s(delay) + delay = delay or 1 + local time_to = os.time() + delay + while os.time() < time_to do end +end + +function run(msg, matches) + local lat = matches[1] + local lon = matches[2] + local receiver = get_receiver(msg) + + local zooms = {16, 18} + + for i = 1, #zooms do + local zoom = zooms[i] + local url = "http://maps.googleapis.com/maps/api/staticmap?zoom=" .. zoom .. "&size=600x300&maptype=roadmap¢er=" .. lat .. "," .. lon .. "&markers=color:blue%7Clabel:X%7C" .. lat .. "," .. lon + local file = download_to_file(url) + send_photo(receiver, file, ok_cb, false) + delay_s(2) + end + + return "www.google.es/maps/place/@" .. lat .. "," .. lon +end + +return { + description = "generates a map showing the given GPS coordinates", + usage = "!gps latitude,longitude", + patterns = {"^!gps ([^,]*)[,%s]([^,]*)$"}, + run = run +} + diff --git a/plugins/location.lua b/plugins/location.lua new file mode 100644 index 0000000..cf3e6b3 --- /dev/null +++ b/plugins/location.lua @@ -0,0 +1,31 @@ + +function delay_s(delay) + delay = delay or 1 + local time_to = os.time() + delay + while os.time() < time_to do end +end + +function run(msg, matches) + local loc = string.gsub(matches[1], "%s+", "+") + local receiver = get_receiver(msg) + + local zooms = {16, 18} + + for i = 1, #zooms do + local zoom = zooms[i] + local url = "http://maps.googleapis.com/maps/api/staticmap?zoom=" .. zoom .. "&size=600x300&maptype=roadmap¢er=" .. loc .. "&markers=color:blue%7Clabel:A%7C" .. loc + local file = download_to_file(url) + send_photo(receiver, file, ok_cb, false) + delay_s(2) + end + + return "www.google.es/maps/place/" .. loc +end + +return { + description = "generates a map showing the given location", + usage = "!loc (location)", + patterns = {"^!loc (.*)$"}, + run = run +} +