我如何修改这个eggdroptcl脚本,使其工作方式有所不同

我如何修改这个eggdroptcl脚本,使其工作方式有所不同,tcl,eggdrop,Tcl,Eggdrop,我正试图建立一个简单的蛋液机器人,在某个特定事件前倒计时。我的想法是,我给它一个预定的日期和时间,用户类型!倒计时,机器人回答“还有x天,x小时,x分钟就要发生了”。这是我发现的脚本(只更改为添加事件的unixtime日期来代替它),在我的eggdrop机器人上运行它会给出一个响应,但当然这不是我需要的响应(重要的是它工作正常) 我不认为它所做的和我想要它做的之间有很大的区别,但是我不知道如何正确地修改它。所以我想知道这里是否有人能教我如何做我想做的事情 bind pub - !test cou

我正试图建立一个简单的蛋液机器人,在某个特定事件前倒计时。我的想法是,我给它一个预定的日期和时间,用户类型!倒计时,机器人回答“还有x天,x小时,x分钟就要发生了”。这是我发现的脚本(只更改为添加事件的unixtime日期来代替它),在我的eggdrop机器人上运行它会给出一个响应,但当然这不是我需要的响应(重要的是它工作正常)

我不认为它所做的和我想要它做的之间有很大的区别,但是我不知道如何正确地修改它。所以我想知道这里是否有人能教我如何做我想做的事情

bind pub - !test countdown
proc countdown { nickname hostname handle channel arg } {  
    set date1 "1385798400"
    # finds the time and date now
    set now [unixtime]
    # counts the time passed scince now 
    incr now -$date1 
    # shows how long has passed since $date1 
    set then [duration $now] 
    puthelp "PRIVMSG $channel :date1 was: $then ago, $nickname | \([\
            clock format $date1 -format %d.%m.%Y] @ [\
            clock format $date1 -format %H:%M:%S]\)"    
}

处理日期最困难的部分是解析和格式化,但您已经有了实用程序命令来完成这项工作(
duration
clock format
)。要计算出未来某个事件的剩余时间,您只需确保在计算中执行timestampfuture event-timestampnow

proc countdown {nickname hostname handle channel arg} {
    set date1 "1385798400"
    # finds the time and date now
    set now [unixtime]

    set left [duration [expr {$date1 - $now}]]
    # Easier to store complex stuff in a variable and substitute stuff in
    set formatted [clock format $date1 -format "(%d.%m.%Y @ %H:%M:%S"}]

    puthelp "PRIVMSG $channel :date1 will be: $left in the future, $nickname | $formatted"
}

只要
bind
就可以了。

注意,持续时间并不是在所有情况下都显示正确的时间。试着把你的出生日期和你的下一个生日联系起来。它应该说“X年”,但它实际上返回“X年,Y天,Z秒”。如果您想要两个日期之间的时差,
duration
不是最佳选择。