diff --git a/miku/plugins/rss.lua b/miku/plugins/rss.lua index 2b9a77c..d5d22f1 100644 --- a/miku/plugins/rss.lua +++ b/miku/plugins/rss.lua @@ -1,7 +1,6 @@ local rss = {} local feedparser = require("feedparser") -require "./miku/encoding" rss.command = 'rss ' diff --git a/miku/plugins/wordpress_posts.lua b/miku/plugins/wordpress_posts.lua index 122702c..6dc0181 100644 --- a/miku/plugins/wordpress_posts.lua +++ b/miku/plugins/wordpress_posts.lua @@ -1,6 +1,9 @@ local wordpress_recent_post = {} wordpress_recent_post.triggers = { + "^/([Aa][Kk][Aa]) (.+)$", + "^/([Tt][Hh][Cc]) (.+)$", + "^/([Pp][Ww]) (.+)$", "^/([Aa][Kk][Aa])$", "^/([Pp][Ww])$" } @@ -11,8 +14,12 @@ local makeOurDate = function(dateString) return day..'.'..month..'.'..year end -function wordpress_recent_post:get_full_url(blog) - local url = blog..'/?json=get_recent_posts' +function wordpress_recent_post:get_full_url(blog, tag) + if tag then + url = blog..'/?json=get_search_results&search='..tag + else + url = blog..'/?json=get_recent_posts' + end local doer = http if url:match('^https') then doer = https @@ -20,16 +27,20 @@ function wordpress_recent_post:get_full_url(blog) local res, code = doer.request(url) if code ~= 200 then return nil end local data = json.decode(res).posts[1] - if not data then return nil end + if not data then return 'NOTFOUND' end - local title = unescape(data.title) - local from = unescape(data.author.name) + local title = encoding(data.title) + local from = encoding(data.author.name) local posted_at = makeOurDate(data.date) local content = data.excerpt:match('

(.*)(.*)

') end - local content = unescape(content) + if not content then + content = "" + else + content = '\n'..encoding(content)..'...' + end local url = data.url if data.thumbnail then image_url = data.thumbnail @@ -37,20 +48,26 @@ function wordpress_recent_post:get_full_url(blog) image_url = nil end - local text = ''..title..'\n'..from..' am '..posted_at..'\n'..content..'...\nArtikel aufrufen' + local text = ''..title..'\n'..from..' am '..posted_at..''..content..'\nArtikel aufrufen' return text, image_url end function wordpress_recent_post:action(msg, config, matches) - if matches[1]:match('[Aa][Kk][Aa]') then + local blog = matches[1] + if blog:match('[Aa][Kk][Aa]') then blog = 'http://akamaru.de' - elseif matches[1]:match('[Pp][Ww]') then + elseif blog:match('[Pp][Ww]') then blog = 'https://ponywave.de' + elseif blog:match('[Tt][Hh][Cc]') then + blog = 'http://homebrew.cloud' end - local text, image_url = wordpress_recent_post:get_full_url(blog) + local text, image_url = wordpress_recent_post:get_full_url(blog, matches[2]) if not text then utilities.send_reply(self, msg, config.errors.connection) return + elseif text == 'NOTFOUND' then + utilities.send_reply(self, msg, config.errors.results) + return end if image_url then diff --git a/miku/utilities.lua b/miku/utilities.lua index 217b84d..7a5d838 100644 --- a/miku/utilities.lua +++ b/miku/utilities.lua @@ -15,6 +15,7 @@ redis = (loadfile './miku/redis.lua')() mime = (loadfile './miku/mimetype.lua')() OAuth = require 'OAuth' helpers = require 'OAuth.helpers' +require('/miku/encoding') http.timeout = 5 https.timeout = 5 @@ -962,24 +963,6 @@ function convertNumbers(str) return str end -function unescape(str) - str = string.gsub( str, '<', '<' ) - str = string.gsub( str, '>', '>' ) - str = string.gsub( str, '"', '"' ) - str = string.gsub( str, ''', "'" ) - str = string.gsub( str, "Ä", "Ä") - str = string.gsub( str, "ä", "ä") - str = string.gsub( str, "Ö", "Ö") - str = string.gsub( str, "ö", "ö") - str = string.gsub( str, "Uuml;", "Ü") - str = string.gsub( str, "ü", "ü") - str = string.gsub( str, "ß", "ß") - str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) - str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) - str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others - return str -end - function url_encode(str) if (str) then str = string.gsub (str, "\n", "\r\n")