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.

Setting $chan when not a arg

Help for those learning Tcl or writing their own scripts.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

forgot about this post.

Yes willyw, that would make the ping reply proc output to the $nick

I also changed to

Code: Select all

unset pingchan($nick)
and it works great :)
ComputerTech
D
DasBrain
Voice
Posts: 19
Joined: Thu Apr 08, 2021 12:31 pm

Post by DasBrain »

There is an other way - as you can pass any data through the CTCP ping (the other side will return the data back to you), you can use this to keep track of who this PING belongs to.

In other words, if you send a "/CTCP <somenick> PING FOO", they will reply with "/CTCR <yournick> PING FOO".

Code: Select all

set pingspending [dict create]
set pingcounter 0

proc ct:pub:ping {nick host hand chan text} {
   global pingpending pingcounter
   incr pingcounter
   set who [lindex [split $text] 0]
   dict set pingpending $pingcounter nick $nick
   dict set pingpending $pingcounter chan $chan
   dict set pingpending $pingcounter who $who
   dict set pingpending $pingcounter time [clock clicks -milliseconds]
   putquick "PRIVMSG $pingwho :\001PING $pingcounter\001"
}

proc ct:pingr {nick uhost hand dest keyword text} {
   global pingpending
   if {![dict exists $pingpending $text]} {return}
   set data [dict get pingpending $text]
   dict unset pingpending $text
   set time [expr {([clock clicks -milliseconds] - [dict get $data time]) / 1000.000}]
   set char "="
   if {[expr {round($time / 0.5)}] > 10} {set red 10} else {set red [expr {round($time / 0.5)}]}
   set green [expr {10 - $red}]
   set output \00303[string repeat $char $green]\003\00304[string repeat $char $red]\003
   if {($ctping(msg) == "0")} {
      putquick "PRIVMSG [dict get $data chan] :\[\0030${colo}PING\003\] reply from $nick: \[\0030${colo}$time\003\] seconds $output"
   } else {
      putquick "NOTICE [dict get $data nick] :\[\0030${colo}PING\003\] reply from $nick: \[\0030${colo}$time\003\] seconds"
   }
} 
Last edited by DasBrain on Thu Apr 15, 2021 3:07 pm, edited 2 times in total.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Interesting DasBrain, thanks very much for that :wink:
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Really interesting, I never tested this way to use ping (or probably other ctcp commands), it could help for some scripts.

Gonne read another time the rfc-1459 :)
Post Reply