2015-11-22 20:52:17 +01:00
|
|
|
do
|
|
|
|
|
|
|
|
local makeOurDate = function(dateString)
|
|
|
|
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
|
|
|
local year, month, day = dateString:match(pattern)
|
|
|
|
return day..'.'..month..'.'..year
|
|
|
|
end
|
|
|
|
|
|
|
|
local function get_post(post)
|
2016-01-31 19:08:28 +01:00
|
|
|
local url = 'http://akamaru.de/?json=get_recent_posts'
|
2015-11-22 20:52:17 +01:00
|
|
|
local res,code = http.request(url)
|
2016-01-31 19:08:28 +01:00
|
|
|
local data = json:decode(res).posts[1]
|
2015-11-22 20:52:17 +01:00
|
|
|
if code ~= 200 then return "HTTP-Fehler" end
|
|
|
|
if not data then return "HTTP-Fehler" end
|
|
|
|
|
2016-02-09 16:22:12 +01:00
|
|
|
local title = unescape(data.title)
|
2015-11-22 20:52:17 +01:00
|
|
|
local from = data.author.name
|
|
|
|
local date = makeOurDate(data.date)
|
2016-02-09 16:22:12 +01:00
|
|
|
local content = unescape(string.match(data.excerpt, '<p>(.*)<span'))
|
|
|
|
if not content then
|
|
|
|
content = unescape(string.match(data.excerpt, '<p>(.*)</p>'))
|
|
|
|
end
|
2015-11-22 20:52:17 +01:00
|
|
|
local url = data.url
|
2015-12-17 17:54:04 +01:00
|
|
|
if data.thumbnail then
|
|
|
|
image_url = data.thumbnail
|
|
|
|
end
|
2015-11-22 20:52:17 +01:00
|
|
|
|
2015-12-01 20:51:42 +01:00
|
|
|
local text = title..' ('..from..' am '..date..')\n\n'..content..'...\n'..url
|
2015-11-22 20:52:17 +01:00
|
|
|
|
2016-02-02 16:13:34 +01:00
|
|
|
if data.thumbnail then
|
2015-12-17 17:54:04 +01:00
|
|
|
return text, image_url
|
|
|
|
else
|
2015-11-22 20:52:17 +01:00
|
|
|
return text
|
2015-12-17 17:54:04 +01:00
|
|
|
end
|
2015-11-22 20:52:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function run(msg, matches)
|
2015-12-17 17:54:04 +01:00
|
|
|
local text, image_url = get_post(post)
|
2015-11-22 20:52:17 +01:00
|
|
|
local receiver = get_receiver(msg)
|
2015-12-17 17:54:04 +01:00
|
|
|
if image_url then
|
|
|
|
local file = download_to_file(image_url)
|
|
|
|
send_photo(receiver, file, ok_cb, false)
|
|
|
|
end
|
2015-11-22 20:52:17 +01:00
|
|
|
return text
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
description = "Sendet letzten Aka's Blog Beitrag",
|
|
|
|
usage = "/aka",
|
|
|
|
patterns = {"^/[Aa][Kk][Aa]$"},
|
|
|
|
run = run
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|