package require http # remember this url: http://www.geeklog.net/staticpages/index.php?page=20030206094434245 namespace eval RDF { set Leaf "" set forceload 1 # search for "special1" or "special2" or "allother" # to change the output for your channels if {![info exists Sites] || $forceload} { set Sites [list] #lappend Sites "name url" lappend Sites "frozen-roms http://www.ponyfish.com/feeds/20300OyPXMvMH" # lappend Sites "AnimeSuki http://animesuki.com/rss.php" lappend Sites "BU.com http://www.baka-updates.com/rss.php" # lappend Sites "inGame http://ingame.de/staff/lucifer/xml/feed.php?id=3&type=RSS" set Sites [lsort -uni $Sites] } set Last(Init) 1; set LastDesc(Init) 1; set UsePrivmsg 1 set UseLeaf 1 set Chans "#cybex.test " # --- compat --- for tclsh -- if [info exist ::version] { set eggdrop 1 } { set eggdrop 0 } proc myputlog { args } { if $RDF::eggdrop { putlog $args } { puts $args } } proc myputcmdlog { args } { if $RDF::eggdrop { putcmdlog $args } { puts $args } } # --- load/save --- proc loadfile {name args} { if {[info exists name] && [file exists $name]} { set fh [open $name r] set gets [gets $fh] close $fh return $gets } { return "" } } proc savefile {name data} { set fh [open $name w] puts $fh $data close $fh } # --- proc --- proc randomizelist list { set l [llength $list] for {set i 0} {$i<=$l} {incr i} { set x [lindex $list [set p [rand $l]]] set list [lreplace $list $p $p] set list [linsert $list [rand $l] $x] } return $list } proc Randomize args { set RDF::Sites [randomizelist $RDF::Sites] } proc SendBot { args } { #myputcmdlog "RDF-SB: Send $args to Bots" if {$::botnick=="NewS-FlasH"} { postrdf $::botnick "RDF:" [join $args] } foreach bot [bots] { if {([lsearch -exact [string tolower $RDF::Leaf] [string tolower $bot]] != -1)} { putbot $bot "RDF: [join $args]" } } } proc GetRDF { args } { set query $args; #set cyagent "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98)"; set cyagent "CyNews/${RDF::Ver} (compatible; Linux)"; #set cyagent "Mozilla/4.0" set token [http::config -useragent $cyagent]; catch { set token [http::geturl $query -timeout 300] } error; if {$error!=$token} { return "-1 Error"; } puts stderr ""; upvar #0 $token state; set size [array size state]; set getstate [array get state]; if {[string tolower [lindex $state(http) 2]] != "ok"} { return "-1 $state(http)"; } set htmldata [http::data $token]; http::cleanup $token #myputcmdlog "GetRDF: before regsub" regsub -all {\[} $htmldata {(} htmldata regsub -all {\]} $htmldata {)} htmldata #regsub -all {\{} $htmldata {(} htmldata #regsub -all {\}} $htmldata {)} htmldata regsub -all {ä} $htmldata {ae} htmldata regsub -all {ö} $htmldata {oe} htmldata regsub -all {ü} $htmldata {ue} htmldata regsub -all {Ä} $htmldata {Ae} htmldata regsub -all {Ö} $htmldata {Oe} htmldata regsub -all {Ü} $htmldata {Ue} htmldata regsub -all {"} $htmldata {\'} htmldata regsub -all {&} $htmldata {\&} htmldata regsub -all {\&\#38;} $htmldata {\&} htmldata regsub -all {\&\#39;} $htmldata {\'} htmldata set htmldata [string map "{ä} {ä} {Ä} {Ä} {ä} {ä} {Ä} {Ä} {ö} {ö} {Ö} {Ö} {ö} {ö} {Ö} {Ö} {ü} {ü} {Ü} {Ü} {ü} {ü} {Ü} {Ü} {ß} {ß} {"} {\'} {’} {\'} {"} {\'} {&} {&} {€} {\200}" $htmldata] while {[regexp {^.*(&#\d+;).*$} $htmldata "" found]} { #putcmdlog "found $found" regexp {&#(\d+);} $found "" temp; set temp [string trimleft $temp " 0"]; #putcmdlog "set temp $temp" if {$temp==""} {set temp 0} set repl "" if {[string is digit $temp]} { set repl [format %c $temp] #putcmdlog "set replace $repl" } { #putcmdlog "remove $found ($temp), no digit" } set pos [lsearch [split $htmldata] *$found*] #putcmdlog "set pos $pos" if {$pos<0} {break} while {$pos>=0} { set htmldata [join [lreplace [split $htmldata] $pos $pos $repl]] set pos [lsearch [split $htmldata] *$found*] #putcmdlog "newtext: $found $pos $repl" } } set htmldata [string map "{ä} {ä} {Ä} {Ä} {ä} {ä} {Ä} {Ä} {ö} {ö} {Ö} {Ö} {ö} {ö} {Ö} {Ö} {ü} {ü} {Ü} {Ü} {ü} {ü} {Ü} {Ü} {ß} {ß} {"} {\'} {’} {\'} {"} {\'} {&} {&} {€} {\200}" $htmldata] #myputcmdlog "GetRDF: return" return $htmldata } proc CatchInfo { data {sitename ""} } { set lines [split $data \n] set item 0; set title 0; set link 0; set desc 0; set newlines [list] #myputcmdlog "Sitename: $sitename" #myputcmdlog "Catch-Data: $data" foreach line $lines { if {[string match -nocase "*.*} $newlines newlines Title] { set title 1; regsub -all {\{|\}} $Title {} Title regexp {^\>\<\!\(CDATA\((.*)\)\)\>} $Title "" Title regexp {^\>\<\!\(CDATA(.*)\)\>} $Title "" Title set Title [string range $Title [expr [string first ">" $Title]+1] end]; lappend ret "Title [string trim $Title]" } if [regexp {^.*.*} $newlines newlines Link] { set link 1; regsub -all {\{|\}} $Link {} Link regexp {^\>\<\!\(CDATA\((.*)\)\)\>} $Link "" Link regexp {^\>\<\!\(CDATA(.*)\)\>} $Link "" Link set Link [string map {{ } { }} $Link] set Link [string range $Link [expr [string first ">" $Link]+1] end]; lappend ret "Link [string trim $Link]" } if [regexp {^.*.*} $newlines newlines Desc] { set desc 1; regsub -all {\{|\}} $Desc {} Desc regexp {^\>\<\!\(CDATA\((.*)\)\)\>} $Desc "" Desc regexp {^\>\<\!\(CDATA(.*)\)\>} $Desc "" Desc set Desc [string range $Desc [expr [string first ">" $Desc]+1] end]; lappend ret "Desc [string trim $Desc]" } #myputcmdlog "CatchInfo: before regsub" #regsub -all $htmldata "\Ã\¼" htmldata {ü} regsub -all {\"} $ret {\'} ret regsub -all {\[} $ret {(} ret regsub -all {\]} $ret {)} ret #regsub -all {\{} $ret {(} ret #regsub -all {\}} $ret {)} ret regsub -all {ä} $ret {ae} ret regsub -all {ö} $ret {oe} ret regsub -all {ü} $ret {ue} ret regsub -all {Ä} $ret {Ae} ret regsub -all {Ö} $ret {Oe} ret regsub -all {Ü} $ret {Ue} ret regsub -all {"} $ret {\'} ret regsub -all {>} $ret {>} ret regsub -all {<} $ret {<} ret regsub -all {\&\#38;} $ret {\&} ret regsub -all {\&\#39;} $ret {\'} ret #myputcmdlog "CatchInfo: return" return $ret #return $newlines } proc Timer { { args "" } } { set Site [lindex $RDF::Sites 0]; set RDF::Sites [lreplace $RDF::Sites 0 0]; lappend RDF::Sites $Site if {![info exist RDF::Last([lindex $Site 0])]} { set RDF::Last([lindex $Site 0]) "" } #myputcmdlog "RDF::GetRDF $Site" set data [split [RDF::GetRDF [lindex $Site 1]] \n]; set arg0 [lindex $data 0] set Title ""; set Link ""; set Desc ""; if {$arg0!="-1" && $arg0!="-2" } { set info [RDF::CatchInfo [join $data \n] [lindex $Site 0]] foreach content $info { set [lindex $content 0] [join [lrange $content 1 end]] } set NDesc "" if {![info exists Title]} {set Title ""} if {![info exists Desc]} {set Desc ""} if {![info exists Link]} {set Link ""} set Title [string trim [stripcodes bcruag $Title]] set Desc [string trim [stripcodes bcruag $Desc]] set Link [string trim [stripcodes bcruag $Link]] if {$info!="" && $Title!="" && $RDF::Last([lindex $Site 0])!=$Title} { savefile "dat.LastNews" [array get RDF::Last] set RDF::Last([lindex $Site 0]) $Title if {[info exists Desc] && $Desc!=""} { if {![info exist RDF::LastDesc([lindex $Site 0])]} { set RDF::LastDesc([lindex $Site 0]) "" } if {$RDF::LastDesc([lindex $Site 0])!=$Desc} { savefile "dat.LastDesc" [array get RDF::LastDesc] set RDF::LastDesc([lindex $Site 0]) $Desc set NDesc $Desc; } } { set Desc ""; set NDesc "" } if {[string match -nocase *special1* $Site]} { set chans [list #special1 #and #more]; set Desc ""; set NDesc ""; putcmdlog "set chans $chans - $Site" } elseif {[string match -nocase *special2* $Site]} { set chans [list #special2 #and #more]; putcmdlog "set chans $chans - $Site"; set Desc ""; set NDesc ""; } {set chans [list #allother #and #more]; putcmdlog "set chans $chans - $Site"} set color [list]; set nocolor [list] foreach dest $chans { if {[string match *c* [lindex [split [getchanmode $dest]] 0]]} { lappend nocolor $dest } { lappend color $dest } } regsub -all -nocase {(.+?)} $Desc \002\\1\002 Desc if {$color!=[list]} { if {$NDesc!=""} { putmsg [join $color ,] "(\002[lindex $Site 0]\002) $Title - \037${Link}\037" putmsg [join $color ,] "${Desc}" #putmsg #randorr "[join $color ,] (\002[lindex $Site 0]\002) $Title - \037${Link}\037" #putmsg #randorr "[join $color ,] ${Desc}" } { putmsg [join $color ,] "(\002[lindex $Site 0]\002) $Title - \037${Link}\037" #putmsg #randorr "[join $color ,] (\002[lindex $Site 0]\002) $Title - \037${Link}\037" } } if {$nocolor!=[list]} { if {$NDesc!=""} { putmsg [join $nocolor ,] "([lindex $Site 0]) $Title - ${Link}" putmsg [join $nocolor ,] "[stripcodes bcruag ${Desc}]" #putmsg #randorr "[join $nocolor ,] ([lindex $Site 0]) $Title - ${Link}" #putmsg #randorr "[join $nocolor ,] [stripcodes bcruag ${Desc}]" } { putmsg [join $nocolor ,] "([lindex $Site 0]) $Title - ${Link}" #putmsg #randorr "[join $nocolor ,] ([lindex $Site 0]) $Title - ${Link}" } } } } } # --- init --- set Devel 0; set Debug 15; if {![info exist Ver]} {set Ver ""} proc Rehash {} { if {[info exist ::botnet-nick]} { if {${::botnet-nick}=="NewsFlash"} { set RDF::Devel 1 } } if {[info exist RDF::Ver] && $RDF::Devel && $RDF::Ver!=""} { set ver [split $RDF::Ver .]; set ver [lreplace $ver 2 2 [expr [lindex $ver 2]+1]]; set RDF::Ver [join $ver .]; myputcmdlog "Rehashed to version $RDF::Ver" } { set data [loadfile "dat.LastNews"] if {$data!=""} {array set RDF::Last $data} set data [loadfile "dat.LastDesc"] if {$data!=""} {array set RDF::LastDesc $data} set RDF::Ver "0.4.9" myputlog "RDF version $RDF::Ver by CyBex loaded (special for Randorr)" } return "$RDF::Ver"; } bind time - "*" RDF::Timer; bind time - "30 *" RDF::Randomize bind time - "00 *" RDF::Randomize } return [RDF::Rehash]