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
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, " ", "+")
return str
function run(msg, matches)
local lyrics = getLyrics(msg.text)
if (lyrics == nil) then
return "Nichts gefunden!"
return lyrics
return {
description = "Liedertext bekommen",
usage = {"/lyrics [Lied]"},
patterns = {"^/lyrics (.*)$"},
run = run
}