egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

waiting time for public command reverse counting

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
simo
Owner


Joined: 22 Mar 2015
Posts: 980

PostPosted: Wed Sep 28, 2022 9:34 am    Post subject: waiting time for public command reverse counting Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1074
Location: France

PostPosted: Wed Sep 28, 2022 10:09 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 980

PostPosted: Wed Sep 28, 2022 10:23 am    Post subject: Reply with quote

excellent thanks CrazyCat
Back to top
View user's profile Send private message
simo
Owner


Joined: 22 Mar 2015
Posts: 980

PostPosted: Wed Sep 28, 2022 11:53 am    Post subject: Reply with quote

would the variable needs to be unset after threshold has been reached or is that cleared by eggdrop ?
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1074
Location: France

PostPosted: Wed Sep 28, 2022 2:07 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 980

PostPosted: Wed Sep 28, 2022 2:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber