84 lines
3.5 KiB
Lua
84 lines
3.5 KiB
Lua
-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
|
|
-- DO NOT USE WITHOUT PERMISSION
|
|
|
|
-- DIES IST EINE PREVIEW!
|
|
|
|
-- Ok Leute, ich zeig euch mal, wie der Hase läuft:
|
|
-- 1. Erstelle die Datei data/feeds.lua
|
|
-- 2. Paste das rein: https://wiidatabase.de/paste/?0772d759b7b49773#7ubf6C8IP78JoafaPK/XrnhhL03cvDgIUCQULTQNYIs=
|
|
-- 3. Du kannst mehr Feeds hinzufügen - mehr Feeds gehen mehr auf die Perfomance und können schnell nerven, also vorsicht! Ich empfehle 2-3
|
|
-- (die Feeds und Feednamen kannst du natürlich beliebig verändern, vergiss nicht, dass das Komma hinter dem letzten Feed weg muss!)
|
|
-- 4. Erstelle die Datei data/feeddata.lua
|
|
-- 5. Paste das rein: https://wiidatabase.de/paste/?87e36c6a5e2ae337#SGE2KLMJL1+oJ8gmLhHav4WxMqU1gYvIyWZxXJQHg7k=
|
|
-- 6. Ersetze die Variablen ("wiidatabase", "heise") durch deine Variablen aus der feeds.lua. Zwischen den '' sollte nichts stehen
|
|
-- 7. Ändere hier deine IP und die chat#id
|
|
-- 8. Starte den Bot, er holt sich die Feeds und schreibt deine feeddata.lua neu
|
|
|
|
do
|
|
|
|
local socket = require('socket')
|
|
local _file_feeddata = './data/feeddata.lua'
|
|
|
|
function get_feed_data(feed_url)
|
|
-- You don't need any IP, but Google won't block you, if you provide one!
|
|
local userip = '84.144.215.197' -- plz change to your IP or leave blank
|
|
local url = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q='..feed_url..'&hl=de&num=1&userip='..userip
|
|
|
|
local res,code = https.request(url)
|
|
if code ~= 200 then return "HTTP-FEHLER" end
|
|
local data = json:decode(res).responseData.feed
|
|
return data
|
|
end
|
|
|
|
function unescape(str)
|
|
str = string.gsub( str, '<', '<' )
|
|
str = string.gsub( str, '>', '>' )
|
|
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 check_feed(msg, matches)
|
|
local dest = "chat#id9587278" -- Plz change this, you can find your group id with "chat_info GROUP_NAME"
|
|
local _file_rss = loadfile ("./data/feeddata.lua")()
|
|
local _file_feeds = loadfile ("./data/feeds.lua")()
|
|
feeddata = io.open(_file_feeddata, "w")
|
|
feeddata:write("do local _ = {\n")
|
|
|
|
-- loop through feeds.lua
|
|
for int_feedname, feed_url in pairs(_file_feeds) do
|
|
local data = get_feed_data(feed_url)
|
|
print(data.title)
|
|
print('Erhalten: '..data.entries[1].link)
|
|
print('Gespeichert: '.._file_rss[int_feedname]..'\n')
|
|
if data.entries[1].link ~= _file_rss[int_feedname] then
|
|
local link = data.entries[1].link
|
|
local feed_title = data.title
|
|
local title = data.entries[1].title
|
|
local content = string.sub(unescape(data.entries[1].content:gsub("%b<>", "")), 1, 250) .. '...'
|
|
local text = title..'\n'..content..'\n\n -- '..link..' ('..feed_title..')'
|
|
|
|
send_msg(dest, text, ok_cb, false)
|
|
feeddata:write(" "..int_feedname.." = '"..link.."',\n")
|
|
else
|
|
-- //TODO: find a better way to rewrite lua when the feed is not updated
|
|
feeddata:write(" "..int_feedname.." = '"..data.entries[1].link.."',\n") -- ew, I hate this workaround
|
|
end
|
|
end
|
|
feeddata:write(" Ende = Ende\n") -- Dirty hack, remember me to not show this to anybody
|
|
feeddata:write("}\nreturn _\nend")
|
|
feeddata:close()
|
|
end
|
|
|
|
return {
|
|
description = "Sendet RSS-Feeds (public preview)",
|
|
usage = "",
|
|
patterns = {},
|
|
run = run,
|
|
cron = check_feed
|
|
}
|
|
|
|
end |