Guest User

Untitled

a guest
Dec 4th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.64 KB | None | 0 0
  1.  
  2. ;==================================================
  3. ; RSS Poster
  4. ; by Cobi
  5. ;==================================================
  6. ; Commands:
  7. ; /rss Starts the rss poster (shortcut for /loadrsshist and /rsscfg)
  8. ; /addrss name host webfile channel count interval -- adds feed to rss.cfg (Implies /rsstimer)
  9. ; /showrss name host webfile channel count -- shows rss feed in channel (Implies /getrss and /parserss)
  10. ;
  11. ; ----- The following are internal commands and should only be used if messing around with the code. -----
  12. ; /loadrsshist Loads the history file so as not to post the same stuff over and over
  13. ; /closersshist Unloads the history file...
  14. ; /reloadrsshist Shortcut for /closersshist and /loadrsshist
  15. ; /rsscfg Loads rss.cfg file and parses it (Implies /rsstimer on every rss feed listed)
  16. ; /rsstimer name host webfile channel count interval starts a rss timer for the specified settings
  17. ; (Implies /showrss each interval)
  18. ; /getrss name host webfile file done -- downloades an rss feed then runs done when it is done (Implies /fixrss)
  19. ; /fixrss file -- fixes rss feed format. This is done automatically, and should only be done when debugging.
  20. ; /parserss file name channel count -- parses rss file and displays it in a channel
  21. ;
  22. ; Arguements:
  23. ; name = Name of feed (used for displaying purposes)
  24. ; host = Where to get the feed ( http://hostwebfile e.g. http://example.com/test.xml example.com is the host and /test.xml is the webfile.. )
  25. ; webfile = file on host
  26. ; file = local rss file
  27. ; channel = channel to show rss postings in
  28. ; count = how many rss posts to show at once
  29. ; interval = how often (in seconds) to show rss posts
  30. ; done = what to do when done downloading file
  31. ;
  32. ; Examples:
  33. ;
  34. ; Add a few rss feeds:
  35. ; /addrss mirc.net mirc.net /rss.php?type=news #rss 6 600
  36. ; /addrss SourceForge images.feedstermedia.com /feedcache/ostg/sourceforge/rss_sfnews.xml #rss 6 600
  37. ; /addrss NPR www.npr.org /rss/rss.php?topicId=1001 #rss 6 600
  38. ; /addrss Moreover p.moreover.com /page?o=rss002&c=Top%20stories&wiz=230176 #rss 6 600
  39. ; /addrss Copyright www.copyright.gov /rss.xml #rss 6 600
  40. ; /addrss podcastingnews www.podcastingnews.com /index.xml #rss 6 600
  41. ; /addrss Infoworld www.infoworld.com /rss/news.xml #rss 6 600
  42. ; /addrss BarkerJr.Net barkerjr.net /rss?c=2;f=5 #RSS 2 600
  43. ; /addrss Linux-Security www.linuxsecurity.com /static-content/linuxsecurity_hybrid.rdf #rss 6 600
  44. ; /addrss Planet-Source-Code www.planet-source-code.com /vb/channel/NewCode/channel.cdf #rss 6 600
  45. ; /addrss /. slashdot.org /rss/index.rss #rss 6 600
  46. ; /addrss ZDnet news.zdnet.com /2509-1_22-0-20.xml #rss 6 600
  47. ; /addrss IRC101 www.irc101.org /tier2.xml #rss 6 600
  48. ; /addrss MSDN msdn.microsoft.com /msdnmag/rss/recent.xml #rss 6 600
  49. ; /addrss Microsoft www.microsoft.com /communities/rss.aspx?&Title=Recent+Posts&CMTYSvcSource=MSCOMBlogPosts&CMTYRawShape=list&Params=%7eCMTYDataSvcParams%5e%7eArg+Name%3d'DateFormat'+Value%3d'MMM+d%2c+yyyy'%2f%5e%7e%2fCMTYDataSvcParams%5e&NumberOfItems=50 #rss 6 600
  50. ; /addrss &color;01,00W&color;00,01I&color;01,00R&color;00,01E&color;01,00D&color; wired.com /news/feeds/rss2/0,2610,,00.xml #rss 6 600
  51. ; /addrss RTCW ict.mcast.edu.mt /ictweb/davidmica/web/rss.xml #rss 6 600
  52. ; /addrss jaos software.jaos.org /cgi-bin/rss #rss 6 600
  53. ;
  54. ; Reload the config file:
  55. ; /rehashrss
  56. ;
  57. ; Edit the config file:
  58. ; /run notepad rss.cfg
  59. ;
  60. ; Load the config file and start posting news:
  61. ; /rss
  62. ;
  63. ; Contact:
  64. ; Cobi on Undernet (#phase, #rss, #game-trivia)
  65. ; Cobi on Winbots (#winbots)
  66. ; Cobi-Wan-Kenobi on Quakenet (#icechat)
  67. ; Cobi on SearchIRC Forums
  68. ; Winbots on UnrealIRCd Forums
  69. ; Cobi on mirc.net
  70. ;
  71. ; ChangeLog:
  72. ; v1.3 -- fixed memory bug
  73. ; v1.2 -- fixed the issue when the tags are not one word (<title blah>blah</title>)
  74. ; v1.1 -- fixed rss.performance issue
  75. ; v1.0 -- Initial Release
  76.  
  77. alias rss { loadrsshist | rsscfg }
  78. alias closersshist { window -c @rss.hist | window -c @rss.performance }
  79. alias reloadrsshist { closersshist | loadrsshist }
  80. alias rsscfg {
  81. var %time = $ticks
  82. var %lcv2 = 0
  83. var %lcv = 1
  84. var %lines = $lines(rss.cfg)
  85. unset %list
  86. while (%lcv <= %lines) {
  87. if ($read(rss.cfg,%lcv)) {
  88. bunset &line
  89. bset -t &line 1 $read(rss.cfg,%lcv)
  90. if ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,\<(.+)\>(.+)\<\/.+\>)) {
  91. bunset &rss. $+ $regml(RSS,1)
  92. bset -t &rss. $+ $regml(RSS,1) 1 $regml(RSS,2)
  93. }
  94. elseif ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,\<\/item\>)) {
  95. rsstimer $bvar(&rss.feed,1,$bvar(&rss.feed,0)).text $bvar(&rss.host,1,$bvar(&rss.host,0)).text $bvar(&rss.file,1,$bvar(&rss.file,0)).text $bvar(&rss.channel,1,$bvar(&rss.channel,0)).text $bvar(&rss.feeds,1,$bvar(&rss.feeds,0)).text $bvar(&rss.interval,1,$bvar(&rss.interval,0)).text
  96. set %list %list $replacex($bvar(&rss.feed,1,$bvar(&rss.feed,0)).text,&amp;,&,&quot;,",&nbsp;,$chr(32),&color;,,&bold;,,&underline,)
  97. bunset &line &rss.*
  98. inc %Lcv2
  99. }
  100. }
  101. inc %lcv
  102. }
  103. if ($window(@rss.performance)) {
  104. aline @rss.performance ---
  105. aline @rss.performance Parsed %lcv Config Lines ( $+ %lcv2 rss entries) (rss.cfg) in $calc(($ticks - %time)/1000) Seconds
  106. }
  107. }
  108. alias rsstimer {
  109. ;$1 = feed name
  110. ;$2 = host
  111. ;$3 = file
  112. ;$4 = channel
  113. ;$5 = max
  114. ;$6 = interval
  115. showrss $1 $2 $3 $4 $5
  116. .timerrss. $+ $1 0 $6 showrss $1 $2 $3 $4 $5
  117. }
  118. alias showrss {
  119. ;$1 = feed name
  120. ;$2 = host
  121. ;$3 = file
  122. ;$4 = channel
  123. ;$5 = max
  124. set %time. $+ $1 $ticks
  125. .remove " $+ $1 $+ .rss $+ "
  126. getrss $1 $2 $3 $replace($1 $+ .rss,$chr(32),_) parserss $replace($1 $+ .rss,$chr(32),_) $1 $4 $5
  127. }
  128. alias getrss {
  129. ;$1 = feed name
  130. ;$2 = host
  131. ;$3 = file
  132. ;$4 = save
  133. ;$5- = done
  134. set %rss. $+ $1 $+ .file $3
  135. set %rss. $+ $1 $+ .host $2
  136. set %rss. $+ $1 $+ .save $4
  137. set %rss. $+ $1 $+ .done $5-
  138. sockopen rss. $+ $1 $2 80
  139. }
  140. on *:SOCKOPEN:rss.*:{
  141. sockwrite -tn $sockname GET % [ $+ [ $sockname $+ .file ] ] HTTP/1.1
  142. sockwrite -tn $sockname Host: % [ $+ [ $sockname $+ .host ] ]
  143. sockwrite -tn $sockname Accept: *.*, */*
  144. sockwrite -tn $sockname Connection: close
  145. sockwrite -tn $sockname $crlf
  146. }
  147. on *:sockclose:rss.*:{ fixrss % [ $+ [ $sockname $+ .save ] ] | % [ $+ [ $sockname $+ .done ] ] | unset % $+ $sockname $+ .* }
  148. on *:sockread:rss.*:{
  149. if ($sockerr) { echo 1 -a ERROR | return }
  150. if (% [ $+ [ $sockname $+ .status ] ] != downloading) {
  151. var %1 | sockread %1 | tokenize 32 %1
  152. if ($1 == HTTP/1.1) { if ($2 != 200 && $2 != 206) { echo 1 -a ERROR } }
  153. elseif ($1 == Content-Range:) { set % [ $+ [ $sockname $+ .size ] ] $gettok($3,-1,47) }
  154. elseif ($1 == Content-Type:) { return }
  155. elseif (!$1) {
  156. set % [ $+ [ $sockname $+ .status ] ] Downloading
  157. return
  158. }
  159. }
  160. else {
  161. var %1 = % [ $+ [ $sockname $+ .save ] ]
  162. :sockread
  163. sockread &1
  164. if (!$sockbr) { return }
  165. bwrite $+(",%1,") -1 &1
  166. unset % [ $+ [ $sockname $+ .resume ] ]
  167. }
  168. }
  169.  
  170. alias fixrss {
  171. ;$1 = rss file
  172. var %file = $1
  173. bread $1 0 $file($1).size &file
  174. breplace &file 10 32 13 32
  175. write -c $1
  176. var %lcv = 1
  177. var %size = $bvar(&file,0)
  178. while (%lcv <= %size) {
  179. parserss2 $1 $bvar(&file,%lcv,500).text
  180. inc %lcv 500
  181. }
  182. }
  183.  
  184. alias parserss {
  185. ;$1 = rss file
  186. ;$2 = feed name
  187. ;$3 = channel
  188. ;$4 = max
  189. var %time = $ticks | var %lcv = 1 | var %lcv2 = 0 | var %lines = $file($1).size
  190. bread $1 0 %lines &file1
  191. while ((%lcv <= %lines) && (%lcv2 < $4)) { bunset &line | bcopy -c &line 1 &file1 %lcv $calc($iif($bfind(&file1,%lcv,$crlf),$bfind(&file1,%lcv,$crlf),$calc(%lines + 1)) - %lcv) | var %lcv = $calc($iif($bfind(&file1,%lcv,$crlf),$bfind(&file1,%lcv,$crlf),$calc(%lines + 1)) + 2)
  192. if (($bvar(&line,0) < 300) && ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,\<(.+)\>(.+)\<\/.+\>))) { if (($regml(RSS,1)) && ($regml(RSS,2))) { bunset &rss. $+ $gettok($regml(RSS,1),1,32) | bset -t &rss. $+ $gettok($regml(RSS,1),1,32) 1 $regml(RSS,2) } }
  193. elseif (($bvar(&line,0) < 300) && ($regex(RSS,$bvar(&line,1,$bvar(&line,0)).text,\<\/item\>))) { checkalreadyrss $3 [[ $+ $2 $+ ]]  $+ $bvar(&rss.title,1,$bvar(&rss.title,0)).text $+  ( $bvar(&rss.link,1,$bvar(&rss.link,0)).text ) | inc %lcv2 | bunset &line &rss.* }
  194. }
  195. if ($window(@rss.performance)) {
  196. aline @rss.performance ---
  197. aline @rss.performance Parsed %lcv Bytes ( $+ %lcv2 rss entries) ( $+ $1 $+ ) in $calc(($ticks - %time)/1000) Seconds
  198. }
  199. if (%time. [ $+ [ $2 ] ]) { if ($window(@rss.performance)) {
  200. aline @rss.performance Downloaded and Parsed %lcv Bytes ( $+ %lcv2 rss entries) ( $+ $1 $+ ) in $calc(($ticks - %time. [ $+ [ $2 ] ] )/1000) Seconds } | unset %time. $+ $2 } }
  201.  
  202. alias addrss {
  203. ;$1 = feed name
  204. ;$2 = host
  205. ;$3 = file
  206. ;$4 = channel
  207. ;$5 = max
  208. ;$6 = interval
  209. write rss.cfg <item>
  210. write rss.cfg $chr(32) $+ $chr(32) $+ <feed> $+ $1 $+ </feed>
  211. write rss.cfg $chr(32) $+ $chr(32) $+ <host> $+ $2 $+ </host>
  212. write rss.cfg $chr(32) $+ $chr(32) $+ <file> $+ $3 $+ </file>
  213. write rss.cfg $chr(32) $+ $chr(32) $+ <channel> $+ $4 $+ </channel>
  214. write rss.cfg $chr(32) $+ $chr(32) $+ <feeds> $+ $5 $+ </feeds>
  215. write rss.cfg $chr(32) $+ $chr(32) $+ <interval> $+ $6 $+ </interval>
  216. write rss.cfg </item>
  217. rsstimer $1 $2 $3 $4 $5 $6
  218. }
  219. alias rehashrss {
  220. timerrss.* off
  221. rsscfg
  222. }
  223. alias rssoff {
  224. timerrss.* off
  225. closersshist
  226. }
  227. on 100:TEXT:!addrss * * * * * *:{ addrss $2 $3 $4 $5 $6 $7 }
  228. alias checkalreadyrss {
  229. if (sponsored isin $1-) { goto done }
  230. if ($file(rss.hist.tmp)) { .remove rss.hist.tmp }
  231. filter -ffc rss.hist rss.hist.tmp * $+ $strip($1-) $+ *
  232. if ($file(rss.hist.tmp)) { .remove rss.hist.tmp }
  233. if ($filtered > 0) { goto done }
  234. write rss.hist $strip($1-)
  235. ; if (!$window(@rss.hist)) { echo 4 -a $nopath($script) $+ : ERROR: no history loaded... (try /loadrsshist) | halt }
  236. ; aline @rss.hist $strip($1-)
  237. msg $replacex($1-,&amp;,&,&quot;,",&nbsp;,$chr(32),&color;,,&bold;,,&underline,)
  238. :done
  239. }
  240. alias loadrsshist {
  241. if (!$file(rss.hist).size) { write rss.hist History File }
  242. ; .window -k0lh @rss.hist
  243. ; .loadbuf @rss.hist rss.hist
  244. ; .window -k0 @rss.performance
  245. }
  246. alias parserss2 {
  247. ;$1 = File
  248. ;$2- = XML data
  249. var %file = $1
  250. ;[Code by FiberOPtics] Thanks.. :P
  251. var %a, %b = $regsub($2-,/(?<=>)(?=\s*<)/g,$lf,%a)
  252. tokenize 10 %a
  253. ;[/Code by FiberOPtics]
  254. var %lcv = 1
  255. while (%lcv <= $0) {
  256. bset -t &tmp $calc($bvar(&tmp,0) +1) $ [ $+ [ %lcv ] ] $+ $crlf
  257. inc %lcv
  258. }
  259. bwrite %file -1 $calc($bvar(&tmp,0) -2) &tmp
  260. bunset &tmp
  261. }
  262. on *:TEXT:!list:#:{ msg $chan I syndicate the following: | msg $chan %list }
Advertisement
Add Comment
Please, Sign In to add comment