Code: Select all
# Nov 29, 2012
# reference: http://forum.egghelp.org/viewtopic.php?t=19178
# Hero
#
# New postPosted: Today at 1:13 pm Post subject: Need Idle Check TCL Reply with quote
# Hello I Wanna Request Idle Check Tcl
# Like:
# <+Hero> !Idle Hero
# <&Bot> Hero Idle Time Is: 5hrs 20mins 36secs
# Thanks In Advance
######################### simple script - resolution to the minute, using bot's built in idle function ###########
bind pub - "!idle" say_idle_time
proc say_idle_time {nick uhost handle chan text} {
if {[lindex [split $text] 0] == ""} {
putserv "privmsg $chan :Syntax: !idle <nick>"
return 0
}
set user [lindex [split $text] 0]
if {![onchan $user $chan]} {
putserv "privmsg $chan :Sorry, $user is not on $chan"
return 0
}
putserv "privmsg $chan :$user idle time in $chan is: [duration [getchanidle $user $chan]]"
}
Code: Select all
# Nov 29, 2012
# reference: http://forum.egghelp.org/viewtopic.php?t=19178
# Hero
#
# New postPosted: Today at 1:13 pm Post subject: Need Idle Check TCL Reply with quote
# Hello I Wanna Request Idle Check Tcl
# Like:
# <+Hero> !Idle Hero
# <&Bot> Hero Idle Time Is: 5hrs 20mins 36secs
# Thanks In Advance
###################### Method - have bot do /whois on user, and get the idle time from return. Should give resolution in seconds, as requested ########
bind pub - "!idle" get_idle_time_whois
proc get_idle_time_whois {nick uhost handle chan text} {
global working_chan
if {[lindex [split $text] 0] == ""} {
putserv "privmsg $chan :Syntax: !idle <nick>"
return 0
}
set user [lindex [split $text] 0]
if {![onchan $user $chan]} {
putserv "privmsg $chan :Sorry, $user is not on $chan"
return 0
}
set working_chan $chan
bind raw - 317 got_whois
putserv "whois $user $user"
}
proc got_whois {from keyword text} {
global working_chan
putserv "privmsg $working_chan :[lindex [split $text] 1] idle time is: [duration [lindex [split $text] 2]]"
utimer 5 [list unbind raw - 317 got_whois]
}
Code: Select all
if {![llength $user]} {
# do whatever, $user is empty
}
Code: Select all
if {[lindex [split $text] 0] == ""} {
putserv "privmsg $chan :Syntax: !idle <nick>"
return 0
}
set user [lindex [split $text] 0]
Code: Select all
if {[scan $text {%s} user] != 1} {
puthelp "PRIVMSG $chan :Syntax: !idle <nick>"
return
}
Code: Select all
putserv "privmsg $working_chan :[lindex [split $text] 1] idle time is: [duration [lindex [split $text] 2]]"
Code: Select all
if {[scan $text {%s%s%s} raw user idle] >= 3} {
puthelp "PRIVMSG $working_chan :$user idle time is: [duration $idle]"
}
Probably because it was used only twice in that procedure.caesar wrote:Why do you split the same variable twice and not just one and reuse it?
That is in a different procedure.Meaning at least define the user (set user [lindex [split $text] 0]) before the if statement cos you will check if it's empty or not,
"should" ??and even then you should use llength in the if statement like:Code: Select all
if {![llength $user]} { # do whatever, $user is empty }
You forgot to say WHY it is better.A better approach is to use scan instead of:would simply be:Code: Select all
if {[lindex [split $text] 0] == ""} { putserv "privmsg $chan :Syntax: !idle <nick>" return 0 } set user [lindex [split $text] 0]
Code: Select all
if {[scan $text {%s} user] != 1} { puthelp "PRIVMSG $chan :Syntax: !idle <nick>" return }
?Same thing goes with the:at leastCode: Select all
putserv "privmsg $working_chan :[lindex [split $text] 1] idle time is: [duration [lindex [split $text] 2]]"
split the $text once and reuse it as many times you wish, or use scan instead and get something like:Code: Select all
if {[scan $text {%s%s%s} raw user idle] >= 3} { puthelp "PRIVMSG $working_chan :$user idle time is: [duration $idle]" }
@caeser:caesar wrote:and even then you should use llength in the if statement like:Code: Select all
if {![llength $user]} { # do whatever, $user is empty }
That's what I thought. But, rather than assume, it is best to simply ask - so I did.speechles wrote: ....
Why does it matter?
It doesn't.
Just so there is no confusion - I wasn't.Sometimes there are several ways to skin a cat, and to argue over which is best.
Don't worry about that with me. I was replying.Who cares as long as both approaches end with the same net result, a skinned cat. It's still murder either way. So stop murdering each other.
Code: Select all
set a "one"
set b "one two"
No.caesar wrote:@willyw : A bit cocky aren't we?
You did not present it as merely your opinion.What I've suggested isn't written in stone somewhere, is just a suggestion
Of course. And I decide that based on the validity - or at least perceived validity of the source.and it's up to you if you wish to use any or not.
Code: Select all
set c1 "{one"
set c2 [list "{one"]
set d1 "{one two}"
set d2 [list "{one" "two}"]
Code: Select all
set data " "
if {[llength $data] > 0} {
puts stdout {$data is empty}
} else {
puts stdout {$data is not empty}
}
if {[string length $data] > 0} {
puts stdout {$data is empty}
} else {
puts stdout {$data is not empty}
}