View previous topic :: View next topic |
Author |
Message |
simo Owner
Joined: 22 Mar 2015 Posts: 980
|
Posted: Wed Sep 28, 2022 9:34 am Post subject: waiting time for public command reverse counting |
|
|
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/14087207/tcl-wait-time-in-countdown
i came up with this:
Code: |
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 |
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1074 Location: France
|
Posted: Wed Sep 28, 2022 10:09 am Post subject: |
|
|
This is simple mathematics.
If you want remaining time, just substract $duration from your delay:
Code: | set calctime [duration [expr {60 - ([clock seconds] - $last_used($nick!$uhost))}]] |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 980
|
Posted: Wed Sep 28, 2022 10:23 am Post subject: |
|
|
excellent thanks CrazyCat |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 980
|
Posted: Wed Sep 28, 2022 11:53 am Post subject: |
|
|
would the variable needs to be unset after threshold has been reached or is that cleared by eggdrop ? |
|
Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1074 Location: France
|
Posted: Wed Sep 28, 2022 2:07 pm Post subject: |
|
|
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. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 980
|
Posted: Wed Sep 28, 2022 2:53 pm Post subject: |
|
|
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: |
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!!!!!!!"
}
|
|
|
Back to top |
|
 |
|