namespace eval anekdot {}
setudef flag nopubanekdot
set anekdot(pref) "!"
set anekdot(commands) "анекдот анек anekdot anek"
set anekdot(time) 10
set anekdot(page) http://pda.anekdot.ru/
set anekdot(version) "1.0"
set anekdot(author) "tvrsh @ IrcNet.ru"
package require http
foreach bind [split $anekdot(commands) " "] {
bind pub -|- $anekdot(pref)$bind ::anekdot::pub
bind msg -|- $anekdot(pref)$bind ::anekdot::msg
}
proc ::anekdot::msg {nick uhost hand arg} {
::anekdot::anekdot $nick $uhost $hand $nick $arg
}
proc ::anekdot::pub {nick uhost hand chan arg} {
if {[channel get $chan nopubanekdot]} return
::anekdot::anekdot $nick $uhost $hand $chan $arg
}
proc ::anekdot::anekdot {nick uhost hand chan arg} {
global anekdot lastbind
set arg [lindex [split $arg] 0]
if {[info exists anekdot(host,$uhost)]} {
if {$chan == $nick} {
putquick "PRIVMSG $nick :\00303Пожалуйста подождите. Запрос не чаще одного раза в \00304$anekdot(time) \00303секунд."
return
} else {
putquick "NOTICE $nick :\00303Пожалуйста подождите. Запрос не чаще одного раза в \00304$anekdot(time) \00303секунд."
return
}
}
set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set anekdot(host,$uhost) 1
set anekdot(timer,$uhost) [utimer $anekdot(time) [list ::anekdot::reset $uhost ] ]
set anekdot_tok [::http::config -useragent $agent]
set anekdot_tok [::http::geturl $anekdot(page) -timeout 30000]
set html [::http::data $anekdot_tok]
::http::cleanup $anekdot_tok
set asplitr [lindex {¤ • # * + °} [rand 6]]
set acolor [lindex {\00309 \00308 \00307 \00304 \00311 \00315 \00310} [rand 7]]
regexp {<a href="/anekdots/random">.*?</a></h2><p>(.*?)</p>} $html "" data
if {[info exists ::sp_version]} {
set data [encoding convertfrom cp1251 $data]
} else {
set data [encoding convertto utf-8 [encoding convertfrom cp1251 $data]]
}
regsub -all -- {<br />} $data "|" data
foreach line [split $data "|"] {
putserv "PRIVMSG $chan :$line"
}
putserv "PRIVMSG $chan :[colorize $asplitr$asplitr$asplitr]"
return 0
}
proc ::anekdot::reset { uhost } {
global anekdot
catch {killutimer $cod(timer,$uhost)}
catch {unset anekdot(timer,$uhost)}
catch {unset anekdot(host,$uhost)}
}
proc colorize {text} {
foreach bukva [split $text ""] {
set cccolor [lindex "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15" [rand 15]]
set bukva "\003$cccolor$bukva"
lappend text2 $bukva
}
return [join $text2 ""]
}
putlog "anekdot.ru.tcl v$anekdot(version) by $anekdot(author) loaded."
setudef flag nopubanekdot
set anekdot(pref) "!"
set anekdot(commands) "анекдот анек anekdot anek"
set anekdot(time) 10
set anekdot(page) http://pda.anekdot.ru/
set anekdot(version) "1.0"
set anekdot(author) "tvrsh @ IrcNet.ru"
package require http
foreach bind [split $anekdot(commands) " "] {
bind pub -|- $anekdot(pref)$bind ::anekdot::pub
bind msg -|- $anekdot(pref)$bind ::anekdot::msg
}
proc ::anekdot::msg {nick uhost hand arg} {
::anekdot::anekdot $nick $uhost $hand $nick $arg
}
proc ::anekdot::pub {nick uhost hand chan arg} {
if {[channel get $chan nopubanekdot]} return
::anekdot::anekdot $nick $uhost $hand $chan $arg
}
proc ::anekdot::anekdot {nick uhost hand chan arg} {
global anekdot lastbind
set arg [lindex [split $arg] 0]
if {[info exists anekdot(host,$uhost)]} {
if {$chan == $nick} {
putquick "PRIVMSG $nick :\00303Пожалуйста подождите. Запрос не чаще одного раза в \00304$anekdot(time) \00303секунд."
return
} else {
putquick "NOTICE $nick :\00303Пожалуйста подождите. Запрос не чаще одного раза в \00304$anekdot(time) \00303секунд."
return
}
}
set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set anekdot(host,$uhost) 1
set anekdot(timer,$uhost) [utimer $anekdot(time) [list ::anekdot::reset $uhost ] ]
set anekdot_tok [::http::config -useragent $agent]
set anekdot_tok [::http::geturl $anekdot(page) -timeout 30000]
set html [::http::data $anekdot_tok]
::http::cleanup $anekdot_tok
set asplitr [lindex {¤ • # * + °} [rand 6]]
set acolor [lindex {\00309 \00308 \00307 \00304 \00311 \00315 \00310} [rand 7]]
regexp {<a href="/anekdots/random">.*?</a></h2><p>(.*?)</p>} $html "" data
if {[info exists ::sp_version]} {
set data [encoding convertfrom cp1251 $data]
} else {
set data [encoding convertto utf-8 [encoding convertfrom cp1251 $data]]
}
regsub -all -- {<br />} $data "|" data
foreach line [split $data "|"] {
putserv "PRIVMSG $chan :$line"
}
putserv "PRIVMSG $chan :[colorize $asplitr$asplitr$asplitr]"
return 0
}
proc ::anekdot::reset { uhost } {
global anekdot
catch {killutimer $cod(timer,$uhost)}
catch {unset anekdot(timer,$uhost)}
catch {unset anekdot(host,$uhost)}
}
proc colorize {text} {
foreach bukva [split $text ""] {
set cccolor [lindex "01 02 03 04 05 06 07 08 09 10 11 12 13 14 15" [rand 15]]
set bukva "\003$cccolor$bukva"
lappend text2 $bukva
}
return [join $text2 ""]
}
putlog "anekdot.ru.tcl v$anekdot(version) by $anekdot(author) loaded."
Все очень просто. В выводе используется процедура раскраски текста выложенная чуть раньше на этом форуме.