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/plugins/google.lua

39 lines
975 B
Lua
Raw Normal View History

2015-01-11 13:20:02 +01:00
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)
2015-03-04 23:51:36 +01:00
vardump(matches)
local results = googlethat(matches[1])
return stringlinks(results)
2015-01-11 13:20:02 +01:00
end
return {
2015-04-14 20:21:23 +02:00
description = "Durchsucht Google und sendet die ersten 5 Ergebnisse",
usage = "/google [Begriff]",
2015-03-04 23:51:36 +01:00
patterns = {
2015-04-14 20:21:23 +02:00
"^/google (.*)$",
2015-03-04 23:51:36 +01:00
"^%.[g|G]oogle (.*)$"
},
run = run
2015-01-11 13:20:02 +01:00
}