Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.25 KB | None | 0 0
  1. ##############################################################################################
  2. ## ## rssreader.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
  3. ##############################################################################################
  4. ## .rss in the party line for commands and syntax. Example Feed Add Below: ##
  5. ##.rss add #Hawkee hawkee Hawkee http://www.hawkee.com/comment.rss.php?tool_type=snippet_id ##
  6. ##############################################################################################
  7. ## ____ __ ########################################### ##
  8. ## / __/___ _ ___ _ ___/ /____ ___ ___ ########################################### ##
  9. ## / _/ / _ `// _ `// _ // __// _ \ / _ \ ########################################### ##
  10. ## /___/ \_, / \_, / \_,_//_/ \___// .__/ ########################################### ##
  11. ## /___/ /___/ /_/ ########################################### ##
  12. ## ########################################### ##
  13. ##############################################################################################
  14. ## ## Start Setup. ## ##
  15. ##############################################################################################
  16. namespace eval rssreader {
  17. ## Edit textf to change the color/state of the text shown ## ##
  18. variable textf "\017\00304"
  19. ## Edit linkf to change the color/state of the links ## ##
  20. variable linkf "\017\037"
  21. ## Change usetiny to shorten links with tinyurl. 1 = on , 0 = off ## ##
  22. variable usetiny 1
  23. ## Change useisgd to shorten links with is.gd. 1 = on , 0 = off ## ##
  24. variable useisgd 0
  25. ## Edit maxresults to the amount of results you want per query. This will not cause ## ##
  26. ## You to lose results. It will only spread them out over several querys. ## ##
  27. variable maxresults 2
  28. ## Edit checkdelay to change the frequency feed pages are checked. Delay is in minutes. ## ##
  29. variable checkdelay 3
  30. ## Edit startupdelay to add delay to startup/restart. Delay is in minutes. ## ##
  31. variable startupdelay 2
  32. ##############################################################################################
  33. ## ## End Setup. ## ##
  34. ##############################################################################################
  35. bind dcc - rss rssreader::settings
  36. bind evnt -|- init-server rssreader::loadhash
  37. bind evnt -|- prerehash rssreader::loadhash
  38. proc settings {hand idx text} {
  39. set choice [lindex $text 0]; set channel [lindex $text 1]
  40. set name [lindex $text 2]; set logo [lindex $text 3]
  41. set link [lindex $text 4]
  42. if {[string equal -nocase "add" $choice] && $link != ""} {
  43. set deleteinfo [string map {\[ ? \] ?} [hget "rssreader" $name]]
  44. if {[set indx [lsearch -glob [timers] "*$deleteinfo*"]] != -1 && $deleteinfo != "0"} {
  45. killtimer [lindex [lindex [timers] $indx] 2]
  46. }
  47. hadd "rssreader" "$name" "rssreader::main {$channel $logo $link}"
  48. savehash
  49. putdcc $idx "Added feed $name to $channel as $logo $link"
  50. rssreader::main "$channel $logo $link"
  51. } elseif {[string equal -nocase "addxml" $choice] && $link != ""} {
  52. set deleteinfo [string map {\[ ? \] ?} [hget "rssreader" $name]]
  53. if {[set indx [lsearch -glob [timers] "*$deleteinfo*"]] != -1 && $deleteinfo != "0"} {
  54. killtimer [lindex [lindex [timers] $indx] 2]
  55. }
  56. hadd "rssreader" "$name" "rssreader::type2 {$channel $logo $link}"
  57. savehash
  58. putdcc $idx "Added feed $name to $channel as $logo $link"
  59. rssreader::type2 "$channel $logo $link"
  60. } elseif {[string equal -nocase "addssl" $choice] && $link != ""} {
  61. set deleteinfo [string map {\[ ? \] ?} [hget "rssreader" $name]]
  62. if {[set indx [lsearch -glob [timers] "*$deleteinfo*"]] != -1 && $deleteinfo != "0"} {
  63. killtimer [lindex [lindex [timers] $indx] 2]
  64. }
  65. hadd "rssreader" "$name" "rssreader::type3 {$channel $logo $link}"
  66. savehash
  67. putdcc $idx "Added feed $name to $channel as $logo $link"
  68. rssreader::type3 "$channel $logo $link"
  69. } elseif {[string equal -nocase "list" $choice]} {
  70. putdcc $idx "\[RSS list\]"
  71. set count [hfind "rssreader" "*" 0]; set counter 1
  72. while {$count >= $counter} {
  73. putdcc $idx "[hfind "rssreader" "*" $counter]"
  74. incr counter
  75. }
  76. } elseif {[string equal -nocase "info" $choice] && $channel != ""} {
  77. putdcc $idx "[hget "rssreader" $channel]"
  78. } elseif {[string equal -nocase "delete" $choice] && $channel != ""} {
  79. set deleteinfo [string map {\[ ? \] ?} [hget "rssreader" $channel]]
  80. hdel "rssreader" $channel
  81. savehash
  82. if {[set indx [lsearch -glob [timers] "*$deleteinfo*"]] != -1 && $deleteinfo != "0"} {
  83. killtimer [lindex [lindex [timers] $indx] 2]
  84. putdcc $idx "Removed $channel from RSS"
  85. } else {
  86. putdcc $idx "$channel not found"
  87. }
  88. } elseif {[string equal -nocase "timers" $choice]} {
  89. putdcc $idx [timers]
  90. } elseif {[string equal -nocase "rehash" $choice]} {
  91. putdcc $idx "rehashing rss...."
  92. hfree rsstempold
  93. hfree rsstempnew
  94. putdcc $idx "done"
  95. } else {
  96. putdcc $idx "\[RSS Syntax\]"
  97. putdcc $idx "Add Feed: .rss add <#chan1,#chan2,#chanetc> <name> <logo> <link>"
  98. putdcc $idx "Add Xml Feed: .rss addxml <#chan1,#chan2,#chanetc> <name> <logo> <link>"
  99. putdcc $idx "Add SSL Feed: .rss addssl <#chan1,#chan2,#chanetc> <name> <logo> <link>"
  100. putdcc $idx "Delete Feed: .rss delete <name>"
  101. putdcc $idx "Info Feed: .rss info <name>"
  102. putdcc $idx "List Feeds: .rss list"
  103. putdcc $idx "Help Feeds: .rss"
  104. }
  105. }
  106. proc main {text} {
  107. set chan [lindex $text 0]; set logo [lindex $text 1]; set linker [lindex $text 2]
  108. set title ""; set link ""; set description ""; set maxcount 1; set json ""
  109. if {[set indx [lsearch -glob [timers] "*rssreader::main {$chan [string map {\[ ? \] ?} $logo] ${linker}}*"]] != -1} {
  110. killtimer [lindex [lindex [timers] $indx] 2]
  111. }
  112. timer $rssreader::checkdelay "rssreader::main {$chan $logo $linker}"
  113. set rssreaderurl "/ajax/services/feed/load?v=1.0&q=${linker}"
  114. set rssreadersite "ajax.googleapis.com"; set rssout ""
  115. if {[catch {set rssreadersock [socket -async $rssreadersite 80]} sockerr]} {
  116. return 0
  117. } else {
  118. puts $rssreadersock "GET $rssreaderurl HTTP/1.0"
  119. puts $rssreadersock "Host: $rssreadersite"
  120. puts $rssreadersock "User-Agent: Opera 9.6"
  121. puts $rssreadersock "Connection: close"
  122. puts $rssreadersock ""
  123. flush $rssreadersock
  124. while {![eof $rssreadersock]} {
  125. set rssreadervar " [string map {<![CDATA[ "" ]]> "" \$ \002\$\002 \[ \( \] \)} [gets $rssreadersock]] "
  126. if {[regexp {\"responseStatus\":\s?400} $rssreadervar]} {
  127. if {[set indx [lsearch -glob [timers] "*rssreader::main {$chan $logo ${linker}}*"]] != -1} {
  128. killtimer [lindex [lindex [timers] $indx] 2]
  129. }
  130. type2 "$chan $logo $linker"
  131. close $rssreadersock
  132. return
  133. } else {
  134. regexp {\:\[(\{.*)$} $rssreadervar match rssout
  135. set rssout [regexp -all -inline {\{(.*?)\}} $rssout]
  136. if {$rssout != ""} {
  137. set count 0
  138. foreach {match matched} $rssout {
  139. incr count
  140. set matched [regexp -all -inline {(".*?":".*?"\,)} $match]
  141. foreach {innermatch innermatched} $matched {
  142. regexp {\"(.*?)\":\".*?\"\,} $innermatch match varname
  143. regexp {\".*?\":\"(.*?)\"\,} $innermatch match value
  144. set value [string map {\$ \002\$\002 \] \002\]\002 \[ \002\[\002} $value]
  145. set $varname $value
  146. }
  147. if {[hfindexact "rsstempold" "${link}" 1] != $link} {
  148. if {$title == ""} { set title $description }
  149. set linked $link
  150. if {$rssreader::usetiny} { set linked [string trimright [tiny $link]] }
  151. if {$rssreader::useisgd} { set linked [string trimright [isgd $link]] }
  152. if {$maxcount <= $rssreader::maxresults} {
  153. putserv "PRIVMSG $chan :${logo} ${rssreader::textf}[dehex $title] ${rssreader::linkf}${linked}"
  154. incr maxcount
  155. hadd "rsstempnew" $link 1
  156. }
  157. }
  158. }
  159. hfree rsstempold
  160. hcopy rsstempnew rsstempold
  161. rssreader::savetemphash
  162. }
  163. }
  164. }
  165. close $rssreadersock
  166. }
  167. }
  168. proc type2 {text} {
  169. set chan [lindex $text 0]; set logo [lindex $text 1]; set linker [lindex $text 2]
  170. set title ""; set link ""; set description ""
  171. if {[set indx [lsearch -glob [timers] "*rssreader::type2 {$chan [string map {\[ ? \] ?} $logo] ${linker}}*"]] != -1} {
  172. killtimer [lindex [lindex [timers] $indx] 2]
  173. }
  174. timer $rssreader::checkdelay "rssreader::type2 {$chan $logo $linker}"
  175. regexp -- {https?\:\/\/(.*?)(\/.*)$} $linker wholematch rsstype2site rsstype2url
  176. set itemfound 0 ; set maxcount 1
  177. if {[catch {set rsstype2sock [socket -async $rsstype2site 80]} sockerr]} {
  178. return 0
  179. } else {
  180. puts $rsstype2sock "GET $rsstype2url HTTP/1.0"
  181. puts $rsstype2sock "Host: $rsstype2site"
  182. puts $rsstype2sock "User-Agent: Opera 9.6"
  183. puts $rsstype2sock "Connection: close"
  184. puts $rsstype2sock ""
  185. flush $rsstype2sock
  186. while {![eof $rsstype2sock]} {
  187. set rsstype2var " [string map {<![CDATA[ "" ]]> "" \$ \002\$\002 \[ \( \] \)} [gets $rsstype2sock]] "
  188. if {[string match {*<item>*} $rsstype2var]} { set itemfound 1 }
  189. if {[regexp {<title>(.*?)(?:<\/title>|$)} $rsstype2var match title]} { }
  190. if {[regexp {<link>(.*?)(?:<\/link>|$)} $rsstype2var match link]} { }
  191. if {[string match {*</item>*} $rsstype2var]} {
  192. if {[hfindexact "rsstempold" "${link}" 1] != $link} {
  193. if {$itemfound} {
  194. if {$maxcount <= $rssreader::maxresults} {
  195. set linked $link
  196. if {$rssreader::usetiny} { set linked [string trimright [tiny $link]] }
  197. if {$rssreader::useisgd} { set linked [string trimright [isgd $link]] }
  198. putserv "PRIVMSG $chan :${logo} ${rssreader::textf}[dehex $title] ${rssreader::linkf}${linked}"
  199. incr maxcount
  200. hadd "rsstempnew" $link 1
  201. }
  202. }
  203. }
  204. }
  205. }
  206. set itemfound 0
  207. hfree rsstempold
  208. hcopy rsstempnew rsstempold
  209. rssreader::savetemphash
  210. close $rsstype2sock
  211. }
  212. }
  213. proc type3 {text} {
  214. set chan [lindex $text 0]; set logo [lindex $text 1]; set linker [lindex $text 2]
  215. set title ""; set link ""; set description ""
  216. if {[set indx [lsearch -glob [timers] "*rssreader::type3 {$chan [string map {\[ ? \] ?} $logo] ${linker}}*"]] != -1} {
  217. killtimer [lindex [lindex [timers] $indx] 2]
  218. }
  219. timer $rssreader::checkdelay "rssreader::type3 {$chan $logo $linker}"
  220. regexp -- {https?\:\/\/(.*?)(\/.*)$} $linker wholematch rsstype3site rsstype3url
  221. set itemfound 0 ; set maxcount 1 ; set count 1 ; set counter 1
  222. ::http::register https 443 tls::socket
  223. set type3searchtoken [::http::geturl "https://${rsstype3site}${rsstype3url}"]
  224. set type3searchdata [string map {<!\[CDATA\[ \"\" \]\]> "" \$ \\\$ \[ \\\[ \] \\\]} [::http::data $type3searchtoken]]
  225. ::http::cleanup $type3searchtoken
  226. ::http::unregister https
  227. set title [regexp -all -inline {<title>(.*?)<\/title>} $type3searchdata]
  228. set link [regexp -all -inline {<link>(.*?)<\/link>} $type3searchdata]
  229. while {$counter <= [llength $title]} {
  230. set thislink [lindex ${link} $counter]
  231. if {[hfindexact "rsstempold" "${thislink}" 1] != $thislink} {
  232. if {$maxcount <= $rssreader::maxresults} {
  233. set linked $thislink
  234. if {$rssreader::usetiny} { set linked [string trimright [tiny $thislink]] }
  235. if {$rssreader::useisgd} { set linked [string trimright [isgd $thislink]] }
  236. putserv "PRIVMSG $chan :${logo} ${rssreader::textf}[dehex [lindex $title $counter]] ${rssreader::linkf}${linked}"
  237. hadd "rsstempnew" $thislink 1
  238. incr maxcount 1
  239. }
  240. incr count 2
  241. }
  242. incr counter 2
  243. }
  244. hfree rsstempold
  245. hcopy rsstempnew rsstempold
  246. rssreader::savetemphash
  247. }
  248. proc tiny {link} {
  249. set tinysite tinyurl.com
  250. set tinyurl /api-create.php?url=[urlencode ${link}]
  251. if {[catch {set tinysock [socket -async $tinysite 80]} sockerr]} {
  252. putlog "$tinysite $tinyurl $sockerr error"
  253. return $link
  254. } else {
  255. puts $tinysock "GET $tinyurl HTTP/1.0"
  256. puts $tinysock "Host: $tinysite"
  257. puts $tinysock "User-Agent: Opera 9.6"
  258. puts $tinysock "Connection: close"
  259. puts $tinysock ""
  260. flush $tinysock
  261. while {![eof $tinysock]} {
  262. set tinyvar " [gets $tinysock] "
  263. if {[regexp {(http:\/\/.*)} $tinyvar match tinyresult]} {
  264. close $tinysock
  265. return [string map {http:// https://} $tinyresult]
  266. }
  267. }
  268. close $tinysock
  269. return $link
  270. }
  271. }
  272. proc isgd {link} {
  273. set isgdsite is.gd
  274. set isgdurl /create.php?format=simple&url=[urlencode ${link}]
  275. if {[catch {set isgdsock [socket -async $isgdsite 80]} sockerr]} {
  276. putlog "$isgdsite $isgdurl $sockerr error"
  277. return $link
  278. } else {
  279. puts $isgdsock "GET $isgdurl HTTP/1.0"
  280. puts $isgdsock "Host: $isgdsite"
  281. puts $isgdsock "User-Agent: Opera 9.6"
  282. puts $isgdsock "Connection: close"
  283. puts $isgdsock ""
  284. flush $isgdsock
  285. while {![eof $isgdsock]} {
  286. set isgdvar " [gets $isgdsock] "
  287. if {[regexp {(http:\/\/.*)} $isgdvar match isgdresult]} {
  288. close $isgdsock
  289. return $isgdresult
  290. }
  291. }
  292. close $isgdsock
  293. return $link
  294. }
  295. }
  296. proc hex {decimal} { return [format %x $decimal] }
  297. proc decimal {hex} { return [expr 0x$hex] }
  298. proc dehex {string} {
  299. regsub -all {^\{|\}$} $string "" string
  300. set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} $string {[format %c [decimal \1]]}]]
  301. set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} $string {[format %c [decimal \1]]}]]
  302. set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  303. set string [subst [regsub -nocase -all {\&#x([0-9]{2});} $string {[format %c [decimal \1]]}]]
  304. set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002 &ndash; – &raquo; \
  305. » &laquo; « &Uuml; Ü &uuml; ü &Aacute; Á &aacute; á &Eacute; É &eacute; é &Iacute; Í &iacute; \
  306. í &Oacute; Ó &oacute; ó &Ntilde; Ñ &ntilde; ñ &Uacute; Ú &uacute; ú &aelig; æ &nbsp; " " &apos; \' \
  307. \( \002\(\002 \) \002\)\002 \{ \002\{\002 \} \002\}\002} $string]
  308. return $string
  309. }
  310. proc urlencode {string} {
  311. regsub -all {^\{|\}$} $string "" string
  312. return [subst [regsub -nocase -all {([^a-z0-9\+])} $string {%[format %x [scan "\\&" %c]]}]]
  313. }
  314. proc hadd {hashname hashitem hashdata } {
  315. global $hashname
  316. set ${hashname}($hashitem) $hashdata
  317. }
  318. proc hget {hashname hashitem} {
  319. upvar #0 $hashname hgethashname
  320. if {[info exists hgethashname($hashitem)]} {
  321. return $hgethashname($hashitem)
  322. } else {
  323. return 0
  324. }
  325. }
  326. proc hfind {hashname search value} {
  327. upvar #0 $hashname hfindhashname
  328. if {[array exists hfindhashname]} {
  329. if {$value == 0} {
  330. return [llength [array names hfindhashname $search]]
  331. } else {
  332. set value [expr $value - 1]
  333. return [lindex [array names hfindhashname $search] $value]
  334. }
  335. }
  336. }
  337. proc hfindexact {hashname search value} {
  338. upvar #0 $hashname hfindhashname
  339. if {[array exists hfindhashname]} {
  340. if {$value == 0} {
  341. return [llength [array names hfindhashname -exact $search]]
  342. } else {
  343. set value [expr $value - 1]
  344. return [lindex [array names hfindhashname -exact $search] $value]
  345. }
  346. }
  347. }
  348. proc hsave {hashname filename} {
  349. upvar #0 $hashname hsavehashname
  350. if {[array exists hsavehashname]} {
  351. set hsavefile [open $filename w]
  352. foreach {key value} [array get hsavehashname] {
  353. puts $hsavefile "${key}=${value}"
  354. }
  355. close $hsavefile
  356. }
  357. }
  358. proc hload {hashname filename} {
  359. upvar #0 $hashname hloadhashname
  360. hfree $hashname
  361. set hloadfile [open $filename]
  362. set linenum 0
  363. while {[gets $hloadfile line] >= 0} {
  364. if {[regexp -- {([^\s]+)=(.*)$} $line wholematch item data]} {
  365. set hloadhashname($item) $data
  366. }
  367. }
  368. close $hloadfile
  369. }
  370. proc hfree {hashname} {
  371. upvar #0 $hashname hfreehashname
  372. if {[array exists hfreehashname]} {
  373. foreach key [array names hfreehashname] {
  374. unset hfreehashname($key)
  375. }
  376. }
  377. }
  378. proc hdel {hashname hashitem} {
  379. upvar #0 $hashname hdelhashname
  380. if {[info exists hdelhashname($hashitem)]} {
  381. unset hdelhashname($hashitem)
  382. }
  383. }
  384. proc hcopy {hashfrom hashto} {
  385. upvar #0 $hashfrom hashfromlocal $hashto hashtolocal
  386. array set hashtolocal [array get hashfromlocal]
  387. }
  388. proc savetemphash {} {
  389. hsave "rsstempnew" "${::network}rsstemp.hsh"
  390. }
  391. proc savehash {} {
  392. hsave "rssreader" "${::network}rssreader.hsh"
  393. }
  394. proc loadhash {type} {
  395. if {[file exists "${::network}rssreader.hsh"]} {
  396. rssreader::hload "rssreader" "${::network}rssreader.hsh"
  397. }
  398. if {[file exists "${::network}rsstemp.hsh"]} {
  399. rssreader::hload "rsstempnew" "${::network}rsstemp.hsh"
  400. rssreader::hload "rsstempold" "${::network}rsstemp.hsh"
  401. }
  402. set count $rssreader::startupdelay
  403. foreach {key value} [array get ::rssreader] {
  404. if {[set indx [lsearch -glob [timers] "*$value*"]] != -1} {
  405. killtimer [lindex [lindex [timers] $indx] 2]
  406. }
  407. timer $count $value
  408. incr count
  409. }
  410. }
  411. }
  412. putlog "\002*Loaded* \017\00304\002RSS Reader\017 \002by \
  413. Ford_Lawnmower irc.GeekShed.net #Script-Help .rss for help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement