0

我正在尝试设置一个简单的蛋滴机器人来倒计时直到某个事件。我的想法是我给它一个预定的日期和时间,用户输入 !countdown 并且机器人回复“还有 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]\)"    
}
4

1 回答 1

1

处理日期的难点在于解析和格式化,但您已经有了执行此操作的实用程序命令(durationclock format)。要计算未来某个事件的剩余时间,您只需确保在计算中为未来事件添加时间戳 -现在为时间戳。

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这样,你就走了。

于 2013-11-25T08:58:50.970 回答