diff --git a/plugins/chucknorris.lua b/plugins/chucknorris.lua new file mode 100644 index 0000000..4b25c38 --- /dev/null +++ b/plugins/chucknorris.lua @@ -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 +} \ No newline at end of file diff --git a/plugins/lyrics.lua b/plugins/lyrics.lua new file mode 100644 index 0000000..2d93ecf --- /dev/null +++ b/plugins/lyrics.lua @@ -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 \ No newline at end of file diff --git a/plugins/urban_dictionary.lua b/plugins/urban_dictionary.lua new file mode 100644 index 0000000..4dc641a --- /dev/null +++ b/plugins/urban_dictionary.lua @@ -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 +} \ No newline at end of file