- 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 feedparser = require("feedparser")
|
||||
require "./miku/encoding"
|
||||
|
||||
rss.command = 'rss <sub/del>'
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
local wordpress_recent_post = {}
|
||||
|
||||
wordpress_recent_post.triggers = {
|
||||
"^/([Aa][Kk][Aa]) (.+)$",
|
||||
"^/([Tt][Hh][Cc]) (.+)$",
|
||||
"^/([Pp][Ww]) (.+)$",
|
||||
"^/([Aa][Kk][Aa])$",
|
||||
"^/([Pp][Ww])$"
|
||||
}
|
||||
@ -11,8 +14,12 @@ local makeOurDate = function(dateString)
|
||||
return day..'.'..month..'.'..year
|
||||
end
|
||||
|
||||
function wordpress_recent_post:get_full_url(blog)
|
||||
local url = blog..'/?json=get_recent_posts'
|
||||
function wordpress_recent_post:get_full_url(blog, tag)
|
||||
if tag then
|
||||
url = blog..'/?json=get_search_results&search='..tag
|
||||
else
|
||||
url = blog..'/?json=get_recent_posts'
|
||||
end
|
||||
local doer = http
|
||||
if url:match('^https') then
|
||||
doer = https
|
||||
@ -20,16 +27,20 @@ function wordpress_recent_post:get_full_url(blog)
|
||||
local res, code = doer.request(url)
|
||||
if code ~= 200 then return nil end
|
||||
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 from = unescape(data.author.name)
|
||||
local title = encoding(data.title)
|
||||
local from = encoding(data.author.name)
|
||||
local posted_at = makeOurDate(data.date)
|
||||
local content = data.excerpt:match('<p>(.*)<span')
|
||||
if not content then
|
||||
content = data.excerpt:match('<p>(.*)</p>')
|
||||
end
|
||||
local content = unescape(content)
|
||||
if not content then
|
||||
content = ""
|
||||
else
|
||||
content = '\n'..encoding(content)..'...'
|
||||
end
|
||||
local url = data.url
|
||||
if data.thumbnail then
|
||||
image_url = data.thumbnail
|
||||
@ -37,20 +48,26 @@ function wordpress_recent_post:get_full_url(blog)
|
||||
image_url = nil
|
||||
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
|
||||
end
|
||||
|
||||
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'
|
||||
elseif matches[1]:match('[Pp][Ww]') then
|
||||
elseif blog:match('[Pp][Ww]') then
|
||||
blog = 'https://ponywave.de'
|
||||
elseif blog:match('[Tt][Hh][Cc]') then
|
||||
blog = 'http://homebrew.cloud'
|
||||
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
|
||||
utilities.send_reply(self, msg, config.errors.connection)
|
||||
return
|
||||
elseif text == 'NOTFOUND' then
|
||||
utilities.send_reply(self, msg, config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
if image_url then
|
||||
|
@ -15,6 +15,7 @@ redis = (loadfile './miku/redis.lua')()
|
||||
mime = (loadfile './miku/mimetype.lua')()
|
||||
OAuth = require 'OAuth'
|
||||
helpers = require 'OAuth.helpers'
|
||||
require('/miku/encoding')
|
||||
|
||||
http.timeout = 5
|
||||
https.timeout = 5
|
||||
@ -962,24 +963,6 @@ function convertNumbers(str)
|
||||
return str
|
||||
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)
|
||||
if (str) then
|
||||
str = string.gsub (str, "\n", "\r\n")
|
||||
|
Reference in New Issue
Block a user