Bennene "Akasblog" in "WordPress_Posts" um und füge Support für PonyWave hinzu. In Zukunft können weitere WordPress-Blogs ganz einfach hinzugefügt werden.

This commit is contained in:
Andreas Bielawski 2016-08-16 00:58:42 +02:00
parent 0c73362292
commit 5b87557194

View File

@ -1,8 +1,9 @@
local wordpress_recent_post = {} local wordpress_recent_post = {}
function wordpress_recent_post:init(config) wordpress_recent_post.triggers = {
wordpress_recent_post.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('aka', true).table "^/([Aa][Kk][Aa])$",
end "^/([Pp][Ww])$"
}
local makeOurDate = function(dateString) local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)" local pattern = "(%d+)%-(%d+)%-(%d+)"
@ -10,9 +11,13 @@ local makeOurDate = function(dateString)
return day..'.'..month..'.'..year return day..'.'..month..'.'..year
end end
function wordpress_recent_post:get_full_url() function wordpress_recent_post:get_full_url(blog)
local url = 'http://akamaru.de/?json=get_recent_posts' local url = blog..'/?json=get_recent_posts'
local res,code = http.request(url) local doer = http
if url:match('^https') then
doer = https
end
local res, code = doer.request(url)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res).posts[1] local data = json.decode(res).posts[1]
if not data then return nil end if not data then return nil end
@ -35,15 +40,20 @@ function wordpress_recent_post:get_full_url()
local text = '<b>'..title..'</b>\n<i>'..from..' am '..posted_at..'</i>\n'..content..'...\n<a href="'..url..'">Artikel aufrufen</a>' local text = '<b>'..title..'</b>\n<i>'..from..' am '..posted_at..'</i>\n'..content..'...\n<a href="'..url..'">Artikel aufrufen</a>'
if image_url then if image_url then
local text = title..' ('..from..' am '..posted_at..')\n\n'..content..'...\n'..url -- captions don't supported markdowns local text = title..' ('..from..' am '..posted_at..')\n\n'..content..'...\n'..url -- captions don't support markdown
return text, image_url return text, image_url
else else
return text return text
end end
end end
function wordpress_recent_post:action(msg, config) function wordpress_recent_post:action(msg, config, matches)
local text, image_url = wordpress_recent_post:get_full_url() if matches[1]:match('[Aa][Kk][Aa]') then
blog = 'http://akamaru.de'
elseif matches[1]:match('[Pp][Ww]') then
blog = 'https://ponywave.de'
end
local text, image_url = wordpress_recent_post:get_full_url(blog)
if not text then if not text then
utilities.send_reply(self, msg, config.errors.connection) utilities.send_reply(self, msg, config.errors.connection)
return return