This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

waiting time for public command reverse counting

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

waiting time for public command reverse counting

Post by simo »

greetingz gentz,

i was trying out this small code to count time remaining before able to use a public command again i found here :

https://stackoverflow.com/questions/140 ... -countdown

i came up with this:

Code: Select all

bind pub -|- !rdigits pub:testwait

proc pub:testwait {nick uhost hand chan text} {
 global last_used
  if {![isop $nick $chan] && ![ishalfop $nick $chan] && ![matchattr $hand o|o $chan]} { return 0 }
 if {[info exists last_used($nick!$uhost)]} {
    if {[clock seconds] - $last_used($nick!$uhost) < 60*1*1 } {
        set calctime [duration [expr {[clock seconds] - $last_used($nick!$uhost)}]]
       putserv "notice $nick :$uhost you cant because you need to wait $calctime"
        return
    }
}
  set last_used($nick!$uhost) [clock seconds]   
 putserv "privmsg $chan checked!!!!!!!"
}

so instead of output the remaining time to wait it seems to output the time that has been waited
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

This is simple mathematics.
If you want remaining time, just substract $duration from your delay:

Code: Select all

set calctime [duration [expr {60 - ([clock seconds] - $last_used($nick!$uhost))}]]
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

excellent thanks CrazyCat
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

would the variable needs to be unset after threshold has been reached or is that cleared by eggdrop ?
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I think you play with tcl since enough time to be able to read and understand the code, and what it does or does not.
s
simo
Revered One
Posts: 1071
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thank you CrazyCat i tried it this way would this be a proper way to clear the variable after the the threshold has been reached ?

Code: Select all

bind pub -|- !wait pub:testwaitingtime

proc pub:testwaitingtime {nick uhost hand chan text} {
 global last_used
 if {![isop $nick $chan] && ![ishalfop $nick $chan] && ![matchattr $hand o|o $chan]} { return 0 }
 if {[info exists last_used($nick!$uhost)]} {
    if {[clock seconds] - $last_used($nick!$uhost) < 60*1*1 } {
        set calctime [duration [expr {60*1*1 - ([clock seconds] - $last_used($nick!$uhost))}]]
        set calctime2 [expr {60*1*1 - ([clock seconds] - $last_used($nick!$uhost))}]
       putserv "notice $nick :$uhost you cant because you need to wait $calctime"
        if {$calctime2 < 2} { array unset last_used($nick!$uhost) }
        return
    }      
}
 set last_used($nick!$uhost) [clock seconds]   
 putserv "privmsg $chan checked!!!!!!!"
}
Post Reply