Прошу помощи сделать именно к этому скрипту дополнительно автовывод на канале с таймером 10 минут.
namespace eval calc {}
setudef flag nopubcalc
setudef flag announcecalc
#################################################
bind pub - !calc ::calc::pub_calc
bind pub - !calclevel ::calc::pub_calclevel
bind pub - !calclist ::calc::pub_calclist
bind pub - !findcalc ::calc::pub_findcalc
bind pub o|o !mailcalc ::calc::pub_mailcalc
bind msg - !calc ::calc::msg_calc
bind msg - !calclevel ::calc::msg_calclevel
bind msg - !calclist ::calc::msg_calclist
bind msg - !findcalc ::calc::msg_findcalc
bind msg o !mailcalc ::calc::msg_mailcalc
bind dcc n setcalclevel ::calc::dcc_setlevel
bind dcc n importcalcs ::calc::dcc_import
#################################################
foreach p [array names calc *] {catch {unset calc($p)}}
#################################################
# max calc name length
set calc(maxnamelen) 50
# max calc value length
set calc(maxdatalen) 400
# max level of access
set calc(maxlevel) 10
# interval between calc announcements (minutes)
set calc(announcetime) 30
# flags required to add/delete/modify calcs
# empty value - everyone can add
# "-" - every registered user can add
set calc(aflags) "o"
# filename to store users
set calc(userfile) "calc.user"
# filename to store calcs
set calc(datafile) "calc.data"
# filename to store calcs before mailing them
set calc(tempfile) "calc.temp"
#################################################
##### DON'T CHANGE ANYTHING BELOW THIS LINE #####
#################################################
set calc(data) ""
set calc(users) ""
set calc(ver) "1.8"
set calc(authors) "Stream@RusNet <stream@eggdrop.org.ru>"
#################################################
proc ::calc::readdata {} {
global calc
set calc(users) ""
if {![catch {set fid [open $calc(userfile) "r"]}]} {
while {![eof $fid]} {
set user [split [string trim [gets $fid]] " "]
if {[llength $user] == 3} {lappend calc(users) $user}
}
close $fid
putlog "\[calc\] loaded [llength $calc(users)] users"
} else {putlog "\[calc\] can't open file '$calc(userfile)'!"}
set calc(data) ""
if {![catch {set fid [open $calc(datafile) "r"]}]} {
while {![eof $fid]} {
set data [split [string trim [gets $fid]] " "]
if {[llength $data] >= 5} {
set cdata [list [lindex $data 0] [lindex $data 1] [lindex $data 2]]
lappend cdata [string trim [lindex [split [join [lrange $data 3 end]] "="] 0]]
lappend cdata [string trim [join [lrange [split [join [lrange $data 3 end]] "="] 1 end] "="]]
lappend calc(data) $cdata
}
}
close $fid
putlog "\[calc\] loaded [llength $calc(data)] calcs"
} else {putlog "\[calc\] can't open file '$calc(datafile)'!"}
}
proc ::calc::writedata {} {
global calc
set fid [open "$calc(userfile)" "w+"]
foreach user $calc(users) {
puts $fid "[join $user] "
}
close $fid
set fid [open "$calc(datafile)" "w+"]
foreach cdata $calc(data) {
puts $fid "[join [lrange $cdata 0 3]] = [lindex $cdata 4] "
}
close $fid
}
proc ::calc::init {} {
global calc
foreach tmr [timers] {if {[lindex $tmr 1] == "::calc::announce"} {killtimer [lindex $tmr 2]}}
::calc::readdata
timer $calc(announcetime) ::calc::announce
}
proc ::calc::tolower {text} {
return [string map {А а Б б В в Г г Д д Е е Ё ё Ж ж З з И и Й й К к Л л М м Н н О о П п Р р С с Т т У у Ф ф Х х Ц ц Ч ч Ш ш Щ щ Ъ ъ Ы ы Ь ь Э э Ю ю Я я} [string tolower $text]]
}
proc ::calc::out {nick chan text} {
global botnick
if {[validchan $chan]} {putserv "PRIVMSG $chan :$text"
} elseif {$nick != $botnick} {
if {$nick == $chan} {putserv "PRIVMSG $chan :$text"
} else {putserv "NOTICE $nick :$text"}
}
}
#################################################
proc ::calc::pub_calc {nick uhost hand chan args} {
if {![validchan $chan]} {return}
if {[channel get $chan nopubcalc]} {return}
regsub -all -- {\\} [join $args] "" args
::calc::calc $nick $uhost $hand $chan [string trim $args]
}
proc ::calc::msg_calc {nick uhost hand args} {
regsub -all -- {\\} [join $args] "" args
::calc::calc $nick $uhost $hand $nick [string trim $args]
}
proc ::calc::pub_calclevel {nick uhost hand chan args} {
if {![validchan $chan]} {return}
if {[channel get $chan nopubcalc]} {return}
regsub -all -- {\\} [join $args] "" args
::calc::calclevel $nick $uhost $hand $chan [string trim $args]
}
proc ::calc::msg_calclevel {nick uhost hand args} {
regsub -all -- {\\} [join $args] "" args
::calc::calclevel $nick $uhost $hand $nick [string trim $args]
}
proc ::calc::pub_calclist {nick uhost hand chan args} {
if {![validchan $chan]} {return}
if {[channel get $chan nopubcalc]} {return}
regsub -all -- {\\} [join $args] "" args
::calc::calclist $nick $chan "" [string trim $args]
}
proc ::calc::msg_calclist {nick uhost hand args} {
regsub -all -- {\\} [join $args] "" args
if {[llength $args] < 1} {
::calc::out $nick $nick "Используй: !calclist <#канал> \[маска\]";
return;
}
set chan [lindex $args 0]
if {![validchan $chan]} {
::calc::out $nick $nick "Я не слежу за каналом '$chan'...";
return;
}
if {[channel get $chan nopubcalc]} {
::calc::out $nick $nick "Кальки на канале '$chan' отключены...";
return;
}
set mask [lrange $args 1 end]
::calc::calclist $nick $chan $nick [string trim [join $mask]]
}
proc ::calc::pub_findcalc {nick uhost hand chan args} {
if {![validchan $chan]} {return}
if {[channel get $chan nopubcalc]} {return}
regsub -all -- {\\} [join $args] "" args
::calc::findcalc $nick $uhost $hand $chan [string trim $args]
}
proc ::calc::msg_findcalc {nick uhost hand args} {
regsub -all -- {\\} [join $args] "" args
::calc::findcalc $nick $uhost $hand $nick [string trim $args]
}
proc ::calc::pub_mailcalc {nick uhost hand chan args} {
if {![validchan $chan]} {return}
if {[channel get $chan nopubcalc]} {return}
::calc::mailcalc $nick $uhost $hand $chan
}
proc ::calc::msg_mailcalc {nick uhost hand args} {
::calc::mailcalc $nick $uhost $hand $nick
}
proc ::calc::dcc_setlevel {hand idx args} {
global calc
set args [split [string trim [join $args]] " "]
if {[llength $args] < 2} {putdcc $idx "Usage: \002.setcalclevel\002 handle level \[channel\]"; return}
set uhand [lindex $args 0]
if {![validuser $uhand]} {putdcc $idx "User '$uhand' is not registered."; return}
set level [lindex $args 1]
if {![regexp -nocase -- {[0-9]} $level]} {putdcc $idx "Invalid level, must be numerical."; return}
if {$level > $calc(maxlevel)} {putdcc $idx "Invalid level, must be 0-$calc(maxlevel)."; return}
if {[llength $args] > 2} {
set chan [lindex $args 2]
if {![validchan $chan]} {putdcc $idx "I don't monitor channel $chan."; return}
} else {set chan "*"}
set res ""
set del 0
foreach user $calc(users) {
if {![validuser [lindex $user 1]]} {incr del
} elseif {[::calc::tolower $uhand] != [::calc::tolower [lindex $user 1]] || [::calc::tolower $chan] != [::calc::tolower [lindex $user 0]]} {
lappend res $user
}
}
lappend res [list $chan $uhand $level]
set calc(users) $res
if {$chan == "*"} {putdcc $idx "Global calc level for '$uhand' set to $level"
} else {putdcc $idx "Calc level for '$uhand' on $chan set to $level"}
::calc::writedata
}
proc ::calc::dcc_import {hand idx args} {
global calc
set args [split [join $args] " "]
if {[llength $args] != 2} {putdcc $idx "Usage: \002.importcalcs\002 userfile datafile"; return}
set userfile [lindex $args 0]
set datafile [lindex $args 1]
putdcc $idx "\[calc\] Importing users from '$userfile'..."
set calc(users) ""
if {![catch {set fid [open $userfile "r"]}]} {
while {![eof $fid]} {
set user [split [string trim [gets $fid]] " "]
if {[llength $user] == 2} {lappend calc(users) [list "*" [lindex $user 0] [lindex $user 1]]}
}
close $fid
putdcc $idx "\[calc\] imported [llength $calc(users)] users"
} else {putdcc $idx "\[calc\] can't open file '$userfile'!"}
putdcc $idx "\[calc\] Importing calcs from '$datafile'..."
set calc(data) ""
if {![catch {set fid [open $datafile "r"]}]} {
while {![eof $fid]} {
set data [split [string trim [gets $fid]] " "]
if {[llength $data] >= 4} {
set user [lindex $data 0]
set ctime [lindex $data 1]
set name [string trim [lindex [split [join [lrange $data 2 end]] "="] 0]]
set value [string trim [join [lrange [split [join [lrange $data 2 end]] "="] 1 end] "="]]
foreach chan [channels] {
if {![channel get $chan inactive]} {
lappend calc(data) [list $chan $user $ctime $name $value]
}
}
}
}
close $fid
putdcc $idx "\[calc\] imported [llength $calc(data)] calcs"
} else {putdcc $idx "\[calc\] can't open file '$datafile'!"}
::calc::writedata
}
#################################################
proc ::calc::getlevel {nick {chan ""}} {
global calc
set hand $nick
if {[validchan $chan]} {if {[onchan $nick $chan]} {set hand [nick2hand $nick $chan]}} else {set chan "*"}
set res 0
if {$hand != "" && $hand != "*" && [validuser $hand]} {
set hand [::calc::tolower $hand]
foreach user $calc(users) {
if {[string equal [::calc::tolower $hand] [::calc::tolower [lindex $user 1]]]} {
if {[string match [::calc::tolower [lindex $user 0]] [::calc::tolower $chan]]} {
set level [lindex $user 2]
set res [expr {$res>$level?$res:$level}]
}
}
}
}
return $res
}
proc ::calc::getchancalcs {data chan} {
global calc
set lchan [::calc::tolower $chan]
set res ""
foreach cdata $data {
if {[string equal $lchan [::calc::tolower [lindex $cdata 0]]]} {lappend res $cdata}
}
return $res
}
proc ::calc::firstname {data name} {
set res $name
set checklinked 1
set checked ""
while {$checklinked == 1} {
set checklinked 0
foreach cdata $data {
if {[string equal [::calc::tolower $name] [::calc::tolower [lindex $cdata 3]]]} {
if {[lsearch -exact $checked $name] != -1} {return [list $res 0]}
lappend checked $name
set res $name
set name [lindex $cdata 4]
set checklinked 1
}
}
}
return [list $res 1]
}
proc ::calc::randomdata {{chan ""}} {
global calc
if {$chan == "" } {set chandata $calc(data)} else {set chandata [::calc::getchancalcs $calc(data) $chan]}
if {[llength $chandata] > 0} {
set rnum [rand [llength $chandata]]
set num 0
foreach cdata $chandata {
if {$num == $rnum} {return $cdata}
incr num
}
}
putlog "\[calc\] error: can't get random calc data for channel $chan!"
return ""
}
proc ::calc::getbyname {name chan} {
global calc
if {$chan == "" } {set chandata $calc(data)} else {set chandata [::calc::getchancalcs $calc(data) $chan]}
if {[llength $chandata] > 0} {
set first [::calc::firstname $chandata $name]
if {[lindex $first 1] != 0} {
set name [lindex $first 0]
foreach cdata $chandata {
if {[string equal [::calc::tolower $name] [::calc::tolower [lindex $cdata 3]]]} {return $cdata}
}
}
}
return ""
}
proc ::calc::addcalc {nick hand chan name value} {
global calc
set name [string trim $name]
set value [string trim $value]
putlog "\[calc\] $nick/$chan add $name = $value"
if {$calc(aflags) != ""} {
if {$hand == "*" || $hand == "" || ![validuser $hand]} {
::calc::out $nick $chan "$nick, только зарегистрированные пользователи могут изменять кальки..."
return
}
if {[validchan $chan]} {set hasflags [matchattr $hand "$calc(aflags)|$calc(aflags)" $chan]
} else {set hasflags [matchattr $hand "$calc(aflags)"]}
if {!$hasflags} {
::calc::out $nick $chan "$nick, недостаточно прав для изменения кальков..."
return
}
}
if {[string equal $name $value]} {
::calc::out $nick $chan "$nick, придумай что-нибудь более нужное..."
return
}
if {[string length $name] > $calc(maxnamelen)} {
::calc::out $nick $chan "Длина имени превышает допустимое значение ($calc(maxnamelen) символов)..."
return
}
if {[string length $value] > $calc(maxdatalen)} {
::calc::out $nick $chan "Длина значения превышает допустимое значение ($calc(maxdatalen) символов)..."
return
}
set res ""
set lname [::calc::tolower $name]
set lchan [::calc::tolower $chan]
foreach cdata $calc(data) {
if {[string equal [::calc::tolower [lindex $cdata 3]] $lname] && [string equal [::calc::tolower [lindex $cdata 0]] $lchan]} {
if {[::calc::getlevel $hand $chan] < [::calc::getlevel [lindex $cdata 1] $chan]} {
::calc::out $nick $chan "Недостаточно прав для изменения этого калька..."
return
}
} else {lappend res $cdata}
}
set chandata [::calc::getchancalcs $res $chan]
if {$value != ""} {
set fname [::calc::tolower [lindex [::calc::firstname $chandata $value] 0]]
foreach cdata $chandata {
if {[string equal [::calc::tolower [lindex $cdata 3]] $fname]} {
if {[string equal [::calc::tolower [lindex $cdata 4]] $lname]} {
::calc::out $nick $chan "После линкования получится бесконечный цикл..."
return
}
}
}
if {$hand != "" && $hand != "*" && [validuser $hand]} {lappend res [list $chan $hand [unixtime] $name $value]
} else {lappend res [list $chan $nick [unixtime] $name $value]}
}
set calc(data) $res
::calc::out $nick $chan "Спасибо за информацию, $nick"
::calc::writedata
}
proc ::calc::showcalc {nick chan mask} {
global calc
set mask [string trim $mask]
putlog "\[calc\] $nick/$chan show $mask"
if {[validchan $chan]} {set chandata [::calc::getchancalcs $calc(data) $chan]} else {set chandata $calc(data)}
if {[llength $chandata] == 0} {::calc::out $nick $chan "В базе нет ни одного калька..."; return}
set res ""
if {$mask != ""} {
if {[string first "?" $mask] != -1 || [string first "*" $mask] != -1} {
foreach cdata $chandata {
if {[string match [::calc::tolower $mask] [::calc::tolower [lindex $cdata 3]]]} {
set mask [lindex $cdata 3]
break
}
}
}
set name $mask
if {[string first "?" $mask] == -1 && [string first "*" $mask] == -1} {
set first [::calc::firstname $chandata $mask]
if {[lindex $first 1] == 0} {::calc::out $nick $chan "Кальки полинкованы в бесконечном цикле..."; return}
set mask [lindex $first 0]
foreach cdata $chandata {
if {[string match [::calc::tolower $mask] [::calc::tolower [lindex $cdata 3]]]} {
set res $cdata
break
}
}
}
if {$res != ""} {::calc::out $nick $chan "$name = [lindex $res 4] \[[lindex $res 1]\]"
} else {::calc::out $nick $chan "Я ничего не знаю о '$mask'..."}
} else {
if {[validchan $chan]} {set res [::calc::getbyname [lindex [::calc::randomdata $chan] 3] $chan]
} else {set res [::calc::getbyname [lindex [::calc::randomdata] 3] ""]}
::calc::out $nick $chan "[lindex $res 3] = [lindex $res 4] \[[lindex $res 1]\]"
}
}
proc ::calc::calc {nick uhost hand chan args} {
set args [join $args]
if {[string first "=" $args] > 0} {
if {![validchan $chan]} {::calc::out $nick $chan "Добавлять кальки можно только на каналах..."; return}
::calc::addcalc $nick $hand $chan [lindex [split $args "="] 0] [join [lrange [split $args "="] 1 end] "="]
} else {
::calc::showcalc $nick $chan $args
}
}
proc ::calc::calclevel {nick uhost hand chan args} {
set args [join $args]
putlog "\[calc\] $nick/$chan calclevel"
if {$nick != $chan} {
if {$args == ""} {::calc::out $nick $chan "$nick, твой уровень доступа к калькам = [::calc::getlevel $nick $chan]"
} else {::calc::out $nick $chan "Уровень доступа к калькам у '$args' = [::calc::getlevel $args $chan]"}
} else {
if {$args == ""} {::calc::out $nick $chan "$nick, твой глобальный уровень доступа к калькам = [::calc::getlevel $nick $chan]"
} else {::calc::out $nick $chan "Глобальный уровень доступа к калькам у '$args' = [::calc::getlevel $args $chan]"}
}
}
proc ::calc::calclist {nick chan dchan mask} {
global calc
set mask [string trim $mask]
if {$mask == ""} {set mask "*"}
putlog "\[calc\] $nick/$chan list $mask"
if {[validchan $chan]} {set chandata [::calc::getchancalcs $calc(data) $chan]} else {set chandata $calc(data)}
if {[llength $chandata] == 0} {::calc::out $nick $dchan "В базе нет ни одного калька..."; return}
set res ""
foreach cdata $chandata {
if {[string match [::calc::tolower $mask] [::calc::tolower [lindex $cdata 3]]]} {
lappend res [lindex $cdata 3]
}
}
#set res [join $res ", "]
if {$res != ""} {
#::calc::out $nick $dchan "Кальки: $res"
while {[llength $res] > 0} {
if {[string length [join $res ", "]] <= $calc(maxdatalen) || [llength $res] == 1} {
set res [join $res ", "]
calc::out $nick $dchan "Кальки: $res"
break
}
set msg ""
set newtext ""
foreach cname $res {
if {$newtext == "" && [expr [string length $msg] + [string length $cname]] <= $calc(maxdatalen)} {lappend msg $cname
} elseif {$newtext == "" && $msg == "" && [string length $cname] > $calc(maxdatalen)} {lappend msg $cname
} else {lappend newtext $cname}
}
set msg [join $msg ", "]
if {$msg != ""} {calc::out $nick $dchan "Кальки: $msg"}
set res $newtext
}
} else {::calc::out $nick $dchan "Не найдено ни одного калька, соответствующего маске '$mask'..."}
}
proc ::calc::announce {} {
global calc botnick
if {[llength $calc(data)] != 0} {
foreach chan [channels] {
if {[channel get $chan announcecalc]} {
set cdata [::calc::getbyname [lindex [::calc::randomdata $chan] 3] $chan]
if {$cdata != ""} {
::calc::out $botnick $chan "[lindex $cdata 3] = [lindex $cdata 4] \[[lindex $cdata 1]\]"
}
}
}
}
timer $calc(announcetime) ::calc::announce
}
proc ::calc::findcalc {nick uhost hand chan args} {
global calc
set mask [string trim [join $args]]
putlog "\[calc\] $nick/$chan find $mask"
if {[validchan $chan]} {set chandata [::calc::getchancalcs $calc(data) $chan]} else {set chandata $calc(data)}
if {[llength $chandata] == 0} {::calc::out $nick $chan "В базе нет ни одного калька..."; return}
set res ""
foreach cdata $chandata {
if {[string match [::calc::tolower $mask] [::calc::tolower [lindex $cdata 4]]]} {
set res $cdata
break
}
}
if {$res != ""} {::calc::out $nick $chan "[lindex $res 3] = [lindex $res 4] \[[lindex $res 1]\]"
} else {::calc::out $nick $chan "Кальк не найден..."}
}
proc ::calc::mailcalc {nick uhost hand chan} {
global calc botnick
if {[validchan $chan]} {set chandata [::calc::getchancalcs $calc(data) $chan]} else {set chandata $calc(data)}
if {[llength $chandata] == 0} {::calc::out $nick $chan "В базе нет ни одного калька..."; return}
if {$hand == "" || $hand == "*" || ![validuser $hand]} {
::calc::out $nick "" "Отправка на e-mail возможна только для зарегистрированных пользователей. Зарегистрироваться можно командой \002/msg $botnick hello\002"
return
}
set email [string trim [getuser $hand XTRA EMAIL]]
if {[string length $email] == 0} {
::calc::out $nick "" "Установите свой e-mail командой \002/msg $botnick email ваш_email\002"
return
}
putlog "\[calc\] $nick/$chan mail $email"
set fid [open "$calc(tempfile)" "w+"]
foreach cdata $chandata {
set ctime [clock format [lindex $cdata 2] -format "%d.%m.%y %H:%M:%S"]
puts $fid "[join [lrange $cdata 0 1]] $ctime [lindex $cdata 3] = [lindex $cdata 4] "
}
close $fid
set subj [expr {[validchan $chan]?"calc.data/$botnick/$chan":"calc.data/$botnick"}]
if {![catch {exec cat $calc(datafile) | mail -s "$subj" $email}]} {::calc::out $nick "" "E-mail отправлен на $email"
} else {::calc::out $nick "" "E-mail не отправлен..."}
}
#################################################
::calc::init
putlog "calc.tcl v$calc(ver) by $calc(authors) loaded"