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.

How to make a time limit between commands?

Help for those learning Tcl or writing their own scripts.
Post Reply
J
JaySon
Voice
Posts: 6
Joined: Mon Aug 04, 2014 7:12 pm

How to make a time limit between commands?

Post by JaySon »

Is there a quick/easy/simple way to make some sort of delay between the bind commands? So the command can only be used once every minute or whatever (and the bot seconds a PRIVMSG stating this information).
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Re: How to make a time limit between commands?

Post by willyw »

JaySon wrote:Is there a quick/easy/simple way to make some sort of delay between the bind commands? So the command can only be used once every minute or whatever (and the bot seconds a PRIVMSG stating this information).

I do this with one little script of mine. I just didn't want the proc to be hammered.

Example:

Code: Select all


bind pub - "!your_command" your_proc

proc your_proc {nick uhost handle chan text} {
global wait_toggle

       if {[info exists wait_toggle]} {
                putserv "notice $nick :Wait [lindex [utimers] [lsearch -index 1 [utimers] *wait_toggle*] 0] seconds, and try again"
                return 0
           }


      ###########
      
      # in here is whatever you want, for your proc
   
      ###########


	set wait_toggle "1"
        utimer 20 [list unset wait_toggle]


}

This will create a 20 second delay. If the proc is called within 20 seconds after first being called, it will notice the user that triggered the bind, telling him how long to wait before trying again.

I hope this helps.

You might get other and better ideas, too.



p.s.
I had to make a few small edits from my original working code. I hope I made no typos.
J
JaySon
Voice
Posts: 6
Joined: Mon Aug 04, 2014 7:12 pm

Post by JaySon »

Unfortunately, this does not work. Here is my code:

Code: Select all

bind pub - !test test

proc test {nick uhost hand chan args} {
global test1targets test2targets test2places test1places wait_toggle
       if {[info exists wait_toggle]} {
                puthelp "PRIVMSG $nick :Wait a bit"
                return 0
           }
	set test1place [lindex $test1places [rand [llength test1places]]]
	set dummies [lindex $test1targets [rand [llength $test1targets]]]
      if ![file exists "/eggdrop/scripts/test1"] {
       set f [open "/eggdrop/scripts/test1" w]
       puts $f "test 1 a"
       close $f
      }
	set f [open "/eggdrop/scripts/test1" r]
	gets $f testrec
	close $f
	set maxtest1 [lindex $testrec 1]
      set maxtest1 [expr $maxtest1 + 100]
	set testnumber [rand $maxtest1]
	puthelp "PRIVMSG $chan :$nick testing"
	if [rand 2] {
		utimer 2 [list puthelp "privmsg $chan :testing 2"]
	} else {
		utimer 2 [list puthelp "privmsg $chan :testing 3"]
		return 1
	}
set f [open "/eggdrop/scripts/test1" r]
gets $f testrec
close $f
if { $testnumber > [lindex $testrec 1] } {
	utimer 4 [list puthelp "privmsg $chan :great test"]
	utimer 6 [list puthelp "privmsg $chan :very great"]
	set f [open "/eggdrop/scripts/test1" w]
	puts $f "$nick $testnumber $dummies"
	close $f
	return 1
} else {
	utimer 4 [list puthelp "privmsg $chan :no test"]
	return 1
}
   set wait_toggle "1"
        utimer 30 [list unset wait_toggle]
}
You can still execute the command successfully without waiting 30 seconds.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

JaySon wrote:Unfortunately, this does not work. Here is my code:
...
You can still execute the command successfully without waiting 30 seconds.

Yep.
Mine was simple, and obviously different.

See what I moved:

Code: Select all


bind pub - !test test

