From 1c93a20e1128bbda09726baa5a9fec0c6f756e0b Mon Sep 17 00:00:00 2001 From: Akamaru Date: Mon, 20 Apr 2015 01:53:34 +0200 Subject: [PATCH] new plugins: pornhub.lua and youporn.lua --- plugins/pornhub.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++ plugins/youporn.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 plugins/pornhub.lua create mode 100644 plugins/youporn.lua diff --git a/plugins/pornhub.lua b/plugins/pornhub.lua new file mode 100644 index 0000000..e657597 --- /dev/null +++ b/plugins/pornhub.lua @@ -0,0 +1,49 @@ + +function run(msg, matches) + + -- local g = require "./plugins/google" + -- local query = "site:pornhub.com+viewkey+" .. matches[1] + -- local new_matches = {query} + + -- return g.run(msg, new_matches) + local results = findPorn(matches[1]) + return results-- build_result(results) +end + +function findPorn(query) + local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:pornhub.com+viewkey+" .. query:gsub(" ", "+") + + -- Do the request + local res, code = https.request(api) + + if code ~=200 then return nil end + local data = json:decode(res) + local results = data.responseData.results + + + + math.randomseed( os.time() ) + math.random(#results) + math.random(#results) + local index = math.random(#results) + + local result = results[index].titleNoFormatting .. "\n".. results[index].unescapedUrl .."\n" + + return result +end + +function build_result(query) + local stringresults="" + for key,val in ipairs(results) do + stringresults=stringresults..val[1].."\n"..val[2].."\n\n" + end + return stringresults +end + +return { + description = "", + usage = "/pornhub", + patterns = {"^/pornhub (.*)$", + "^/ph (.*)$"}, + run = run + } \ No newline at end of file diff --git a/plugins/youporn.lua b/plugins/youporn.lua new file mode 100644 index 0000000..dadc8ba --- /dev/null +++ b/plugins/youporn.lua @@ -0,0 +1,49 @@ + +function run(msg, matches) + + -- local g = require "./plugins/google" + -- local query = "site:pornhub.com+viewkey+" .. matches[1] + -- local new_matches = {query} + + -- return g.run(msg, new_matches) + local results = findAss(matches[1]) + return results-- build_result(results) +end + +function findAss(query) + local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=site:youporn.com+viewkey+" .. query:gsub(" ", "+") + + -- Do the request + local res, code = https.request(api) + + if code ~=200 then return nil end + local data = json:decode(res) + local results = data.responseData.results + + + + math.randomseed( os.time() ) + math.random(#results) + math.random(#results) + local index = math.random(#results) + + local result = results[index].titleNoFormatting .. "\n".. results[index].unescapedUrl .."\n" + + return result +end + +function build_result(query) + local stringresults="" + for key,val in ipairs(results) do + stringresults=stringresults..val[1].."\n"..val[2].."\n\n" + end + return stringresults +end + +return { + description = "", + usage = "/youporn", + patterns = {"^/youporn (.*)$", + "^/yp (.*)$"}, + run = run + } \ No newline at end of file