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/pluginsold/wiki_old.lua

66 lines
1.9 KiB
Lua
Raw Normal View History

2015-06-17 22:23:25 +02:00
require("./plugins/googlethat")
function firstresult(results)
return results[1][2]
end
function wikiapilink(wikiurl)
local wikipattern="^http://de.wikipedia.org/wiki/(.*)$"
local matches = { string.match(wikiurl, wikipattern) }
local queryterm=matches[1]
local apilink = "http://de.wikipedia.org/w/index.php?action=raw&title="..queryterm
return apilink
end
function getwikifromapi(apilink)
-- Do the request
local res, code = https.request(apilink)
if code ~=200 then return "Ein Fehler ist aufgetreten" end
local data = res
local wikitext=data
return wikitext
end
function plaintext(wikitext)
local plaintext=string.gsub(wikitext,"{{Infobox.-\n}}\n","")
plaintext=string.gsub(wikitext,"{{Medienbox.-\n}}\n","")
plaintext=string.gsub(wikitext,"<!--.--->","")
plaintext=string.gsub(plaintext,"Datei:.-]]","")
plaintext=string.gsub(plaintext,"{{.-}}","")
plaintext=string.gsub(plaintext,"[%[%|%]%]]","")
plaintext=string.gsub(plaintext,"<ref.->.-</ref>","")
local firstsectionindex=string.find(plaintext,"==")
if firstsectionindex~=nil then
plaintext=string.sub(plaintext,1,firstsectionindex-1)
end
return plaintext
end
function formatwikiforsending(wikitext,url)
-- local stringtosend=title.."\n==="
local stringtosend=plaintext(wikitext).."\n"
stringtosend=stringtosend.."- "..url
return stringtosend
end
function scrapewiki(results)
local url=firstresult(results)
local tosend=formatwikiforsending(getwikifromapi(wikiapilink(url)),url)
return tosend
end
function run(msg, matches)
vardump(matches)
local results = googlethat(matches[1].." site:de.wikipedia.org")
return scrapewiki(results)
end
return {
description = "Sendet einen Wikipedia-Artikel",
usage = {"/wiki [Suchwort]","de.wikipedia.org Link"},
patterns = {"^/wiki (.*)$","^%.[w|W]iki (.*)$","de.wikipedia.org/wiki/([A-Za-z0-9-_-]+)"},
run = run
}