cnn.tcl

cnn.tcl

Eggdrop tcl that connects to CNN rss and post on irc channel.

Postat de Copyright Categorie Review user Vizualizari Data
btc domsen sockopen Cod netestat 321 2023-12-24 23:45:39

# cnn.tcl v1.0 by domsen <domsen@domsen.org> (c)2oo4
#
# comments? bugs? ideas? requests? money? beer? 
# plz mail me or visit my homepage @ www.domsen.org
# visit #newsticker@ircnet
#
# props to thrill <jmildham59@hotmail.com> for the original script
# idea of an cnn newsfetcher. but i needed an own one to serve my
# needs :)
#
# v1.0 - fist public release
#
# cnntrigger - der trigger auf den der bot reagiert (public und message)
# cnnlimit - maximum der news die auf befehl geposted werden
# cnnnewspost  - 1 für newsposting, 0 für keines
# cnnchans  - die  chans in  denen das tcl aktiv  ist, "" für alle
# cnnnewspostlimit - maximum der news die geposted werden
# iscnnhub  - legt fest ob der bot newshub ist oder nicht
# cnnleafs  - die nicks der leafbots auf denen das leaf tcl läuft
#
####### config ######################

set cnntrigger ".cnn"
set cnnchans ""
set cnnlimit "10"
set cnnnewspostlimit "3"
set cnnnewspost "1"
set iscnnhub "0"
set cnnleafs ""

####### ende der config #############

bind msg - $cnntrigger msg_cnn
bind pub - $cnntrigger pub_cnn
bind time - "?0 * * * *" cnncheck

proc sendcnnnews { arg } {
global cnnleafs
foreach bot [bots] {
if {([lsearch -exact [string tolower $cnnleafs] [string tolower $bot]] != -1)} {
putbot $bot "cnn: $arg"
}}}

proc shrink { calc number string start bl} { return [expr [string first "$string" $bl $start] $calc $number] }


proc html { text } {
regsub -all "&uuml;" $text "ü" text
regsub -all "&ouml;" $text "ö" text
regsub -all "&auml;" $text "ä" text
regsub -all "&Uuml;" $text "Ü" text
regsub -all "&Ouml;" $text "Ö" text
regsub -all "&Auml;" $text "Ä" text
regsub -all "&szlig;" $text "ß" text
regsub -all "&quot;" $text "\"" text
regsub -all "&amp;" $text "&" text
regsub -all "<sub>" $text "" text
regsub -all "&lt;" $text "<" text
regsub -all "&gt;" $text ">" text
regsub -all "&#39;" $text "'" text
return $text
}


proc cnncheck {nick uhost hand chan arg} {
global cnnchans cnnnewspost iscnnhub cnnnewspostlimit
set counter 0
if {$cnnnewspost == 1 } {
putlog "cnn: suche nach neuer newsline"
set cnnlastnews "none"
if {[file exists cnn.hdl]} {
set temp [open "cnn.hdl" r]
set cnnlastnews "[gets $temp]"
if {$cnnlastnews == ""} { set cnnlastnews "none" }
close $temp
}
set temp [open "cnn.hdl" w+]
if {[catch {set sock [socket rss.syntechsoftware.com 80] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /cnn.xml HTTP/1.1"
puts $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
puts $sock "Host: rss.syntechsoftware.com"
puts $sock ""
flush $sock
set counter 0
while {[eof $sock] != 1} {
set bl [gets $sock]

if {[string first "<title>" $bl] != -1 && [string first "syntechsoft" $bl] == -1 } { set newsline [string range $bl 7 [shrink - 1 "</" 0 $bl]]}
if {[string first "<link>" $bl] != -1 && [string first "com/</link" $bl] == -1} {
set link [string range $bl [shrink + 1 "=http" 0 $bl] [shrink - 1 </ 0 $bl]]
puts $temp "[html $newsline] <$link>"
}}}
close $sock ; close $temp
if {$cnnlastnews == "none" } { putlog "cnn: headlinefile created" ; return 0 }
set temp [open "cnn.hdl" r]
while { [eof $temp] != 1 } {
set cnnneunews [gets $temp]
if {($cnnlastnews == $cnnneunews) || ($counter == $cnnnewspostlimit)} { close $temp;return 0 }
incr counter
foreach chan [channels] {
if {$cnnchans == "" } { putserv "privmsg $chan :(new cnn headline) $cnnneunews" }
if {$cnnchans != "" } {
if {([lsearch -exact [string tolower $cnnchans] [string tolower $chan]] != -1) || ($cnnchans == "")} {putserv "privmsg $chan :(new cnn headline) $cnnneunews"}
}
if { $iscnnhub == "1" } { sendcnnnews $cnnneunews }
}}}}


proc cnnnews {target limit} {
if {[catch {set sock [socket rss.syntechsoftware.com 80] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /cnn.xml HTTP/1.1"
puts $sock "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
puts $sock "Host: rss.syntechsoftware.com"
puts $sock ""
flush $sock
set counter 0
while {[eof $sock] != 1} {
set bl [gets $sock]
if {[string first "<title>" $bl] != -1 && [string first "syntechsoft" $bl] == -1 } { set newsline [string range $bl 7 [shrink - 1 "</" 0 $bl]]}
if {[string first "<link>" $bl] != -1 && [string first "com/</link" $bl] == -1} {
set link [string range $bl[shrink + 1 "=http" 0 $bl] [shrink - 1 </ 0 $bl]]
putserv "privmsg $target :[incr counter] [html $newsline] <$link>"
}
if {$counter == $limit} {close $sock ; return 0 }
}}}

proc msg_cnn { nick uhost hand arg } { global cnnlimit ; cnnnews $nick $cnnlimit }
proc pub_cnn { nick uhost hand chan arg } { global cnnchans cnnlimit ; if {([lsearch -exact [string tolower $cnnchans] [string tolower $chan]] != -1) || ($cnnchans == "")} { cnnnews $nick $cnnlimit }}

putlog "*** cnn.tcl v1.0 by domsen <domsen@domsen.org> succesfully loaded"

#[EOF]