#################################################### # WindropClan @ http://windrop.clan.su # Автор: Vladislav # Версия: 1.3 # Описание: Погода с foreca.com # Команды: !погода #################################################### namespace eval foreca { setudef flag no[namespace tail [namespace current]] variable file "data/city.dat" variable timer 5 variable pbind 1 variable clock 0 foreach bind {п погода p pogoda foreca} {bind pub - $::gprefix(1)$bind [namespace current]::pub; if {$pbind} {bind msg - $::gprefix(1)$bind [namespace current]::msg}} proc msg {nick host hand text} {pub $nick $host $hand $nick $text; return} proc pub {nick host hand chan text} { variable timer; variable clock if {$chan != $nick && [channel get $chan no[namespace tail [namespace current]]]} {return} else {set lastbind $::lastbind; set text [string trim [string map { {}} [stripcodes cubr $text]]]; set gorod [pgorod $nick]} if {[regexp -nocase -- {-(\d+)} $text -> n]} {set text [string trim [regsub -- {-\d+} $text ""]]; if {$n < 1} {set n 1}} else {set n 1} if {[regexp -nocase -- {\+(\d+)} $text -> d]} {set text [string trim [regsub -- {\+\d+} $text ""]]} else {set d 0} if {![string is space $text] && [string length $text] > 60} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Название города не может быть длиннее 60 символов."; return} elseif {![string is space $text] && [string length $text] < 2} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Название города не может быть короче 3 символов."; return} elseif {[string is space $text]} {set text $gorod} if {$text == 0 || [string match -nocase "хелп" $text] || [string match -nocase "help" $text]} { putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Формат: $lastbind \[-номер\] \<город\> - погода с foreca.com." if {$gorod != 0} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Ваш город: $gorod. Вы можете не указывать город в команде."} else {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Добавьте свой город командой \002!город\002 для автоматического определения вашего города."} } else { if {[expr [clock seconds]-$clock] < $timer} {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Команда недавно запрашивалась. Повтори попытку через [expr $timer-([clock seconds]-$clock)] сек."; return}; set clock [clock seconds] ::http::config -useragent "Mozilla/6.0" -urlencoding utf-8 if {[catch {set token [::http::geturl http://www.foreca.com/ -binary true -query [::http::formatQuery loc_id "" continent_id "" country_id "" geode_lon "" geode_lat "" q $text do_search "Find place"] -headers [list "Accept-Language" "ru-RU,ru;q=0.9,en;q=0.8" "Accept-Charset" "iso-8859-1, utf-8, utf-16, *;q=0.1" Cookie "lv=cnU6MTAwNTI0OTAx; st2=lang%3Dru%26units%3Dmetricmmhg%26tf%3D24h%26ml%3D%26u%3D02UWOU5U6QNA"] -timeout 10000 -command [list [namespace current]::data $nick $host $hand $chan $n $d $text 1]]} err]} { if {[info exists ::gismeteo::clock]} {::gismeteo::pub $nick $host $hand $chan "-$n +$d $text"; return} else {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Ошибка при подключении к удаленному серверу: $err"; return} } } } proc data {nick host hand chan n d text total token} { set ncode [::http::ncode $token]; set status [::http::status $token]; array set meta [::http::meta $token] if {[string index $ncode 0] == 3 && [info exists meta(Location)]} { ::http::cleanup $token; ::http::config -useragent "Mozilla/6.0" -urlencoding utf-8 if {[catch {set token [::http::geturl "http://www.foreca.com$meta(Location)" -binary true -headers [list "Accept-Language" "ru-RU,ru;q=0.9,en;q=0.8" "Accept-Charset" "iso-8859-1, utf-8, utf-16, *;q=0.1" Cookie "lv=cnU6MTAwNTI0OTAx; st2=lang%3Dru%26units%3Dmetricmmhg%26tf%3D24h%26ml%3D%26u%3D02UWOU5U6QNA"] -timeout 10000 -command [list [namespace current]::data $nick $host $hand $chan $n $d $text 1]]} err]} { if {[info exists ::gismeteo::clock]} {::gismeteo::pub $nick $host $hand $chan "-$n +$d $text"} else {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Ошибка при подключении к удаленному серверу после перенаправления: $err"} }; return } if {$ncode != 200 || $status ne "ok"} {::http::cleanup $token; if {[info exists ::gismeteo::clock]} {::gismeteo::pub $nick $host $hand $chan "-$n +$d $text"; return} else {putserv "[expr {$nick == $chan ? "PRIVMSG":"NOTICE"}] $nick :Сервер вернул $ncode-код ошибки или произошел таймаут соединения."}; return} set data [regsub -all -- {\n|\r|\t|\v} [encoding convertfrom utf-8 [::http::data $token]] ""]; ::http::cleanup $token; regsub -all -- {\s+} $data " " data if {[string match -nocase "*No results*" $data] || [string match -nocase "*без результ*" $data]} { if {[info exists ::gismeteo::clock]} {::gismeteo::pub $nick $host $hand $chan "-$n +$d $text"; return} else {putserv "PRIVMSG $chan :Ничего не найдено."; return} } if {[regexp -nocase -- {
.*?(.*?)} $data -> data]} { set list [list]; foreach {b x} [regexp -nocase -inline -all {(.*?)(?: