3 new plugins

This commit is contained in:
Akamaru 2015-04-19 21:18:06 +02:00
parent 26ab8ca279
commit 1cf4948539
3 changed files with 107 additions and 0 deletions

21
plugins/chucknorris.lua Normal file
View File

@ -0,0 +1,21 @@
function getChuckNorris()
b = http.request("http://api.icndb.com/jokes/random/")
response = json:decode(b)
return response.value.joke
end
function run(msg, matches)
local j = getChuckNorris()
if (j == nil) then
return "Zzzzz..."
else
return j
end
end
return {
description = "get chuck norris joke",
usage = "/cn",
patterns = {"^/cn$"},
run = run
}

47
plugins/lyrics.lua Normal file
View File

@ -0,0 +1,47 @@
do
local apikey = cred_data.lyricsnmusic_apikey
function getLyrics(text)
local q = string.match(text, "/lyrics (.+)")
q = url_encode(q)
b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q)
response = json:decode(b)
local reply = ""
if #response > 0 then
-- grab first match
local result = response[1]
reply = result.title .. " - " .. result.artist.name .. "\n" .. result.snippet .. "\n" .. result.url
else
reply = nil
end
return reply
end
function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function run(msg, matches)
local lyrics = getLyrics(msg.text)
if (lyrics == nil) then
return "Zzzzz..."
else
return lyrics
end
end
return {
description = "Liedertext bekommen",
usage = "/lyrics [Lied]",
patterns = {"^/lyrics (.*)$"},
run = run
}
end

View File

@ -0,0 +1,39 @@
function getUrbanDictionary(text)
local topic = string.match(text, "/ud (.+)")
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)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function run(msg, matches)
local text = getUrbanDictionary(msg.text)
if (text == nil) then
return "Zzzzz..."
else
return text
end
end
return {
description = "get urban dictionary definition",
usage = "/ud [topic]",
patterns = {"^/ud (.*)$"},
run = run
}