This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Need Idle Check TCL

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Need Idle Check TCL

Post by Hero »

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
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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]]"
}


w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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]
 
}


Don't load both scripts at the same time. One or the other, never both.


I hope this helps.
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

Thanks Willyw Its Working Awesome
Thanks For Help :)
The Road To Hell Is Full Of Good Intentions
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Hero wrote:Thanks Willyw
You're welcome.
Its Working Awesome
Which one did you decide to use?
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

2nd Is Better Then 1st ;)
The Road To Hell Is Full Of Good Intentions
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Hero wrote:2nd Is Better Then 1st ;)
Excellent. :)
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

Yeh ;)
The Road To Hell Is Full Of Good Intentions
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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: Select all

if {![llength $user]} {
# do whatever, $user is empty
}
A better approach is to use scan instead of:

Code: Select all

 if {[lindex [split $text] 0] == ""} {
      putserv "privmsg $chan :Syntax: !idle <nick>"
      return 0
         }

   set user [lindex [split $text] 0] 
would simply be:

Code: Select all

if {[scan $text {%s} user] != 1} {
	puthelp "PRIVMSG $chan :Syntax: !idle <nick>"
	return
}
Same thing goes with the:

Code: Select all

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: Select all

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.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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.
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.
and even then you should use llength in the if statement like:

Code: Select all

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.

A better approach is to use scan instead of:

Code: Select all

 if {[lindex [split $text] 0] == ""} {
      putserv "privmsg $chan :Syntax: !idle <nick>"
      return 0
         }

   set user [lindex [split $text] 0] 
would simply be:

Code: Select all

if {[scan $text {%s} user] != 1} {
	puthelp "PRIVMSG $chan :Syntax: !idle <nick>"
	return
}
You forgot to say WHY it is better.
Same thing goes with the:

Code: Select all

putserv "privmsg $working_chan :[lindex [split $text] 1] idle time is: [duration [lindex [split $text] 2]]"   
at least
?
Why does it matter?
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]"
}
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

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
}
@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 :roll: :lol:
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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.
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.
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.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

@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: Select all

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.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote:@willyw : A bit cocky aren't we?
No.
I resent the implication.
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.)

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.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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: 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}
}
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
Post Reply