Код
-- Общие настройки
sBotName = "" -- Имя бота. Если "" то имя основного бота хаба.
bTimer = 1 -- Выдача по таймеру (в минутах).
AntiFl = 50 -- Если в чате было написано столько или более сообщений за время таймера, то новости не будут выданы.
StartDay = 3 -- С какого часа до полуночи скрипт будет выдавать новости.
sAddr = {
{"http://xox.uz/rss.xml","windows-1251","1"},
{"http://kids.xox.uz/engine/rss.php","windows-1251","2"},
{"http://news.olam.uz/rss/all.rss","windows-1251","3"},
}
---------------------------
function OnStartup()
if sBotName == "" then sBotName = SetMan.GetString(21) end
tmr = TmrMan.AddTimer(bTimer*60000)
sMsg1,sMsg2,sOldDesc1,sOldDesc2,n = "","","","",0
end
function ChatArrival()
n = n+1
collectgarbage("collect")
end
function OnTimer(tmr)
local hour = tonumber(os.date("%H"))
if (n <= AntiFl) and (hour >= StartDay) then
http = require("socket.http")
assert(http,"Ошибка загрузки библиотеки socket.http. Проверьте наличие файлов необходимых библиотек.")
http.TIMEOUT = 3
for i in pairs(sAddr) do
local msg = http.request(sAddr[i][1])
if msg then
if (sAddr[i][3]) == "1" then
_,_,Link,Description = string.find(msg,"<item>.-<link>(.-)</link>.-<description>(.-)</p.-</item>(.*)")
if Link and Description then
sMsg = Description
if Description == sOldDesc1 then sMsg1 = ""
else
sOldDesc1 = Description
RepChars()
if (sAddr[i][2]) == "UTF-8" then sMsg = Utf8ToAnsi(sMsg) end
sMsg1 = "RSS "..sMsg.."\n\t\tПодробности: "..Link
end
end
end
if (sAddr[i][3]) == "2" then
_,_,Link,Description = string.find(msg,"<item>.-<link>(.-)</link>.-<description>(.-)</description>.-</item>(.*)")
if Link and Description then
sMsg = Description
if Description == sOldDesc2 then sMsg2 = ""
else
sOldDesc2 = Description
RepChars()
if (sAddr[i][2]) == "UTF-8" then sMsg = Utf8ToAnsi(sMsg) end
sMsg2 = "RSS "..sMsg.."\n\t\tПодробности: "..Link
end
end
end
if (sAddr[i][3]) == "3" then
_,_,Link,Description = string.find(msg,"<item>.-<link>(.-)</link>.-<description>(.-)</description>.-</item>(.*)")
if Link and Description then
sMsg = Description
if Description == sOldDesc3 then sMsg3 = ""
else
sOldDesc3 = Description
RepChars()
if (sAddr[i][2]) == "UTF-8" then sMsg = Utf8ToAnsi(sMsg) end
sMsg3 = "RSS "..sMsg.."\n\t\tПодробности: "..Link
end
end
end
end
end
if sMsg1 ~= "" or sMsg2 ~= "" or sMsg3 ~= "" then
if sMsg1 ~= "" and sMsg2 == "" and sMsg3 == "" then sMsg1 = "\n\n"..sMsg1.."\n" end
if sMsg2 ~= "" and sMsg1 == "" and sMsg3 == "" then sMsg2 = "\n\n"..sMsg2.."\n" end
if sMsg3 ~= "" and sMsg1 == "" and sMsg2 == "" then sMsg2 = "\n\n"..sMsg3.."\n" end
if sMsg1 ~= "" and sMsg2 ~= "" and sMsg3 ~= "" then
sMsg1 = "\n"..sMsg1.."\n"
sMsg2 = "\n"..sMsg2.."\n"
sMsg3 = "\n"..sMsg3.."\n"
end
Core.SendToAll("<"..sBotName..">"..sMsg1..sMsg2..sMsg3)
sMsg1 = ""
sMsg2 = ""
sMsg3 = ""
end
end
n = 0
collectgarbage("collect") return string.format("%-.2f Kb.",collectgarbage("count"))
end
function RepChars()
sMsg = string.gsub (sMsg, "__g", "ig")
sMsg = string.gsub (sMsg, ("%[b%]"), " ")
sMsg = string.gsub (sMsg, ("%[/b%]"), " ")
sMsg = string.gsub (sMsg, "<br>", "\r\n\t")
sMsg = string.gsub (sMsg, "<br />", "\r\n\t")
sMsg = string.gsub (sMsg, "<", "<")
sMsg = string.gsub (sMsg, ">", ">")
sMsg = string.gsub (sMsg, """, string.char (34))
sMsg = string.gsub (sMsg, "&", "")
sMsg = string.gsub (sMsg, " ", " ")
sMsg = string.gsub (sMsg, "nbsp;", " ")
sMsg = string.gsub (sMsg, "$", "$")
sMsg = string.gsub (sMsg, "'", "`")
sMsg = string.gsub (sMsg, "'", "`")
sMsg = string.gsub (sMsg, "|", "")
sMsg = string.gsub (sMsg, "|", "")
sMsg = string.gsub (sMsg, "<!%[CDATA%[", "")
sMsg = string.gsub (sMsg, "%]%]>", "")
sMsg = string.gsub (sMsg, "<a target=\"_blank\" href=", "")
sMsg = string.gsub (sMsg, ">paparazzi.ru</a>", " ")
sMsg = string.gsub (sMsg, "<strong>", "")
sMsg = string.gsub (sMsg, "</strong>", "")
sMsg = string.gsub (sMsg, "- <a href=", "")
sMsg = string.gsub (sMsg, "target=\"_blank\">", " ")
sMsg = string.gsub (sMsg, "</a> –", "")
sMsg = string.gsub (sMsg, "<p>","")
end
local utf8_decode={
[128]={[147]="\150",[148]="\151",[152]="\145",[153]="\146",[154]="\130",[156]="\147",[157]="\148",[158]="\132",[160]="\134",[161]="\135",[162]="\149",[166]="\133",[176]="\137",[185]="\139",[186]="\155"},
[130]={[172]="\136"},
[132]={[150]="\185",[162]="\153"},
[194]={[152]="\152",[160]="\160",[164]="\164",[166]="\166",[167]="\167",[169]="\169",[171]="\171",[172]="\172",[173]="\173",[174]="\174",[176]="\176",[177]="\177",[181]="\181",[182]="\182",[183]="\183",[187]="\187"},
[208]={[129]="\168",[130]="\128",[131]="\129",[132]="\170",[133]="\189",[134]="\178",[135]="\175",[136]="\163",[137]="\138",[138]="\140",[139]="\142",[140]="\141",[143]="\143",[144]="\192",[145]="\193",[146]="\194",[147]="\195",[148]="\196",
[149]="\197",[150]="\198",[151]="\199",[152]="\200",[153]="\201",[154]="\202",[155]="\203",[156]="\204",[157]="\205",[158]="\206",[159]="\207",[160]="\208",[161]="\209",[162]="\210",[163]="\211",[164]="\212",[165]="\213",[166]="\214",
[167]="\215",[168]="\216",[169]="\217",[170]="\218",[171]="\219",[172]="\220",[173]="\221",[174]="\222",[175]="\223",[176]="\224",[177]="\225",[178]="\226",[179]="\227",[180]="\228",[181]="\229",[182]="\230",[183]="\231",[184]="\232",
[185]="\233",[186]="\234",[187]="\235",[188]="\236",[189]="\237",[190]="\238",[191]="\239"},
[209]={[128]="\240",[129]="\241",[130]="\242",[131]="\243",[132]="\244",[133]="\245",[134]="\246",[135]="\247",[136]="\248",[137]="\249",[138]="\250",[139]="\251",[140]="\252",[141]="\253",[142]="\254",[143]="\255",[144]="\161",[145]="\184",
[146]="\144",[147]="\131",[148]="\186",[149]="\190",[150]="\179",[151]="\191",[152]="\188",[153]="\154",[154]="\156",[155]="\158",[156]="\157",[158]="\162",[159]="\159"},[210]={[144]="\165",[145]="\180"}
}
local nmdc = {
[36] = "$",
[124] = "|"
}
function Utf8ToAnsi(s)
local a, j, r, b = 0, 0, ""
for i = 1, s and s:len() or 0 do
b = s:byte(i)
if b < 128 then
if nmdc[b] then
r = r..nmdc[b]
else
r = r..string.char(b)
end
elseif a == 2 then
a, j = a - 1, b
elseif a == 1 then
a, r = a - 1, r..utf8_decode[j][b]
elseif b == 226 then
a = 2
elseif b == 194 or b == 208 or b == 209 or b == 210 then
j, a = b, 1
else
r = r.."_"
end
end
return r
end