namespace eval nyash {}
setudef flag nopubnyash
set nyash(pref) "!"
set nyash(commands) "nya"
set nyash(time) 10
set nyash(page) http://nya.sh/post/
set nyash(version) "1.0"
set nyash(author) "tvrsh @ IrcNet.ru"
package require http
foreach bind [split $nyash(commands) " "] {
bind pub -|- $nyash(pref)$bind ::nyash::pub
bind msg -|- $nyash(pref)$bind ::nyash::msg
}
proc ::nyash::msg {nick uhost hand arg} {
::nyash::nyash $nick $uhost $hand $nick $arg
}
proc ::nyash::pub {nick uhost hand chan arg} {
if {[channel get $chan nopubnyash]} return
::nyash::nyash $nick $uhost $hand $chan $arg
}
proc ::nyash::nyash {nick uhost hand chan arg} {
global nyash lastbind
if {[info exists nyash(host,$uhost)]} {
if {$chan == $nick} {
putquick "PRIVMSG $nick :\00303Пожалуйста подождите. Запрос не чаще одного раза в \00304$nyash(time) \00303секунд."
return 0
} else {
putquick "NOTICE $nick :\00303Пожалуйста подождите. Запрос не чаще одного раза в \00304$nyash(time) \00303секунд."
return 0
}
}
set agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
set nyash(host,$uhost) 1
set nyash(timer,$uhost) [utimer $nyash(time) [list ::nyash::reset $uhost ] ]
set nyash_tok [::http::config -useragent $agent]
set post [rand 6117]
set nyash_tok [::http::geturl $nyash(page)$post -timeout 30000]
set html [::http::data $nyash_tok]
::http::cleanup $nyash_tok
set asplitr [lindex {¤ • # * + °} [rand 6]]
set acolor [lindex {\00309 \00308 \00307 \00304 \00311 \00315 \00310} [rand 7]]
set rgx "<div class=\\\"content\\\">(.*?)</div>"
regsub -all -- {\n} $html "" html
foreach line [split $html \n] {
if {[regexp -nocase -- $rgx $line garb data]} {
regsub -all -- {<br />} $data "|" data
putserv "PRIVMSG $chan :$asplitr $post $asplitr"
foreach line [split $data "|"] {
putserv "PRIVMSG $chan :${acolor}$line"
}
putserv "PRIVMSG $chan :$asplitr$asplitr$asplitr"
return 0
}
}
}
proc ::nyash::reset { uhost } {
global nyash
catch {killutimer $cod(timer,$uhost)}
catch {unset nyash(timer,$uhost)}
catch {unset nyash(host,$uhost)}
}
putlog "nyash.ru.tcl v$nyash(version) by $nyash(author) loaded."