| View previous topic :: View next topic |
| Author |
Message |
Hero Halfop
Joined: 26 Jun 2012 Posts: 49 Location: root@localhost
|
Posted: Thu Nov 29, 2012 2:13 pm Post subject: Need Idle Check TCL |
|
|
Hello I Wanna Request Idle Check Tcl
Like:
<+Hero> !Idle Hero
<&Bot> Hero Idle Time Is: 5hrs 20mins 36secs
Thanks In Advance _________________ The Road To Hell Is Full Of Good Intentions |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Nov 29, 2012 3:09 pm Post subject: |
|
|
| Code: |
# 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]]"
}
|
|
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Nov 29, 2012 3:12 pm Post subject: |
|
|
| Code: |
# 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]
}
|
Don't load both scripts at the same time. One or the other, never both.
I hope this helps. |
|
| Back to top |
|
 |
Hero Halfop
Joined: 26 Jun 2012 Posts: 49 Location: root@localhost
|
Posted: Thu Nov 29, 2012 3:22 pm Post subject: |
|
|
Thanks Willyw Its Working Awesome
Thanks For Help  _________________ The Road To Hell Is Full Of Good Intentions |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Nov 29, 2012 3:34 pm Post subject: |
|
|
| Hero wrote: | Thanks Willyw
|
You're welcome.
| Quote: |
Its Working Awesome
|
Which one did you decide to use? |
|
| Back to top |
|
 |
Hero Halfop
Joined: 26 Jun 2012 Posts: 49 Location: root@localhost
|
Posted: Thu Nov 29, 2012 3:41 pm Post subject: |
|
|
2nd Is Better Then 1st  _________________ The Road To Hell Is Full Of Good Intentions |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Thu Nov 29, 2012 3:53 pm Post subject: |
|
|
| Hero wrote: | 2nd Is Better Then 1st  |
Excellent.  |
|
| Back to top |
|
 |
