# CrazyCat Programming Factory # ___ ____ ____ # / __)___( _ \ ___( ___) # ( (__(___))___/(___))__) # \___) (__) (__) # # http://www.c-p-f.org # ###################################### # # DirectNews.tcl 2.0 # ###################################### # # French news on IRC # ###################################### ## DESCRIPTION ## # # Ce tcl permet d'obtenir les informations # provenant de net2one directement sur un # canal IRC ## EVOLUTION ## # # Utilise désormais le package http.tcl # ce qui permet de le faire fonctionner # avec un windrop package require html ## CONFIGURATION ## # default bind command !actu, change to your liking bind msg - "!actu" news:direct bind pub - "!actu" news:error bind join - "#actu *" news:join bind join - "#c-p-f *" news:join bind msg o "show" news:log bind msg o "dellog" news:clear # tempfile to use set tempfile "news/news.txt" set logfile "news/news.log" set working 0 unset working #define all strings here set une "A la Une" set culture "Culture" set comput "Informatique & Internet" set nature "Natures, Sciences & Techniques" set business "Business & Finances" set politic "Politique, Société & Institutions" set sports "Sports" set pratic "Vie pratique, Loisirs & Services" set movies "Cinéma" set games "Jeux vidéos" set news_author "CrazyCat" set news_ver "2.0" ################ proc news:join { nick uhost handle chan } { puthelp "NOTICE $nick :Bonjour, pour afficher les informations, veuillez taper /msg $::botnick !actu help" } proc news:error { nick uhost handle chan arg } { putquick "NOTICE $nick :Merci de taper /msg $::botnick !actu ou /msg $::botnick !actu help" } # Function: news proc news:direct { nick uhost handle args } { set arg [string tolower $args] if {[info exists working]} { putquick "NOTICE $nick :Une demande est déjà en cours de traitement, veuillez recommencer dans quelques instants." return 0 } elseif {![llength $arg]} { putquick "PRIVMSG $nick :Entrez la rubrique qui vous intéresse (/msg $::botnick !actu help)" } else { if {$arg=="help"} { putquick "NOTICE $nick :Usage: /msg $::botnick !actu " putquick "NOTICE $nick :avec pris dans la liste suivante:" putquick "NOTICE $nick :une => $::une" putquick "NOTICE $nick :culture => $::culture" putquick "NOTICE $nick :informatique => $::comput" putquick "NOTICE $nick :nature => $::nature" putquick "NOTICE $nick :business => $::business" putquick "NOTICE $nick :politique => $::politic" putquick "NOTICE $nick :sports => $::sports" putquick "NOTICE $nick :loisirs => $::pratic" putquick "NOTICE $nick :cinema => $::movies" } else { set ::working 1 utimer 60 [list error_get $nick] switch [lindex $arg 0] { "une" { set rub "n2o1_0_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_1.asp" set topic $::une getnews $nick $rub $uhost $topic unset ::working } "culture" { set rub "n2o1_1_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_2.asp" set topic $::culture getnews $nick $rub $uhost $topic unset ::working } "informatique" { set rub "n2o1_4_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_3.asp" set topic $::comput getnews $nick $rub $uhost $topic unset ::working } "nature" { set rub "n2o1_8_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_4.asp" set topic $::nature getnews $nick $rub $uhost $topic unset ::working } "business" { set rub "n2o1_3_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_5.asp" set topic $::business getnews $nick $rub $uhost $topic unset ::working } "politique" { set rub "n2o1_12_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_6.asp" set topic $::politic getnews $nick $rub $uhost $topic unset ::working } "sports" { set rub "n2o1_7_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_7.asp" set topic $::sports getnews $nick $rub $uhost $topic unset ::working } "loisirs" { set rub "n2o1_10_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_8.asp" set topic $::pratic getnews $nick $rub $uhost $topic unset ::working } "cinema" { set rub "n2o1_894_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_9.asp" set topic $::movies getnews $nick $rub $uhost $topic unset ::working } "jeux" { set rub "n2o1_956_FE99AE8CAC185B6A7413C83748F8EBD9369B541C76907028AA0B1A2C6082ACB4_10.asp" set topic $::games getnews $nick $rub $uhost $topic unset ::working } default { news:bad $nick $uhost $arg unset ::working } } } } return 0 } ################ # Function: getnews proc getnews { nick rub host topic } { set log [open $::logfile a] puts $log "\[[strftime %H:%M]\] \002$nick\002 ($host)" puts $log "$nick> \037$topic\037 request" close $log set url "http://content4web.net2one.fr/error/error.asp?404;http://content4web.net2one.fr/scripts/$rub" set endfile "document.write" set key [http::geturl $url] putquick "NOTICE $nick :L'information en direct avec DirectNews V$::news_ver - \002$topic\002" foreach datas [split [http::data $key] "\n"] { if {[string first "" $datas] > 0} { set b_source [string first ">" $datas] incr b_source 1 set e_source [string first " - " $datas $b_source] incr e_source -1 set inf_source [string range $datas $b_source $e_source] } if {[string first "" $datas $e_link] incr b_text 1 set e_text [string first "" $datas $b_text] incr e_text -1 set inf_text [string range $datas $b_text $e_text] regsub -all {\\} $inf_text "" inf_text regsub -all {\\} $inf_source "" inf_source regsub -all " " $inf_text " " inf_text putserv "NOTICE $nick :\002$inf_text\002 : \037$inf_link\037 (Source: $inf_source)" unset inf_source } } } http::cleanup $key putserv "NOTICE $nick :\002Fin de la commande\002 - DirectNews V$::news_ver by $::news_author" set log [open $::logfile a] puts $log "\[[strftime %H:%M]\] \002$topic\002 for $nick \037successfull\037" close $log return 0 } proc error_get { nick } { if {[info exists ::working]} { putquick "NOTICE $nick :Délai d'acquisition dépassé... Veuillez retentez plus tard." unset ::working } else { return 1 } } proc news:log { nick uhost handle chan } { if {![file exists $::logfile]} { putquick "NOTICE $nick :Pas d'utilisation depuis le dernier nettoyage du log" putquick "NOTICE $nick :DirectNews V$::news_ver by $::news_author" } else { set viewlog [open $::logfile r] putquick "NOTICE $nick :" while {![eof $viewlog]} { gets $viewlog text putquick "NOTICE $nick :$text" } close $viewlog putquick "NOTICE $nick :/msg $::botnick dellog pour effacer le fichier" putquick "NOTICE $nick :DirectNews V$::news_ver by $::news_author" } return 0 } proc news:clear { nick uhost handle chan } { file delete -force $::logfile putquick "NOTICE $nick :log file cleared" putquick "NOTICE $nick :DirectNews V$::news_ver by $::news_author" return 0 } proc news:avert { nick uhost handle chan } { putquick "NOTICE $nick :Pour afficher en direct les nouvelles, veuillez taper /msg $::botnick !actu" return 0 } proc news:bad { nick host word } { putquick "NOTICE $nick :ATTENTION : \002$word\002 n'est pas une bonne option !" putquick "NOTICE $nick :Veuillez taper /msg $::botnick !actu help pour les options valides." set log [open $::logfile a] puts $log "\[[strftime %H:%M]\] \002$nick\002 ($host) \037$word\037 request" close $log return 0 } putlog "DirectNews V$::news_ver by $news_author loaded"