From 5b875571949773b8dde6ac9c4def427c36ea0ecc Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 16 Aug 2016 00:58:42 +0200 Subject: [PATCH] =?UTF-8?q?Bennene=20"Akasblog"=20in=20"WordPress=5FPosts"?= =?UTF-8?q?=20um=20und=20f=C3=BCge=20Support=20f=C3=BCr=20PonyWave=20hinzu?= =?UTF-8?q?.=20In=20Zukunft=20k=C3=B6nnen=20weitere=20WordPress-Blogs=20ga?= =?UTF-8?q?nz=20einfach=20hinzugef=C3=BCgt=20werden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{akasblog.lua => wordpress_posts.lua} | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) rename miku/plugins/{akasblog.lua => wordpress_posts.lua} (67%) diff --git a/miku/plugins/akasblog.lua b/miku/plugins/wordpress_posts.lua similarity index 67% rename from miku/plugins/akasblog.lua rename to miku/plugins/wordpress_posts.lua index 3eaedea..2f6e9c5 100644 --- a/miku/plugins/akasblog.lua +++ b/miku/plugins/wordpress_posts.lua @@ -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 = ''..title..'\n'..from..' am '..posted_at..'\n'..content..'...\nArtikel aufrufen' 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