From 2665a6dae8e0378955950b56c236d0dd5606cd7a Mon Sep 17 00:00:00 2001 From: Akshay S Dinesh Date: Sun, 11 Jan 2015 17:50:02 +0530 Subject: [PATCH 1/3] google search --- plugins/google.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/google.lua diff --git a/plugins/google.lua b/plugins/google.lua new file mode 100644 index 0000000..792131e --- /dev/null +++ b/plugins/google.lua @@ -0,0 +1,38 @@ +function googlethat(query) + local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&" + local parameters = "q=".. (URL.escape(query) or "") + + -- Do the request + local res, code = https.request(api..parameters) + if code ~=200 then return nil end + local data = json:decode(res) + local results={} + for key,result in ipairs(data.responseData.results) do + table.insert(results,{result.titleNoFormatting, result.url}) + end + return results +end + +function stringlinks(results) + local stringresults="" + for key,val in ipairs(results) do + stringresults=stringresults..val[1].." - "..val[2].."\n" + end + return stringresults +end + +function run(msg, matches) + vardump(matches) + local results = googlethat(matches[1]) + return stringlinks(results) +end + +return { + description = "Searches Google", + usage = "!google terms", + patterns = { + "^!google (.*)$", + "^.[g|G]oogle (.*)$" + }, + run = run +} From f50c130d9fb998c0558cfae03571d5164e76674f Mon Sep 17 00:00:00 2001 From: Akshay S Dinesh Date: Mon, 12 Jan 2015 09:07:58 +0530 Subject: [PATCH 2/3] fixed doubling of replies --- plugins/google.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/google.lua b/plugins/google.lua index 792131e..d3b22de 100644 --- a/plugins/google.lua +++ b/plugins/google.lua @@ -32,7 +32,7 @@ return { usage = "!google terms", patterns = { "^!google (.*)$", - "^.[g|G]oogle (.*)$" + "^%.[g|G]oogle (.*)$" }, run = run } From e0f374b0db9b27276d8c125844132e610930fb68 Mon Sep 17 00:00:00 2001 From: yago Date: Mon, 12 Jan 2015 20:50:22 +0100 Subject: [PATCH 3/3] just a "," --- bot/bot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/bot.lua b/bot/bot.lua index 07fa42e..cb9dd85 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -145,7 +145,7 @@ function create_config( ) "9gag", "echo", "get", - "help" + "help", "images", "img_google", "location",