2013-11-25 33 views
0

我正在嘗試設置一個簡單的蛋清機器人,讓倒計時直到某個事件發生。這個想法是,我給它一個預定的日期和時間,用戶鍵入!倒計時和機器人回答「有x天,x小時,x分鐘,直到它發生」。這是我發現它的腳本(只改變了事件的unixtime日期而不是它的內容),並且在我的eggdrop bot上運行它給出了一個響應,但它當然不是我需要的響應(重要的事情是,它的工作)。我如何修改這個蛋液滴TCL腳本,使其工作方式有點不同

我不認爲它做什麼和我想要做什麼之間有很大的區別,但我不知道如何正確地修改它。所以我想知道這裏有沒有人能告訴我如何去做我想做的事情。

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

使用日期是解析和格式,但你已經有了實用的困難的部分命令來做到這一點(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這和你走了。

+0

請注意,持續時間在所有情況下都不會顯示正確的時間。試試你的下一個生日的出生日期。應該說「X年」,但實際上它返回「X年,Y日Z秒」。如果你想要兩個日期之間的時間差,「持續時間」不是最好的選擇。 –

相關問題