if {[info exists queue($variable)} {
if {[expr [unixtime] - $queue($variable)]<86400} {
set calctime [expr [unixtime] - queue($variable)]
putquick "PRIVMSG $channel :you cant because you need to wait $calctime"
}
}
set queue($variable) [unixtime]
我已经在我的Tcl脚本中得到了这段代码,因此每个用户都需要等待24小时才能再次执行该命令。我会设置一个倒计时,显示他们需要等待多少时间(小时、分钟、秒)才能再次做这件事。但现在我唯一能做的就是用$calctime
知道我该怎么做吗?当然,我对$calctime
的尝试是失败的:P
以时钟格式处理相对于epoch的秒数。不要漏掉-gmt 1
,否则你会得到错误的数小时。有多少取决于你所在的时区。
putquick "PRIVMSG $channel :you cant because you need to wait
[clock format $calctime -format "%T" -gmt 1]"
或者自己计算:
set seconds [expr {$calctime % 60}]
set calctime [expr {$calctime / 60}]
set minutes [expr {$calctime % 60}]
set hours [expr {$calctime / 60}]
putquick "PRIVMSG $channel :you cant because you need to wait
$hours hours, $minutes minutes and $seconds seconds"
要显示用户等待的时间,可以使用鸡蛋掉落的特定命令duration
。
if {[info exists queue($variable)} {
if {[clock seconds] - $queue($variable) < 60*60*24 } {
set calctime [duration [expr {[clock seconds] - queue($variable)}]]
putmsg $channel "you cant because you need to wait $calctime"
return
}
}
set queue($variable) [clock seconds]
# Do the command stuff