### # # Название: ufootball.tcl # Версия: 1.1 # Автор: tvrsh # Оффсайт: http://egghelp.ru/ # ### # # Описание: Скрипт забирает турнирные таблицы по футболу. # ### # # Установка: # 1. Скопируйте скрипт ufootball.tcl в папку scripts вашего бота. # 2. В файле eggdrop.conf впишите строку source scripts/ufootball.tcl # 3. Сделайте .rehash боту. # ### # # Версион хистори: # # 1.0(09.07.2011) Первая паблик версия. # 1.1(10.07.2011) Изменен вывод таблиц. Теперь все ровно и красиво. # ### namespace eval ufootball { # Сбрасываем значения всех переменных. foreach p [array names ufootball *] { catch {unset ufootball($p) } } # Указываем канальный флаг(.chanset #chan +ufootball для включения скрипта). setudef flag ufootball ### ### # Меню настроек ниже этой линии: # # ______________________________ # ### ### variable ufootball array set ufootball { pref {!} binds {ufootball ufoot uball} showlines 16 msg 1 delay 10 color1 \00314 color2 \00303 color3 \00305 version "ufootball.tcl version 1.1" author "tvrsh" } ### ### # Ниже этой линии начинается код, не изменяйте его если не знаете TCL: # # ____________________________________________________________________ # ### ### # Обработка биндов. foreach bind [split $ufootball(binds) " "] { bind pub -|- "$ufootball(pref)$bind" ::ufootball::ufootball_pub if {$ufootball(msg) >= 1} { bind msg -|- "$ufootball(pref)$bind" ::ufootball::ufootball_msg } } # Процедура обработки приватных команд. proc ::ufootball::ufootball_msg {nick uhost hand text} { variable ufootball ::ufootball::ufootball_proc $nick $uhost $hand $nick $text } # Процедура обработки паблик команд. proc ::ufootball::ufootball_pub {nick uhost hand chan text} { variable ufootball # Проверяем наличие флага. if {![channel get $chan ufootball]} { return } ::ufootball::ufootball_proc $nick $uhost $hand $chan $text } # Процедура обработки запроса. proc ::ufootball::ufootball_proc {nick uhost hand chan text} { global lastbind variable ufootball if {[info exists ufootball(lasttime,$chan)] && [expr $ufootball(lasttime,$chan) + $ufootball(delay)] > [clock seconds]} { putserv "NOTICE $nick :$ufootball(color1)Запрос не чаще одного раза в $ufootball(color2)$ufootball(delay) $ufootball(color1)[lindex {. секунду секунды секунд} [::ufootball::ufootball_numgrp $ufootball(delay)]]." putserv "NOTICE $nick :$ufootball(color1)Подождите $ufootball(color3)[expr $ufootball(delay) - [expr [clock seconds] - $ufootball(lasttime,$chan)]] $ufootball(color1)[lindex {. секунду секунды секунд} [::ufootball::ufootball_numgrp [expr $ufootball(delay) - [expr [clock seconds] - $ufootball(lasttime,$chan)]]]] до следующего запроса." return 0 } set text_ [lindex [split $text] 1] if {$text == "help"} { putserv "PRIVMSG $chan :$ufootball(color1)Используйте $ufootball(color2)$lastbind $ufootball(color3)<страна> $ufootball(color1)для просмотра турнирной таблицы.\003" putserv "PRIVMSG $chan :$ufootball(color1)Доступные страны: $ufootball(color2)Россия$ufootball(color1), $ufootball(color2)Украина$ufootball(color1), $ufootball(color2)Англия$ufootball(color1), $ufootball(color2)Испания$ufootball(color1), $ufootball(color2)Италия$ufootball(color1), $ufootball(color2)Германия.\003" putserv "PRIVMSG $chan :$ufootball(color1)Чтобы посмотреть отдельное место в таблице используйте $ufootball(color2)$lastbind $ufootball(color3)<страна> <место>$ufootball(color1).\003" return 0 } if {[string match -nocase "укра*" $text]} { set country ukraine } elseif {[string match -nocase "англ*" $text]} { set country england } elseif {[string match -nocase "испа*" $text]} { set country spain } elseif {[string match -nocase "итал*" $text]} { set country italy } elseif {[string match -nocase "герм*" $text]} { set country germany } else { set country russia } set ufootball_tok [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)"] set ufootball_tok [::http::geturl "http://www.readfootball.com/$country.php" -timeout "15000"] set data [::http::data $ufootball_tok] ::http::cleanup $ufootball_tok putlog "\[ufootball\] $nick/$chan/$text" if {[info exists ::sp_version]} { set data [encoding convertfrom cp1251 $data] } regexp {(.*?)} $data "" title putserv "PRIVMSG $chan :\00310\002$title\002\003" regsub -all -- {\n} $data " " data regsub -all -- {^.*?} $data "" data regsub -all -- {.*?$} $data "" data regsub -all -- {\s+} $data " " data regsub -all -- { } $data "|" data regsub -all -- {} $data "_" data regsub -all -- {\<[^\>]*\>| } $data "" data set w1 5; set w2 18; set w3 3; set w4 3; set w5 3; set w6 3; set w7 7; set w8 4 putserv "PRIVMSG $chan :+-[string repeat - $w1]-+-[string repeat - $w2]-+-[string repeat - $w3]-+-[string repeat - $w4]-+-[string repeat - $w5]-+-[string repeat - $w6]-+-[string repeat - $w7]-+-[string repeat - $w8]-+" putserv "PRIVMSG $chan :[format "| \00302%-*s\003 | \00303%-*s\003 | \00304%*s\003 | \00305%*s\003 | \00306%*s\003 | \00307%*s\003 | \00310%*s\003 | \00312%*s\003 |" $w1 "Место" $w2 "Клуб" $w3 "И" $w4 "В" $w5 "Н" $w6 "П" $w7 "Мячи" $w8 "Очки"] " putserv "PRIVMSG $chan :+-[string repeat - $w1]-+-[string repeat - $w2]-+-[string repeat - $w3]-+-[string repeat - $w4]-+-[string repeat - $w5]-+-[string repeat - $w6]-+-[string repeat - $w7]-+-[string repeat - $w8]-+" set i 1 if {[info exists "text_"] && [isnumber "$text_"]} { foreach line [split $data "|"] { if {$i == $text_} { putserv "PRIVMSG $chan :[format "| \00302%-*s\003 | \00303\002%-*s\002\003 | \00304%*s\003 | \00305%*s\003 | \00306%*s\003 | \00307%*s\003 | \00310%*s\003 | \00312%*s\003 |" $w1 "$i)" $w2 "[lindex [split $line "_"] 1]" $w3 "[lindex [split $line "_"] 2]" $w4 "[lindex [split $line "_"] 3]" $w5 "[lindex [split $line "_"] 4]" $w6 "[lindex [split $line "_"] 5]" $w7 "[lindex [split $line "_"] 6]" $w8 "[lindex [split $line "_"] 7]"] " putserv "PRIVMSG $chan :+-[string repeat - $w1]-+-[string repeat - $w2]-+-[string repeat - $w3]-+-[string repeat - $w4]-+-[string repeat - $w5]-+-[string repeat - $w6]-+-[string repeat - $w7]-+-[string repeat - $w8]-+" set ufootball(lasttime,$chan) [clock seconds] return 0 } incr i } } else { foreach line [split $data "|"] { if {$i <= $ufootball(showlines)} { putserv "PRIVMSG $chan :[format "| \00302%*s\003 | \00303%-*s\003 | \00304%*s\003 | \00305%*s\003 | \00306%*s\003 | \00307%*s\003 | \00310%*s\003 | \00312%*s\003 |" $w1 "$i)" $w2 "[lindex [split $line "_"] 1]" $w3 "[lindex [split $line "_"] 2]" $w4 "[lindex [split $line "_"] 3]" $w5 "[lindex [split $line "_"] 4]" $w6 "[lindex [split $line "_"] 5]" $w7 "[lindex [split $line "_"] 6]" $w8 "[lindex [split $line "_"] 7]"] " incr i } } putserv "PRIVMSG $chan :+-[string repeat - $w1]-+-[string repeat - $w2]-+-[string repeat - $w3]-+-[string repeat - $w4]-+-[string repeat - $w5]-+-[string repeat - $w6]-+-[string repeat - $w7]-+-[string repeat - $w8]-+" set ufootball(lasttime,$chan) [clock seconds] return 0 } } proc ::ufootball::ufootball_numgrp {number} { switch -glob -- "$number" { *11 {return 3} *12 {return 3} *13 {return 3} *14 {return 3} *1 {return 1} *2 {return 2} *3 {return 2} *4 {return 2} default {return 3} } } # Выводим сообщение о том, что скрипт удачно загружен. putlog "\[ufootball\] $ufootball(version) by $ufootball(author) loaded" }