Hero Halfop
Joined: 26 Jun 2012 Posts: 49 Location: root@localhost
|
Posted: Thu Nov 29, 2012 4:26 pm Post subject: |
|
|
Yeh  _________________ The Road To Hell Is Full Of Good Intentions |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Nov 30, 2012 1:29 am Post subject: |
|
|
Why do you split the same variable twice and not just one and reuse it? 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, and even then you should use llength in the if statement like:
| Code: |
if {![llength $user]} {
# do whatever, $user is empty
}
|
A better approach is to use scan instead of:
| Code: |
if {[lindex [split $text] 0] == ""} {
putserv "privmsg $chan :Syntax: !idle <nick>"
return 0
}
set user [lindex [split $text] 0]
|
would simply be:
| Code: |
if {[scan $text {%s} user] != 1} {
puthelp "PRIVMSG $chan :Syntax: !idle <nick>"
return
}
|
Same thing goes with the:
| Code: |
putserv "privmsg $working_chan :[lindex [split $text] 1] idle time is: [duration [lindex [split $text] 2]]"
|
at least split the $text once and reuse it as many times you wish, or use scan instead and get something like:
| Code: |
if {[scan $text {%s%s%s} raw user idle] >= 3} {
puthelp "PRIVMSG $working_chan :$user idle time is: [duration $idle]"
}
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri Nov 30, 2012 2:44 pm Post subject: |
|
|
| caesar wrote: | Why do you split the same variable twice and not just one and reuse it?
|
Probably because it was used only twice in that procedure.
| Quote: |
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,
|
That is in a different procedure.
| Quote: |
and even then you should use llength in the if statement like:
| Code: |
if {![llength $user]} {
# do whatever, $user is empty
}
|
|
"should" ??
I'm just self taught. If there is some principle or convention of good TCL programming that I've violated, that is why I'm unaware of it.
Perhaps you could point me - with a link - to some good reading on that, particularly this example that you've pointed out.
| Quote: |
A better approach is to use scan instead of:
| Code: |
if {[lindex [split $text] 0] == ""} {
putserv "privmsg $chan :Syntax: !idle <nick>"
return 0
}
set user [lindex [split $text] 0]
|
would simply be:
| Code: |
if {[scan $text {%s} user] != 1} {
puthelp "PRIVMSG $chan :Syntax: !idle <nick>"
return
}
|
|
You forgot to say WHY it is better.
| Quote: |
Same thing goes with the:
| Code: |
putserv "privmsg $working_chan :[lindex [split $text] 1] idle time is: [duration [lindex [split $text] 2]]"
|
at least
|
?
Why does it matter?
| Quote: |
split the $text once and reuse it as many times you wish, or use scan instead and get something like:
| Code: |
if {[scan $text {%s%s%s} raw user idle] >= 3} {
puthelp "PRIVMSG $working_chan :$user idle time is: [duration $idle]"
}
|
|
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Fri Nov 30, 2012 11:00 pm Post subject: |
|
|
| caesar wrote: | and even then you should use llength in the if statement like: | Code: | if {![llength $user]} {
# do whatever, $user is empty
}
|
|
@caeser:
Since when do we allow strings ( $user is a string here ) to be manipulated with list commands ( llength works on lists )?...........(correct answer is, since never )
Did you mean ![string length $user]? Sometimes in our rush to correct others problems, we cause them to inherit ours. There are several ways to skin a cat, which one is the best method is usually best left up to the cat killer. Don't you agree?
@caesar and @willyw:
BTW caesar, I like you dude. You do plenty for this site yo. Don't take this as some swipe at your credibility. Same as willyw, props yo. But this is beyond the scope of OP's original topic in this thread. So I'll get to the point....
Why does it matter?
It doesn't. Sometimes there are several ways to skin a cat, and to argue over which is best. 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.
BTW: lol... roflcopter...lollerskates  _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri Nov 30, 2012 11:23 pm Post subject: |
|
|
| speechles wrote: |
....
Why does it matter?
It doesn't.
|
That's what I thought. But, rather than assume, it is best to simply ask - so I did.
There is always the possibility that there is something to be learned, if the source is credible.
| Quote: |
Sometimes there are several ways to skin a cat, and to argue over which is best.
|
Just so there is no confusion - I wasn't.
| Quote: |
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.
|
Don't worry about that with me. I was replying. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Dec 01, 2012 1:03 pm Post subject: |
|
|
@willyw : A bit cocky aren't we? What I've suggested isn't written in stone somewhere, is just a suggestion and it's up to you if you wish to use any or not.
No matter the language of programming, you should reuse the code where you can as it would be easier to debug, edit and follow a code.
@speechles : if I where to compare me with ppslim for instance, I didn't do [censored].
Anyway, what's the difference between variable $a and $b
| Code: |
set a "one"
set b "one two"
|
that apart that second variable has two elements in it? Is variable $b a list or not? If I would remove an element from variable $b, would it no longer a list? why?
For me, the easiest way to check if a variable is empty is to use llength instead of string equal, or any other method you could come out with, for instance scan. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sat Dec 01, 2012 1:19 pm Post subject: |
|
|
| caesar wrote: | @willyw : A bit cocky aren't we?
|
No.
I resent the implication.
| Quote: |
What I've suggested isn't written in stone somewhere, is just a suggestion
|
You did not present it as merely your opinion.
I simply read what you wrote, and replied. (I suggest you do that also... perhaps you read into other's words that which is not there.)
| Quote: |
and it's up to you if you wish to use any or not.
|
Of course. And I decide that based on the validity - or at least perceived validity of the source. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Dec 01, 2012 1:37 pm Post subject: |
|
|
Just for the fun of it...
Variable a contains a string with a single word. Additionally, the string is list-like.
Variable b contains a string with two words separated by a space. Additionally, the string is list-like.
These two cases are trivial, since the equivalent tcl-list would be identical to the string. There is, however, the more complex cases:
| Code: | set c1 "{one"
set c2 [list "{one"]
set d1 "{one two}"
set d2 [list "{one" "two}"] |
In this case, neither c1 nor d1 are list-like, and list-commands will have problems making the proper actions on these.
c2 and d2 on the other hand, are properly defined lists, and will work as expected with all list commands.
Another example:
| Code: | 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}
} |
Here, data is a string containing a few spaces. It is list-like with no elements, yet the variable is not empty.
Since tcl variables are not typed, it is generally a very good idea to separate lists, strings and integers; and using the various interfaces for converting inbetween these. Hand-crafting lists works well, if you are well-aware of what you are doing. It is unwize to assume any channel-user having access to this script will, or that they will not attempt to exploit it. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|