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.
Help for those learning Tcl or writing their own scripts.
ComputerTech
Master
Posts: 399 Joined: Sat Feb 22, 2020 10:29 am
Contact:
Post
by ComputerTech » Mon Feb 08, 2021 4:27 am
So say i am needing $chan and its not in the proc's args
how would i set it?
like say when usind bind msg.
and not to just set a channel via script like
i mean the current channel arg
Thanks in advanced
EDIT
Havent tested yet (about to head out)
would that be equivalent of $chan ?
Last edited by
ComputerTech on Tue Feb 09, 2021 2:48 pm, edited 1 time in total.
ComputerTech
CrazyCat
Revered One
Posts: 1306 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Mon Feb 08, 2021 6:51 am
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
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Mon Feb 08, 2021 10:47 am
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 !
ComputerTech
Master
Posts: 399 Joined: Sat Feb 22, 2020 10:29 am
Contact:
Post
by ComputerTech » Tue Feb 09, 2021 1:53 am
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
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Tue Feb 09, 2021 1:58 am
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.
ComputerTech
Master
Posts: 399 Joined: Sat Feb 22, 2020 10:29 am
Contact:
Post
by ComputerTech » Tue Feb 09, 2021 5:42 am
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
CrazyCat
Revered One
Posts: 1306 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Tue Feb 09, 2021 11:39 am
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:
ComputerTech
Master
Posts: 399 Joined: Sat Feb 22, 2020 10:29 am
Contact:
Post
by ComputerTech » Tue Feb 09, 2021 2:47 pm
Oh i see CrazyCat, Thank You for the idea
ComputerTech
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Tue Feb 09, 2021 7:26 pm
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 !
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Wed Feb 10, 2021 1:59 am
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.
CrazyCat
Revered One
Posts: 1306 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Feb 10, 2021 8:47 am
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.
ComputerTech
Master
Posts: 399 Joined: Sat Feb 22, 2020 10:29 am
Contact:
Post
by ComputerTech » Wed Feb 10, 2021 5:25 pm
got a working version which does the job
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
Last edited by
ComputerTech on Wed Feb 10, 2021 7:58 pm, edited 1 time in total.
ComputerTech
CrazyCat
Revered One
Posts: 1306 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Feb 10, 2021 7:29 pm
So you do:
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
ComputerTech
Master
Posts: 399 Joined: Sat Feb 22, 2020 10:29 am
Contact:
Post
by ComputerTech » Wed Feb 10, 2021 7:55 pm
well maybe i could do
I'll try come up with more ideas myself while you're sleeping.
ComputerTech
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Wed Feb 10, 2021 8:00 pm
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 !