proc ::help::msg_help { nick uhost hand args } {
global help
set helplines [utimers]
foreach line $helplines { if {"help:reset $uhost" == [lindex $line 1]} { set helptime [lindex $line 0] } }
if { [info exists help(host,$uhost)] } {
set temp $helptime
::egglib::out $nick $nick "\00310Пожалуйста ждите. Запрос не чаще одного раза в \00305[::help::duration $help(flood_time)]. \00310Вам осталось ждать \00305[::help::duration $temp] "
return
}
set help(host,$uhost) 1
set help(timer,$uhost) [utimer $help(flood_time) [list help:reset $uhost ] ]
::help::help $nick $uhost $hand $nick $args 0
putlog "\[$nick\] Read Help"
}
proc ::help::pub_help { nick uhost hand chan args } {
global help lastbind
if {[channel get $chan nopubhelp]} {::egglib::outn $nick "\0033Использование команды \037$lastbind\037 на этом канале запрещено";return}
set helplines [utimers]
foreach line $helplines { if {"help:reset $uhost" == [lindex $line 1]} { set helptime [lindex $line 0] } }
if { [info exists help(host,$uhost)] } {
set temp $helptime
::egglib::outn $nick "\00310Пожалуйста ждите. Запрос не чаще одного раза в \00305[::help::duration $help(flood_time)]. \00310Вам осталось ждать \00305[::help::duration $temp] "
return
}
set help(host,$uhost) 1
set help(timer,$uhost) [utimer $help(flood_time) [list help:reset $uhost ] ]
::help::help $nick $uhost $hand $chan $args 0
putlog "\[$chan/$nick\] Read Help"
}
proc ::help::help { nick uhost hand chan args } {
global help
set file [open $help(file) r]
while {![eof $file]} {
putquick "PRIVMSG $nick :[gets $file]"
}
close $file
}
proc ::help::duration {seconds} {
set years [expr {$seconds / 31449600}]
set seconds [expr {$seconds % 31449600}]
set weeks [expr {$seconds / 604800}]
set seconds [expr {$seconds % 604800}]
set days [expr {$seconds / 86400}]
set seconds [expr {$seconds % 86400}]
set hours [expr {$seconds / 3600}]
set seconds [expr {$seconds % 3600}]
set minutes [expr {$seconds / 60}]
set seconds [expr {$seconds % 60}]
set res ""
if {$years != 0} {lappend res [::help::numstr $years "03лет05" "03год05" "03года05"]}
if {$weeks != 0} {lappend res [::help::numstr $weeks "03недель05" "03неделю05" "03недели05"]}
if {$days != 0} {lappend res [::help::numstr $days "03дней05" "03день05" "03дня05"]}
if {$hours != 0} {lappend res [::help::numstr $hours "03часов05" "03час05" "03часа05"]}
if {$minutes != 0} {lappend res [::help::numstr $minutes "03минут05" "03минуту05" "03минуты05"]}
if {$seconds != 0} {lappend res [::help::numstr $seconds "03секунд05" "03секунду05" "03секунды05"]}
return [join $res ", "]
}
proc ::help::numstr {val str1 str2 str3} {
set d1 [expr $val % 10]
set d2 [expr $val % 100]
if {$d2 < 10 || $d2 > 19} {
if {$d1 == 1} {return "$val $str2"}
if {$d1 >= 2 && $d1 <= 4} {return "$val $str3"}
}
return "$val $str1"
}
proc help:reset { uhost } {
global help
catch {killutimer $help(timer,$uhost)}
catch {unset help(timer,$uhost)}
catch {unset help(host,$uhost)}
}