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 

How to make a time limit between commands?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
JaySon
Voice


Joined: 04 Aug 2014
Posts: 6

PostPosted: Mon Aug 04, 2014 7:15 pm    Post subject: How to make a time limit between commands? Reply with quote

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).
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Mon Aug 04, 2014 9:04 pm    Post subject: Re: How to make a time limit between commands? Reply with quote

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:


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.
Back to top
View user's profile Send private message
JaySon
Voice


Joined: 04 Aug 2014
Posts: 6

PostPosted: Mon Aug 04, 2014 10:20 pm    Post subject: Reply with quote

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

Code:

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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Mon Aug 04, 2014 11:48 pm    Post subject: Reply with quote

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:


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. Smile
Back to top
View user's profile Send private message
JaySon
Voice


Joined: 04 Aug 2014
Posts: 6

PostPosted: Tue Aug 05, 2014 9:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Aug 06, 2014 12:54 am    Post subject: Reply with quote

Have a look at user's throttled function.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Aug 06, 2014 7:55 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Aug 06, 2014 7:58 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Aug 06, 2014 11:30 am    Post subject: Reply with quote

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.
Quote:

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:

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

if {[throttled $c 30]} {
for instance.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Aug 06, 2014 12:06 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Aug 07, 2014 12:55 am    Post subject: Reply with quote

The culprit is
Code:

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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Thu Aug 07, 2014 9:24 am    Post subject: Reply with quote

caesar wrote:
The culprit is
Code:

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.

Quote:

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.
Back to top
View user's profile Send private message
JaySon
Voice


Joined: 04 Aug 2014
Posts: 6

PostPosted: Fri Aug 08, 2014 5:20 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sat Aug 09, 2014 9:36 am    Post subject: Reply with quote

You've restarted the bot, haven't you? Smile
_________________
Once the game is over, the king and the pawn go back in the same box.
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 -> Scripting Help 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