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.

Restrictive timer

Old posts that have not been replied to for several years.
Locked
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Restrictive timer

Post by cvanmeer »

Hi all,

I have a question.

I have this command that will retrieve a certain server status from a webpage and report it on the channel.

But what I want is to put a restrictive timer on it, so the command (!status) can only be used once every one minute. And if someone triggers the command within that minute it will get a response like: Sorry, this command is blocked for $remainingtime.

Could someone please help me?
I've searched the forum but couldn't find what I was looking for.

Thx

Chrizz
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Set a variable to a unix timestamp when the command is called, and check against that variable when the user performs the command again...

for example....

Code: Select all

# there are 60 seconds in a minute, thus the < 60 ...
if {[info exists ourtimestamp] && [expr {[clock seconds] - $ourtimestamp}] < 60} {
  # command was already called less than a minute ago ...
} else {
  # command has not been called for atleast a minute ...
  set ourtimestamp [clock seconds]
}
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Post by cvanmeer »

Thx for your reply.

I've tried to implement your example, but it seems it doesn't work.
It seems to skip the first part and go right into the second part, not checking for the 60 seconds.

I've tried some stuff, but it didn't work out for me...

Any ideas how to fix it?

gr.

Chris
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

you need to make your variable globally declared within whatever procedure you are invoking the code in...
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Post by cvanmeer »

thx..that did the trick :)
I owe you one

Chrizz
Locked