- Portiere Plugin für Fefes Blog (kein Markdown-Support)

- Ändere string.ends für Dropbox (Danke @Akamaru)
This commit is contained in:
Andreas Bielawski 2016-06-18 15:48:32 +02:00
parent f3c841fb90
commit 3f2b987839
2 changed files with 37 additions and 1 deletions

View File

@ -17,7 +17,7 @@ function dropbox:action(msg, config, matches)
local v,code = https.request(link) local v,code = https.request(link)
if code == 200 then if code == 200 then
if string.ends(link, ".png") or string.ends(link, ".jpeg") or string.ends(link, ".jpg") then if string.ends(link, ".png") or string.ends(link, ".jpe?g")then
utilities.send_typing(self, msg.chat.id, 'upload_photo') utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(link) local file = download_to_file(link)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)

36
otouto/plugins/fefe.lua Normal file
View File

@ -0,0 +1,36 @@
local fefe = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('otouto.utilities')
fefe.triggers = {
"blog.fefe.de/%?ts=%w%w%w%w%w%w%w%w"
}
function fefe:post(id)
local url = 'http://'..id
local results, code = https.request(url)
if code ~= 200 then return "HTTP-Fehler" end
if string.match(results, "No entries found.") then return "Eintrag nicht gefunden." end
local line = string.sub( results, string.find(results, "<li><a href[^\n]+"))
local text = line:gsub("<div style=.+", "")
-- remove link at begin
local text = text:gsub("<li><a href=\"%?ts=%w%w%w%w%w%w%w%w\">%[l]</a>", "")
-- replace "<p>" with newline; "<b>" and "</b>" with "*"
local text = text:gsub("<p>", "\n\n"):gsub("<p u>", "\n\n")
local text = text:gsub("<b>", "*"):gsub("</b>", "*")
local text = text:gsub("<i>", "_"):gsub("</i>", "_")
-- format quotes and links markdown-like
local text = text:gsub("<a href=\"", "("):gsub("\">", ")["):gsub("</a>", "]")
local text = text:gsub("<blockquote>", "\n\n> "):gsub("</blockquote>", "\n\n")
return text
end
function fefe:action(msg, config, matches)
utilities.send_reply(self, msg, fefe:post(matches[1]))
end
return fefe