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:
parent
0c73362292
commit
5b87557194
@ -1,8 +1,9 @@
|
||||
local wordpress_recent_post = {}
|
||||
|
||||
function wordpress_recent_post:init(config)
|
||||
wordpress_recent_post.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('aka', true).table
|
||||
end
|
||||
wordpress_recent_post.triggers = {
|
||||
"^/([Aa][Kk][Aa])$",
|
||||
"^/([Pp][Ww])$"
|
||||
}
|
||||
|
||||
local makeOurDate = function(dateString)
|
||||
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
||||
@ -10,9 +11,13 @@ local makeOurDate = function(dateString)
|
||||
return day..'.'..month..'.'..year
|
||||
end
|
||||
|
||||
function wordpress_recent_post:get_full_url()
|
||||
local url = 'http://akamaru.de/?json=get_recent_posts'
|
||||
local res,code = http.request(url)
|
||||
function wordpress_recent_post:get_full_url(blog)
|
||||
local url = blog..'/?json=get_recent_posts'
|
||||
local doer = http
|
||||
if url:match('^https') then
|
||||
doer = https
|
||||
end
|
||||
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
|
||||
@ -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>'
|
||||
|
||||
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
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
|
||||
function wordpress_recent_post:action(msg, config)
|
||||
local text, image_url = wordpress_recent_post:get_full_url()
|
||||
function wordpress_recent_post:action(msg, config, matches)
|
||||
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
|
||||
utilities.send_reply(self, msg, config.errors.connection)
|
||||
return
|
Reference in New Issue
Block a user