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.

[SOLVED] Excessive command use

Help for those learning Tcl or writing their own scripts.
Post Reply
W
Way2Death
Voice
Posts: 15
Joined: Tue Mar 31, 2009 3:30 pm

[SOLVED] Excessive command use

Post by Way2Death »

He this should be simple, but i cant seem to find the right keyword to search it....

how would i set a lock on my command to prevent it from over using,
like if you type
!show
!show
you would get : Please wait at least 5 minutes to re-use this command
Last edited by Way2Death on Tue Apr 07, 2009 2:21 pm, edited 1 time in total.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Code: Select all

set vFlood [expr {[unixtime] - 300}]

bind PUB - !show pShow

proc pShow {nick uhost hand channel txt} {
    global vFlood
    if {[expr {[unixtime] - $vFlood}] > 299} {
        set vFlood [unixtime]

        # your code here

    } else {putserv "PRIVMSG $channel :sorry $nick, there is a 5 minute wait between successive uses of the command !show"}
    return 0
}
I must have had nothing to do
W
Way2Death
Voice
Posts: 15
Joined: Tue Mar 31, 2009 3:30 pm

Post by Way2Death »

All right thanks, so what is this called? Excessive command use?
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

It doesn't have a specific name. It is simply one method of preventing overuse of a command. Command flood control I suppose you could say.

btw I have edited the code a little, be sure to reread it

In plain english, the command will only trigger if the last time it was used is more than 299 seconds ago (or if the bot was just rehashed/restarted).
Last edited by arfer on Mon Apr 06, 2009 9:50 am, edited 1 time in total.
I must have had nothing to do
W
Way2Death
Voice
Posts: 15
Joined: Tue Mar 31, 2009 3:30 pm

Post by Way2Death »

arfer wrote:It doesn't have a specific name. It is simply one method of preventing overuse of a command. Command flood control I suppose you could say.
All right, thanks so much =D i appreciate the help!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I believe the most common term is "throttling".
I recall user posted a nice proc (function) called "throttled" a long time ago, to make it simple to add such checks to any code. A quick search in the forum would probably reveal it. (arfer's code should do the trick just as well).
NML_375
Post Reply