Urban Dictionary Plugin neu geschrieben
This commit is contained in:
parent
d38e9caa20
commit
6e4ff13e59
@ -1,42 +1,50 @@
|
|||||||
function getUrbanDictionary(text)
|
do
|
||||||
local topic = string.match(text, "/ud (.+)") or string.match(text, "http://([A-Za-z0-9-_-]+).urbanup.com/") or string.match(text, "http://www.urbandictionary.com/define.php[?]term=([A-Za-z0-9-_-]+)")
|
|
||||||
topic = url_encode(topic)
|
|
||||||
b = http.request("http://api.urbandictionary.com/v0/define?term=" .. topic)
|
|
||||||
res = json:decode(b)
|
|
||||||
local definition = nil
|
|
||||||
if #res.list > 0 then
|
|
||||||
definition = res.list[1].word..": "..res.list[1].definition.."\n".. res.list[1].permalink
|
|
||||||
else
|
|
||||||
definition = nil
|
|
||||||
end
|
|
||||||
return definition
|
|
||||||
end
|
|
||||||
|
|
||||||
function url_encode(str)
|
local function getUrbanDictionary(term)
|
||||||
if (str) then
|
local url = 'http://api.urbandictionary.com/v0/define?term='..term
|
||||||
str = string.gsub (str, "\n", "\r\n")
|
local res,code = http.request(url)
|
||||||
str = string.gsub (str, "([^%w %-%_%.%~])",
|
local data = json:decode(res)
|
||||||
function (c) return string.format ("%%%02X", string.byte(c)) end)
|
if code ~= 200 then return "HTTP-Fehler" end
|
||||||
str = string.gsub (str, " ", "+")
|
if not data then return "Nichts gefunden!" end
|
||||||
|
|
||||||
|
local word = data.list[1].word
|
||||||
|
local dev = data.list[1].definition
|
||||||
|
local exam = data.list[1].example
|
||||||
|
local url = data.list[1].permalink
|
||||||
|
if data.sounds[1] then
|
||||||
|
sound = data.sounds[1]
|
||||||
end
|
end
|
||||||
return str
|
|
||||||
end
|
local text = unescape(word..'\n'..dev..'\n\nBeispiel: "'..exam..'"\n')..url
|
||||||
|
|
||||||
function run(msg, matches)
|
if data.sounds[1] then
|
||||||
local text = getUrbanDictionary(msg.text)
|
return text, sound
|
||||||
if (text == nil) then
|
|
||||||
return '"'..matches[1]..'" nicht gefunden.'
|
|
||||||
else
|
else
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function run(msg, matches)
|
||||||
|
local term = string.gsub(matches[1], ' ', '%%20')
|
||||||
|
local text, sound = getUrbanDictionary(term)
|
||||||
|
local receiver = get_receiver(msg)
|
||||||
|
if sound then
|
||||||
|
local file = download_to_file(sound, term..'.mp3')
|
||||||
|
send_audio(receiver, file, ok_cb, false)
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Zeigt eine Urban Dictionary Definition",
|
description = "Zeigt eine Urban Dictionary Definition",
|
||||||
usage = {"#ud [Begriff]"},
|
usage = {"#ud [Begriff]"},
|
||||||
patterns = {"^#ud (.*)$",
|
patterns = {"^#[Uu][Dd] (.*)$",
|
||||||
"^http://([A-Za-z0-9-_-]+).urbanup.com/",
|
"^http://([A-Za-z0-9-_-]+).urbanup.com/",
|
||||||
"^http://www.urbandictionary.com/define.php[?]term=([A-Za-z0-9-_-]+)"
|
"^http://www.urbandictionary.com/define.php%?term=([A-Za-z0-9-_-]+)"
|
||||||
},
|
},
|
||||||
run = run
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--by Akamaru [https://ponywave.de]
|
||||||
|
|
||||||
|
end
|
Reference in New Issue
Block a user