如何修改eggdrop TCL脚本以使其有所不同

时间:2013-11-25 04:09:13

标签: tcl eggdrop

我正在尝试设置一个简单的eggdrop机器人,直到特定事件倒计时。我的想法是,我给它一个预定的日期和时间,用户输入!倒计时和机器人回复“有x天,x小时,x分钟直到它发生”。这是我发现它的脚本(仅更改为添加事件的unixtime日期代替它的内容),并且在eggdrop bot上运行它会给出响应,但当然不是我需要的响应(重要的)事情就是它起作用了。)

我认为它的作用与我想要它之间存在很大差异,但我不知道如何正确地修改它。所以我想知道这里是否有人能告诉我如何做我想做的事。

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]\)"    
}

1 个答案:

答案 0 :(得分:1)

使用日期的难点在于解析和格式化,但是您已经有了实用程序命令(durationclock format)。为了计算未来事件的剩余时间,您必须确保在计算中为时间戳 future event - timestamp now

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即可离开。