url-fix for wiki.lua

This commit is contained in:
Akamaru 2015-06-21 22:00:19 +02:00
parent 724696f2f2
commit 5dde8edad8

View File

@ -2,6 +2,17 @@
local socket = require "socket" local socket = require "socket"
local JSON = require "cjson" local JSON = require "cjson"
local decodetext
do
local char, gsub, tonumber = string.char, string.gsub, tonumber
local function _(hex) return char(tonumber(hex, 16)) end
function decodetext(s)
s = gsub(s, '%%(%x%x)', _)
return s
end
end
local wikiusage = { local wikiusage = {
"/wiki [Begriff]: Poste Artikel von der deutschen Wikipedia", "/wiki [Begriff]: Poste Artikel von der deutschen Wikipedia",
"/wiki(lang) [Begriff]: Poste Artikel aus anderer Sprache. Beispiel: /wikien Hello", "/wiki(lang) [Begriff]: Poste Artikel aus anderer Sprache. Beispiel: /wikien Hello",
@ -88,6 +99,7 @@ end
-- extract intro passage in wiki page -- extract intro passage in wiki page
function Wikipedia:wikintro(text, lang) function Wikipedia:wikintro(text, lang)
local text = decodetext(text)
local result = self:loadPage(text, lang, true, true) local result = self:loadPage(text, lang, true, true)
if result and result.query then if result and result.query then
@ -160,7 +172,6 @@ local function run(msg, matches)
if search then if search then
result = Wikipedia:wikisearch(term, lang) result = Wikipedia:wikisearch(term, lang)
else else
-- TODO: Show the link
result = Wikipedia:wikintro(term, lang) result = Wikipedia:wikintro(term, lang)
end end
return result return result
@ -174,7 +185,7 @@ return {
"^/[Ww]iki (search) ?(.*)$", "^/[Ww]iki (search) ?(.*)$",
"^/[Ww]iki(%w+) (.+)$", "^/[Ww]iki(%w+) (.+)$",
"^/[Ww]iki ?(.*)$", "^/[Ww]iki ?(.*)$",
"de.wikipedia.org/wiki/([A-Za-z0-9-_-]+)" "de.wikipedia.org/wiki/(.+)"
}, },
run = run run = run
} }