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-2/otouto/plugins/ap.lua
Andreas Bielawski 7f45f4d736 - gImages: Stark verbessert, keine Code-Duplikation mehr + Bilder werden nicht mehr heruntergeladen, sondern direkt an den TG-Server gesendet (3. Oktober Update)
- Einige Plugins nutzen jetzt Bilder-URLs, anstatt die Datei selbst herunterzuladen (3. Oktober Update)
2016-10-03 20:19:20 +02:00

38 lines
1.1 KiB
Lua

local ap = {}
ap.triggers = {
"hosted.ap.org/dynamic/stories/(.+)"
}
function ap:get_article(article)
local url = 'http://hosted.ap.org/dynamic/stories/'..article
local res, code = http.request(url)
if code ~= 200 then return 'HTTP-Fehler '..code..' ist aufgetreten.' end
local headline = res:match('<span class%=\"headline entry%-title\">(.-)</span>')
if not headline then return end
local article = unescape(utilities.trim(res:match('<p class%=\"ap%-story%-p\">(.-)</p>')))
local pic_url = res:match('<img src%=\"(/photos/.-)" alt%=\"AP Photo\"')
local text = '<b>'..headline..'</b>\n'..article
return text, pic_url
end
function ap:action(msg, config, matches)
local article_id = matches[1]
local article, pic = ap:get_article(article_id)
if not article then
utilities.send_reply(msg, config.errors.connection)
return
end
if pic then
local pic = pic:gsub('-small', '-big')
utilities.send_photo(msg.chat.id, 'http://hosted.ap.org'..pic, nil, msg.message_id)
end
utilities.send_reply(msg, article, 'HTML')
end
return ap