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:

Setting $chan when not a arg

Post by ComputerTech »

So say i am needing $chan and its not in the proc's args

how would i set it? :lol:

like say when usind bind msg.

Code: Select all

proc name {nick host hand text} {
and not to just set a channel via script like

Code: Select all

set chan "#channel"
i mean the current channel arg :roll:

Thanks in advanced

EDIT
Havent tested yet (about to head out)

Code: Select all

set c [channels] {
would that be equivalent of $chan ?
Last edited by ComputerTech on Tue Feb 09, 2021 2:48 pm, edited 1 time in total.
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Well, you'd better read the doc:
channels : Returns: a list of the channels the bot has a channel record for
So, your line of code will create a list, including inactive channels.

Give us the context, or more your tcl, because our cristal ball is under repair
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Setting $chan when not a arg

Post by willyw »

ComputerTech wrote:So say i am needing $chan and its not in the proc's args
...
Start by asking yourself : Where is it?
Where ever that is - start there.

Is the channel in question determined somewhere? Is it in some variable, somewhere?
If it is, you just need to figure out how to get it from there, to where ever you next need it.
One possibility might be to utilize the global command.


But CrazyCat is right.
We cannot read your mind. :) Need more info.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

So i figured it out myself, and thought i could share what i wanted and hopefully help others :)

Code: Select all

bind pub "!test1" test:one

proc test:one {nick host hand chan text} {
set pingchan $chan
putserv "PRIVMSG $pingchan :Blah"
}

bind pub "test2" test:two

proc test:two {nick host hand text} {
global pingchan 
putserv "PRIVMSG $pingchan :Blah"
}
ComputerTech
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

The function that is triggered by the bind pub expects 5 arguments and you provided just 4 in your second function.

Code: Select all

proc test:two {nick host hand chan text} { 
	# your code
}
Once the game is over, the king and the pawn go back in the same box.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Meh, i'll post my entire script and not bother creating examples heh

Code: Select all

bind pub $ctping(flag) $ctping(trig)ping ct:pub:ping
bind ctcr - PING ct:pingr

set pingchan ""

 proc pub:ping {nick host hand chan text} {
  global pingchan pingwho
  set pingwho [lindex [split $text] 0]
     if {$pingwho == ""} {set pingwho $nick}
  putquick "PRIVMSG $pingwho :\001PING [clock clicks -milliseconds]\001"
  set pingchan $chan
 }
 proc ct:pingr {nick uhost hand dest keyword args} {
  global pingchan ctping colo pingwho char
  set time [expr {([clock clicks -milliseconds] - $args) / 1000.000}]
      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 $pingchan :\[\0030${colo}PING\003\] reply from $pingwho: $output \[\0030${colo}$time\003\] seconds"
  } else {
   putquick "NOTICE $nick :\[\0030${colo}PING\003\] reply from $pingwho: \[\0030${colo}$time\003\] seconds"
  }
 }
so as you can see proc 1 sets $pingchan and then use global to bring it to proc 2, script works perfect :)
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

It works because the ping reply is quick and you don't have a lot of queries.

If you have several users on several channels asking for a ping in a few delay, the reply can go to the bad chan.

You'd better store chan in an array:

Code: Select all

set pingchan($nick) $chan
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

Oh i see CrazyCat, Thank You for the idea :D
ComputerTech
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

CrazyCat wrote::
...

Code: Select all

set pingchan($nick) $chan

Just thinking ...

Wouldn't it be possible, with a lot of users, to thus have a huge array?
Would it consume a lot of memory?

Would it be wise to come up with some code to clear it all, somehow?
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Since there's no code to clear the array it will pile up and eat his RAM at some point. Apart this, he needs to add a piece of code to track nickname changes, parts, quits and maybe some flood control mechanism just to be on the safe side.
Once the game is over, the king and the pawn go back in the same box.
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Sure, I just gave an indication on the kind of variable to use, no more.
There is several examples here about how to manage that.
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

got a working version which does the job :D

Code: Select all

# Start Of Configuration #
##########################
#Set trigger of the Command.

set ctping(trig) "@"


##################
#Set flag for Commands.
##
#Owner     = n
#Master    = m
#Op        = o
#Voice     = v
#Friend    = f
#Everyone  = -
set ctping(flag) "-|-"


##################
#Set to use Notice Or Channel for Output of Command
##
#1 = Notice
#0 = Channel

set ctping(msg) "0"


##################
#Set Colour of Output
##
#White       = 0
#Black       = 1
#Dark Blue   = 2
#Green       = 3
#Red         = 4
#Brown       = 5
#Purple      = 6
#Orange      = 7
#Yellow      = 8
#Light Green = 9
#DarkCyan    = 10
#LightCyan   = 11
#LightBlue   = 12
#Pink        = 13
#Dark Grey   = 14
#Light Grey  = 15


set colo "3"


##################
#Set Time per usage of Command
##

set ctping(time) "5"


########################
# End Of Configuration #
#################################################################################################################################################################

bind pub $ctping(flag) $ctping(trig)ping ct:pub:ping
bind ctcr - PING ct:pingr


proc ct:pub:ping {nick host hand chan text} {
global pingchan pingwho
	set pingwho [lindex [split $text] 0]
	if {$pingwho == ""} {set pingwho $nick}
	putquick "PRIVMSG $pingwho :\001PING [clock clicks -milliseconds]\001"
	set pingchan($pingwho) $chan
}
proc ct:pingr {nick uhost hand dest keyword text} {
	global pingchan ctping colo pingwho
	set time [expr {([clock clicks -milliseconds] - $text) / 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 $pingchan($pingwho) :\[\0030${colo}PING\003\] reply from $pingwho: \[\0030${colo}$time\003\] seconds $output"
	} else {
		putquick "NOTICE $nick :\[\0030${colo}PING\003\] reply from $pingwho: \[\0030${colo}$time\003\] seconds"
	}
unset pingchan
}
Probably not the best heh :lol:
Last edited by ComputerTech on Wed Feb 10, 2021 7:58 pm, edited 1 time in total.
ComputerTech
User avatar
CrazyCat
Revered One
Posts: 1305
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

So you do:

Code: Select all

unset pingchan
You unset the full array when you got the first ping reply ? What about the others if they did !ping at the same moment ?

And you don't check if pingchan($pingwho) exists, you just use it... This code is not really better than your previous one, I'll try to show ytou how to do that in a few hours, it's sleepin time now :)
User avatar
ComputerTech
Master
Posts: 399
Joined: Sat Feb 22, 2020 10:29 am
Contact:

Post by ComputerTech »

well maybe i could do

Code: Select all

unset pingchan($nick)

I'll try come up with more ideas myself while you're sleeping. 8)
ComputerTech
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

ComputerTech wrote:

Code: Select all

...

		putquick "NOTICE $nick :\[\0030${colo}PING\003\] reply from 
...
...
What's stored in $nick there?
Is that what you really want there?
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Post Reply