52 lines
1.2 KiB
Lua
52 lines
1.2 KiB
Lua
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)
|
|
local url = 'https://ponywave.de/?json=get_recent_posts'
|
|
local res,code = https.request(url)
|
|
local data = json:decode(res).posts[1]
|
|
if code ~= 200 then return "HTTP-Fehler" end
|
|
if not data then return "HTTP-Fehler" end
|
|
|
|
local title = data.title
|
|
local from = data.author.name
|
|
local date = makeOurDate(data.date)
|
|
local content = string.match(data.excerpt, '<p>(.*)</p>')
|
|
local url = data.url
|
|
if data.thumbnail then
|
|
image_url = data.thumbnail
|
|
end
|
|
|
|
local text = unescape(title..' ('..from..' am '..date..')\n\n'..content)..'...\n'..url
|
|
|
|
if data.thumbnail then
|
|
return text, image_url
|
|
else
|
|
return text
|
|
end
|
|
end
|
|
|
|
local function run(msg, matches)
|
|
local text, image_url = get_post(post)
|
|
local receiver = get_receiver(msg)
|
|
if image_url then
|
|
local receiver = get_receiver(msg)
|
|
local file = download_to_file(image_url)
|
|
send_photo(receiver, file, ok_cb, false)
|
|
end
|
|
return text
|
|
end
|
|
|
|
return {
|
|
description = "Sendet letzten PonyWave Beitrag",
|
|
usage = "/pw",
|
|
patterns = {"^/[Pp][Ww]$"},
|
|
run = run
|
|
}
|
|
|
|
end |