proc test {nick uhost hand chan args} {
global test1targets test2targets test2places test1places wait_toggle
       if {[info exists wait_toggle]} {
                puthelp "PRIVMSG $nick :Wait a bit"
                return 0
           }

# Just cut this from where it was, and paste it here
  set wait_toggle "1"
        utimer 30 [list unset wait_toggle]


   set test1place [lindex $test1places [rand [llength test1places]]]
   set dummies [lindex $test1targets [rand [llength $test1targets]]]
      if ![file exists "/eggdrop/scripts/test1"] {
       set f [open "/eggdrop/scripts/test1" w]
       puts $f "test 1 a"
       close $f
      }
   set f [open "/eggdrop/scripts/test1" r]
   gets $f testrec
   close $f
   set maxtest1 [lindex $testrec 1]
      set maxtest1 [expr $maxtest1 + 100]
   set testnumber [rand $maxtest1]
   puthelp "PRIVMSG $chan :$nick testing"
   if [rand 2] {
      utimer 2 [list puthelp "privmsg $chan :testing 2"]
   } else {
      utimer 2 [list puthelp "privmsg $chan :testing 3"]
      return 1
   }
set f [open "/eggdrop/scripts/test1" r]
gets $f testrec
close $f
if { $testnumber > [lindex $testrec 1] } {
   utimer 4 [list puthelp "privmsg $chan :great test"]
   utimer 6 [list puthelp "privmsg $chan :very great"]
   set f [open "/eggdrop/scripts/test1" w]
   puts $f "$nick $testnumber $dummies"
   close $f
   return 1
} else {
   utimer 4 [list puthelp "privmsg $chan :no test"]
   return 1
}
 
} 

Try that.
( with some made up values to the global variables, and different paths,
it worked for me. Bot pm'd me with "Wait a bit". )

I have no idea why I did it the way I first showed it to you.
That was from the little script that I threw together for myself, long ago.
I remembered it, found it, and picked out the lines, and posted here.

I hope this works for you now. :)
J
JaySon
Voice
Posts: 6
Joined: Mon Aug 04, 2014 7:12 pm

Post by JaySon »

Hi willyw, thanks for your time.

Unfortunately, this now sends the message "wait a bit" even when it's the first time the person has issues the command. So now users can never issue the !test command without it executing the proper commands. It always just says "wait a bit" every single time the command is issued.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Have a look at user's throttled function.
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

JaySon wrote: ...
Unfortunately, this now sends the message "wait a bit" even when it's the first time the person has issues the command. So now users can never issue the !test command without it executing the proper commands. It always just says "wait a bit" every single time the command is issued.
This is mysterious then. It doesn't do that for me. I just tried it, again - and it works for me.

We need to figure out what I'm doing different from you, or vice versa.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote:Have a look at user's throttled function.
I thought of that too, but seemed to recall that it throttles a particular user from re-using a command within a given time.
Do you know - is that correct?

I think JaySon wants some command to be protected from repeated use by anybody, for a given amount of time.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If you use it as is in his example and have nick,channel as id then that's correct, but this doesn't stop you from changing from nick,channel to just channel.
example limiting usage by same user@host on a specific channel
(the id part can be what ever you like of course)
From his example replace the:

Code: Select all

if {[throttled $u,$c 30]} {
to:

Code: Select all

if {[throttled $c 30]} {
for instance.
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Ah.
That's interesting, and could be a "better" idea for JaySon.

Have you read all the above? Any ideas as to why the simple thing that I've done is behaving differently for him and me?

Thanks.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The culprit is

Code: Select all

if {[info exists wait_toggle]} { 
as my guess in his case is that the wait_toggle variable exist and wasn't unset yet or won't be at all unless restarts the bot. It was working for you cos that variable didn't exist, but starting with the second !test should you get the same error if you issued the same command withing the 30 seconds time frame.
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote:The culprit is

Code: Select all

if {[info exists wait_toggle]} { 
as my guess in his case is that the wait_toggle variable exist and wasn't unset yet or won't be at all unless restarts the bot.
Interesting.
It was working for you cos that variable didn't exist, but starting with the second !test should you get the same error if you issued the same command withing the 30 seconds time frame.
Actually, that wouldn't be an error - as that is what it is supposed to do.

Perhaps instead of checking for the existence of the variable, it would be better to set it to 0, and change it to 1, and back and forth like that - and check the value.
I really don't know why I did it the way I did - it was quick, and quite some time ago.

Thanks for your input.
J
JaySon
Voice
Posts: 6
Joined: Mon Aug 04, 2014 7:12 pm

Post by JaySon »

Actually, it seems to be behaving the way it should for the most part now. I haven't changed anything from willyw's original suggestion, but if it ain't broke... I'll just leave it the way it is for now. Thanks all.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You've restarted the bot, haven't you? :)
Once the game is over, the king and the pawn go back in the same box.
Post Reply