This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/akasblog.lua

56 lines
1.3 KiB
Lua
Raw Normal View History

do
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)"
local year, month, day = dateString:match(pattern)
return day..'.'..month..'.'..year
end
2016-07-07 21:24:02 +02:00
local function get_post()
2016-01-31 19:08:28 +01:00
local url = 'http://akamaru.de/?json=get_recent_posts'
local res,code = http.request(url)
2016-01-31 19:08:28 +01:00
local data = json:decode(res).posts[1]
if code ~= 200 then return "HTTP-Fehler" end
if not data then return "HTTP-Fehler" end
2016-03-04 16:34:52 +01:00
local title = data.title
local from = data.author.name
local date = makeOurDate(data.date)
2016-03-04 16:34:52 +01:00
local content = string.match(data.excerpt, '<p>(.*)<span')
2016-02-09 16:22:12 +01:00
if not content then
2016-03-04 16:34:52 +01:00
content = string.match(data.excerpt, '<p>(.*)</p>')
2016-02-09 16:22:12 +01:00
end
local url = data.url
2015-12-17 17:54:04 +01:00
if data.thumbnail then
image_url = data.thumbnail
end
2016-03-04 16:34:52 +01:00
local text = unescape(title..' ('..from..' am '..date..')\n\n'..content)..'...\n'..url
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
return text
2015-12-17 17:54:04 +01:00
end
end
local function run(msg, matches)
2016-07-07 21:24:02 +02:00
local text, image_url = get_post()
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
return text
end
return {
2016-07-07 21:24:02 +02:00
description = "Sendet den aktuellen Beitrag von Aka's Blog",
usage = "#aka",
patterns = {"^#[Aa][Kk][Aa]$"},
run = run
}
2016-07-07 21:24:02 +02:00
--by Akamaru [https://ponywave.de]
end