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).
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]
}
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]
}
JaySon wrote:Unfortunately, this does not work. Here is my code:
...
You can still execute the command successfully without waiting 30 seconds.
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
}
}
This is mysterious then. It doesn't do that for me. I just tried it, again - and it works for me.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.
I thought of that too, but seemed to recall that it throttles a particular user from re-using a command within a given time.caesar wrote:Have a look at user's throttled function.
From his example replace the:example limiting usage by same user@host on a specific channel
(the id part can be what ever you like of course)
Code: Select all
if {[throttled $u,$c 30]} {
Code: Select all
if {[throttled $c 30]} {
Code: Select all
if {[info exists wait_toggle]} {
Interesting.caesar wrote:The culprit isas 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.Code: Select all
if {[info exists wait_toggle]} {
Actually, that wouldn't be an error - as that is what it is supposed to do.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.