proc find {nick host hand chan arg} {
if {[string length $arg] < 3} {
# they put in less than four characters.. bitch at them
putquick "NOTICE $nick : oh pls n00b... use more than 2 characters ffs"
return
} else {
}
putquick "NOTICE $nick :4Starting Search For 9 [lindex [split $arg] 0] 4Please wait..."
set stat [exec_players]
set stat_arr [split $stat "\n"]
set i 0
set str $stat_arr
set found 0
# set str [lsort $stat_arr]
for {set i 0} {$i < [llength $str]} {incr i} {
set j [expr $i + 1]
# Loop through all the players and save them into a list
while {[string range [lindex $str $j] 0 6] == "Player:"} {
set player [string trimleft [lindex $str $j] "Player:"]
set playername [lindex [split $player " "] 2]
set server [join [lindex [split [lindex $str $i] ""] 1] " "]
if {[string first [string tolower $arg] [string tolower $playername]] != -1} then {
incr found
putquick "NOTICE $nick :$playername is on $server"
}
incr j
}
# Make sure we don't check through the players again
set i [expr $j - 1]
}
set info_str [get_number_of $found "player"]
putquick "NOTICE $nick :$info_str"
return 0
}
just add a utimer, set a variable to "1" while it is searching.. make it global, once 5 secs is gone (which you set with the utimer) you can set the variable to 0 again.. then just add a check on at the beginning of the proc which will return 0 and send te msg if the var == 1 , if not it will start a continue..
proc find {nick host hand chan arg} {
global findhold
if {[info exists findhold]} {
puthelp "PRIVMSG $nick :Search info system is busy, please try again in 5 seconds"
return
}
set findhold 1
utimer 5 [list catch {unset findhold}]
if {[string length $arg] < 3} {
# they put in less than four characters.. bitch at them
little problem is now Search info system is busy, please try again in 5 seconds come after the first user have search and the bot is ready to a new search
Black|Man wrote:little problem is now Search info system is busy, please try again in 5 seconds come after the first user have search and the bot is ready to a new search
Afaics, there is no real solution to the problem in this way. The proc is triggered, processes the request, gives results and is then ready for a new request. Note that all requests are processed sequentially.
The only way to have it the way you want is by having two individual and separated procs. In one proc you store the request and the timestamp. Any new requests are tested for the 5 seconds by this proc. In other words this proc is always available to process new requests.
The second proc, which may be triggered by the first proc (for example by a utimer), performs the find in the stats and outputs the result.
bind pub - !find trigfind
proc trigfind { nick uhost hand chan text } {
global findstamp
set currenttime [unixtime]
# Check if a timestamp exists
# Note that the existence of the "findstamp" indicates that the
# data processing is still busy. Or something went wrong
# during the data processing and the variable was never unset.
if { [info exists findstamp] } {
# It is assumed that the data processing always takes
# less than 10 seconds. This is a sanity check.
if { [expr $currenttime - $findstamp] < 10 } {
puthelp "PRIVMSG $chan :System is currently busy."
# do not proceed any further and ...
return
}
}
# trigger the stats data processing proc
utimer 0 [list execfind $chan $text]
# notify the channel: data processing has started
puthelp "PRIVMSG $chan :Data processing has started, please wait."
# reset the timestamp
set findstamp $currenttime
}
proc execfind { chan text } {
global findstamp
puthelp "PRIVMSG $chan :Hello $chan! ($text)."
# do stats data processing here
# ...
# ...
# ...
# end stats processing here
# unset the timestamp and eggdrop is ready for new
# requests.
if { [info exists findstamp] } { unset findstamp }
}
Last edited by egghead on Mon Jan 13, 2003 6:21 pm, edited 6 times in total.
proc find {nick host hand chan arg} {
if {[string length $arg] < 3} {
global findstamp
set currenttime [unixtime]
if { [info exists findstamp] } {
if { [expr $currenttime - $findstamp] < 10 } {
puthelp "PRIVMSG $chan :System is currently busy."
return
# they put in less than four characters.. bitch at them
putquick "NOTICE $nick : oh pls n00b... use more than 2 characters ffs"
return
} else {
}
putquick "NOTICE $nick :4Starting Search For 9 [lindex [split $arg] 0] 4Please wait..."
set stat [exec_players]
set stat_arr [split $stat "\n"]
set i 0
set str $stat_arr
set found 0
# set str [lsort $stat_arr]
for {set i 0} {$i < [llength $str]} {incr i} {
set j [expr $i + 1]
# Loop through all the players and save them into a list
while {[string range [lindex $str $j] 0 6] == "Player:"} {
set player [string trimleft [lindex $str $j] "Player:"]
set playername [lindex [split $player " "] 2]
set server [join [lindex [split [lindex $str $i] ""] 1] " "]
if {[string first [string tolower $arg] [string tolower $playername]] != -1} then {
incr found
putquick "NOTICE $nick :$playername is on $server"
}
incr j
}
# Make sure we don't check through the players again
set i [expr $j - 1]
}
set info_str [get_number_of $found "player"]
putquick "NOTICE $nick :$info_str"
return 0
}
}
utimer 0 [exec_players]
puthelp "PRIVMSG $chan :Data processing has started, please wait."
set findstamp $currenttime
}
You are mudding around with tcl without attempting to understand what you are doing. In other words, you are taking random bits and pieces of the suggestions made here and insert them at more or less random places in your existing script.
If you want to modify a tcl beyond trivial string modifications (such as modifying "hello world" into "hello channel"), you must go through it step by step and understand what is happening and what you are doing.
It was suggested earlier to use two separated procs. But you continue to use one single proc.
One proc takes care of the trigger and the other proc takes care of the execution of the players data processing.
The reason why you get the error message is because the variable "currenttime" only gets set "if {[string length $arg] < 3}". But this is not the root problem.
proc find {nick host hand chan arg} {
global findstamp
if {[string length $arg] < 3} {
putquick "NOTICE $nick : oh pls n00b... use more than 2 characters ffs"
return 0
}
if {[info exists findstamp]} {
if {[expr [unixtime] - $findstamp] < 10} {
puthelp "NOTICE $nick : ystem is currently busy."
return 0
}
}
putquick "NOTICE $nick 4Starting Search For 9 [lindex [split $arg] 0] 4Please wait..."
set stat [exec_players]
set stat_arr [split $stat "\n"]
set i 0
set str $stat_arr
set found 0
# set str [lsort $stat_arr]
for {set i 0} {$i < [llength $str]} {incr i} {
set j [expr $i + 1]
# Loop through all the players and save them into a list
while {[string range [lindex $str $j] 0 6] == "Player:"} {
set player [string trimleft [lindex $str $j] "Player:"]
set playername [lindex [split $player " "] 2]
set server [join [lindex [split [lindex $str $i] "] 1] " "]
if {[string first [string tolower $arg] [string tolower $playername]] != -1} then {
incr found
putquick "NOTICE $nick :$playername is on $server"
}
incr j
}
# Make sure we don't check through the players again
set i [expr $j - 1]
}
set info_str [get_number_of $found "player"]
putquick "NOTICE $nick :$info_str"
catch {unset findstamp}
return 0
}