1

New! Save questions or answers and organize your favorite content.
Learn more.

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]

I have got this code in my Tcl script, so each user will need to wait 24 hours before can do the command again. I would to put a countdown showing how much time (hours,minutes,seconds) they need to wait before can do it again. But at the moment the only thing I can do is put the seconds counting with the $calctime

Any idea how I can do it? Definitly my try of $calctime is a failure :P

2
  • 1
    Note the if condition is already processed by expr, so if {([unixtime] - $queue($variable))<86400} {... Dec 30, 2012 at 0:57
  • putquick is for stuff that are probably more urgent than sending your message, like kicks and bans. Use puthelp instead, or your channel could for example be flooded by someone while the eggdrop is busy with channel message(s). eggwiki.org/Queues#General_principle
    – potrzebie
    Dec 30, 2012 at 8:16

2 Answers 2

1

Treat the seconds as relative to the epoch with clock format. Don't leave out -gmt 1, or you'll get a number of hours wrong. How many depends on what timezone you're in.

putquick "PRIVMSG $channel :you cant because you need to wait \
  [clock format $calctime -format "%T" -gmt 1]"

Or calculate it yourself:

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"
3
  • Actually, the first method assumes that the epoch is at midnight (any-date-here 00:00:00), and I don't think Tcl 8.4 guarantees that. Tcl 8.5 does.
    – potrzebie
    Dec 30, 2012 at 20:04
  • ptrzebie, can you help me there? I tried what you said, and the result was: you cant because you need to wait 0 hours, 3 minutes and 8 seconds . but What I need is a countdown from 24hours to 0, not from 0 to 24 :x
    – user676032
    Dec 30, 2012 at 22:18
  • @user676032 Since you're not interested in when the user last used the command, but rather when he/she can use it again, save that in your array elements instead, i.e. add 24 * 60 * 60 when you save the time. Then use $queue($variable) - [unixtime] instead of [unixtime] - $queue($variable). And for god's sake, change the variable name queue to e.g. last_used and variable to e.g. nick.
    – potrzebie
    Dec 31, 2012 at 0:51
0

To display the time that the user have to wait you can use the eggdrop specific command 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.