- Nutze encoding.lua (global)
- Suche für PonyWave, Akamaru.de und Homebrew.cloud ergänzt
This commit is contained in:
parent
8800ce6f45
commit
0e830fefda
@ -1,7 +1,6 @@
|
|||||||
local rss = {}
|
local rss = {}
|
||||||
|
|
||||||
local feedparser = require("feedparser")
|
local feedparser = require("feedparser")
|
||||||
require "./miku/encoding"
|
|
||||||
|
|
||||||
rss.command = 'rss <sub/del>'
|
rss.command = 'rss <sub/del>'
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
local wordpress_recent_post = {}
|
local wordpress_recent_post = {}
|
||||||
|
|
||||||
wordpress_recent_post.triggers = {
|
wordpress_recent_post.triggers = {
|
||||||
|
"^/([Aa][Kk][Aa]) (.+)$",
|
||||||
|
"^/([Tt][Hh][Cc]) (.+)$",
|
||||||
|
"^/([Pp][Ww]) (.+)$",
|
||||||
"^/([Aa][Kk][Aa])$",
|
"^/([Aa][Kk][Aa])$",
|
||||||
"^/([Pp][Ww])$"
|
"^/([Pp][Ww])$"
|
||||||
}
|
}
|
||||||
@ -11,8 +14,12 @@ local makeOurDate = function(dateString)
|
|||||||
return day..'.'..month..'.'..year
|
return day..'.'..month..'.'..year
|
||||||
end
|
end
|
||||||
|
|
||||||
function wordpress_recent_post:get_full_url(blog)
|
function wordpress_recent_post:get_full_url(blog, tag)
|
||||||
local url = blog..'/?json=get_recent_posts'
|
if tag then
|
||||||
|
url = blog..'/?json=get_search_results&search='..tag
|
||||||
|
else
|
||||||
|
url = blog..'/?json=get_recent_posts'
|
||||||
|
end
|
||||||
local doer = http
|
local doer = http
|
||||||
if url:match('^https') then
|
if url:match('^https') then
|
||||||
doer = https
|
doer = https
|
||||||
@ -20,16 +27,20 @@ function wordpress_recent_post:get_full_url(blog)
|
|||||||
local res, code = doer.request(url)
|
local res, code = doer.request(url)
|
||||||
if code ~= 200 then return nil end
|
if code ~= 200 then return nil end
|
||||||
local data = json.decode(res).posts[1]
|
local data = json.decode(res).posts[1]
|
||||||
if not data then return nil end
|
if not data then return 'NOTFOUND' end
|
||||||
|
|
||||||
local title = unescape(data.title)
|
local title = encoding(data.title)
|
||||||
local from = unescape(data.author.name)
|
local from = encoding(data.author.name)
|
||||||
local posted_at = makeOurDate(data.date)
|
local posted_at = makeOurDate(data.date)
|
||||||
local content = data.excerpt:match('<p>(.*)<span')
|
local content = data.excerpt:match('<p>(.*)<span')
|
||||||
if not content then
|
if not content then
|
||||||
content = data.excerpt:match('<p>(.*)</p>')
|
content = data.excerpt:match('<p>(.*)</p>')
|
||||||
end
|
end
|
||||||
local content = unescape(content)
|
if not content then
|
||||||
|
content = ""
|
||||||
|
else
|
||||||
|
content = '\n'..encoding(content)..'...'
|
||||||
|
end
|
||||||
local url = data.url
|
local url = data.url
|
||||||
if data.thumbnail then
|
if data.thumbnail then
|
||||||
image_url = data.thumbnail
|
image_url = data.thumbnail
|
||||||
@ -37,20 +48,26 @@ function wordpress_recent_post:get_full_url(blog)
|
|||||||
image_url = nil
|
image_url = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local text = '<b>'..title..'</b>\n<i>'..from..' am '..posted_at..'</i>\n'..content..'...\n<a href="'..url..'">Artikel aufrufen</a>'
|
local text = '<b>'..title..'</b>\n<i>'..from..' am '..posted_at..'</i>'..content..'\n<a href="'..url..'">Artikel aufrufen</a>'
|
||||||
return text, image_url
|
return text, image_url
|
||||||
end
|
end
|
||||||
|
|
||||||
function wordpress_recent_post:action(msg, config, matches)
|
function wordpress_recent_post:action(msg, config, matches)
|
||||||
if matches[1]:match('[Aa][Kk][Aa]') then
|
local blog = matches[1]
|
||||||
|
if blog:match('[Aa][Kk][Aa]') then
|
||||||
blog = 'http://akamaru.de'
|
blog = 'http://akamaru.de'
|
||||||
elseif matches[1]:match('[Pp][Ww]') then
|
elseif blog:match('[Pp][Ww]') then
|
||||||
blog = 'https://ponywave.de'
|
blog = 'https://ponywave.de'
|
||||||
|
elseif blog:match('[Tt][Hh][Cc]') then
|
||||||
|
blog = 'http://homebrew.cloud'
|
||||||
end
|
end
|
||||||
local text, image_url = wordpress_recent_post:get_full_url(blog)
|
local text, image_url = wordpress_recent_post:get_full_url(blog, matches[2])
|
||||||
if not text then
|
if not text then
|
||||||
utilities.send_reply(self, msg, config.errors.connection)
|
utilities.send_reply(self, msg, config.errors.connection)
|
||||||
return
|
return
|
||||||
|
elseif text == 'NOTFOUND' then
|
||||||
|
utilities.send_reply(self, msg, config.errors.results)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if image_url then
|
if image_url then
|
||||||
|
@ -15,6 +15,7 @@ redis = (loadfile './miku/redis.lua')()
|
|||||||
mime = (loadfile './miku/mimetype.lua')()
|
mime = (loadfile './miku/mimetype.lua')()
|
||||||
OAuth = require 'OAuth'
|
OAuth = require 'OAuth'
|
||||||
helpers = require 'OAuth.helpers'
|
helpers = require 'OAuth.helpers'
|
||||||
|
require('/miku/encoding')
|
||||||
|
|
||||||
http.timeout = 5
|
http.timeout = 5
|
||||||
https.timeout = 5
|
https.timeout = 5
|
||||||
@ -962,24 +963,6 @@ function convertNumbers(str)
|
|||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
function unescape(str)
|
|
||||||
str = string.gsub( str, '<', '<' )
|
|
||||||
str = string.gsub( str, '>', '>' )
|
|
||||||
str = string.gsub( str, '"', '"' )
|
|
||||||
str = string.gsub( str, ''', "'" )
|
|
||||||
str = string.gsub( str, "Ä", "Ä")
|
|
||||||
str = string.gsub( str, "ä", "ä")
|
|
||||||
str = string.gsub( str, "Ö", "Ö")
|
|
||||||
str = string.gsub( str, "ö", "ö")
|
|
||||||
str = string.gsub( str, "Uuml;", "Ü")
|
|
||||||
str = string.gsub( str, "ü", "ü")
|
|
||||||
str = string.gsub( str, "ß", "ß")
|
|
||||||
str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
|
|
||||||
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
|
|
||||||
str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others
|
|
||||||
return str
|
|
||||||
end
|
|
||||||
|
|
||||||
function url_encode(str)
|
function url_encode(str)
|
||||||
if (str) then
|
if (str) then
|
||||||
str = string.gsub (str, "\n", "\r\n")
|
str = string.gsub (str, "\n", "\r\n")
|
||||||
|
Reference in New Issue
Block a user