| View previous topic :: View next topic |
| Author |
Message |
mrNobody Voice
Joined: 02 Dec 2013 Posts: 14
|
Posted: Sat Dec 21, 2013 11:58 am Post subject: lsearch help |
|
|
Okay, I'm almost afraid to make yet another topic :$ I used search and couldn't find an answer, so here we go:
I have this piece of code:
| Code: |
set family {
pubchan #chan1
famchan #chan2
capochan #chan3
topchan #chan4
}
proc test {nick host handle chan args} {
global family
set family [split [string trim $family] "\n"]
set pubchan [lindex [lsearch -inline $family "pubchan* *"] 1]
set famchan [lindex [lsearch -inline $family "famchan* *"] 1]
set capochan [lindex [lsearch -inline $family "capochan* *"] 1]
set topchan [lindex [lsearch -inline $family "topchan* *"] 1]
putserv "PRIVMSG $chan :pubchan is $pubchan, famchan is $famchan, capochan is $capochan, topchan is $topchan"
}
|
Now that only works for pubchan, everything else returns an empty string. How can I get all the values I want? |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Sat Dec 21, 2013 12:55 pm Post subject: Re: lsearch help |
|
|
| mrNobody wrote: |
...
How can I get all the values I want?
|
Experiment with:
| Code: |
set family [list {pubchan #chan1} {famchan #chan2} {capochan #chan3} {topchan #chan4} ]
bind pub - "!mrnobody" mrnobody
proc mrnobody {nick host handle chan args} {
global family
set pubchan [lindex [lsearch -inline $family "pubchan* *"] 1]
set famchan [lindex [lsearch -inline $family "famchan* *"] 1]
set capochan [lindex [lsearch -inline $family "capochan* *"] 1]
set topchan [lindex [lsearch -inline $family "topchan* *"] 1]
putserv "PRIVMSG $chan :pubchan is $pubchan, famchan is $famchan, capochan is $capochan, topchan is $topchan"
}
|
I hope this helps. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Dec 21, 2013 1:06 pm Post subject: |
|
|
| Code: | set family {
pubchan #chan1
famchan #chan2
capochan #chan3
topchan #chan4
}
proc test {nick host handle chan args} {
global family
set fam [split [string trim $family] "\n"]
set pubchan [lindex [split [string trim [lsearch -inline $fam "*pubchan *"]]] 1]
set famchan [lindex [split [string trim [lsearch -inline $fam "*famchan *"]]] 1]
set capochan [lindex [split [string trim [lsearch -inline $fam "*capochan *"]]] 1]
set topchan [lindex [split [string trim [lsearch -inline $fam "*topchan *"]]] 1]
putserv "PRIVMSG $chan :pubchan is $pubchan, famchan is $famchan, capochan is $capochan, topchan is $topchan"
} |
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
mrNobody Voice
Joined: 02 Dec 2013 Posts: 14
|
Posted: Sat Dec 21, 2013 1:44 pm Post subject: |
|
|
thnx spike, works flawlessly :)
I'm learning a lot of tcl principles by looking at your beer.tcl script, but the lack of comments makes it difficult to decipher sometimes xD |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Dec 21, 2013 2:11 pm Post subject: |
|
|
Another option..
| Code: | set family {
pubchan #chan1
famchan #chan2
capochan #chan3
topchan #chan4
}
proc test {nick host handle chan text} {
array set fam $::family
puthelp "PRIVMSG $chan :pubchan is $fam(pubchan), famchan is $fam(famchan), capochan is $fam(capochan), topchan is $fam(topchan)"
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
mrNobody Voice
Joined: 02 Dec 2013 Posts: 14
|
Posted: Sat Dec 21, 2013 2:14 pm Post subject: |
|
|
| oh very interesting nml! I'm gonna look into that as well. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Dec 21, 2013 2:22 pm Post subject: |
|
|
Worth mentioning,
array set expects a valid list of key-value pairs as input. For a trivial case, you'll be able to craft lists by hand; though I generally recommend using the list command for building more complex lists. This is especially important if you have strings containing spaces or brackets/braces.
| Code: | set family [list pubchan "#chan1 here" \
famchan "#chan2 {there}" \
capochan #otherchan \
topchan "We're on the top #chan" \
]
... |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
mrNobody Voice
Joined: 02 Dec 2013 Posts: 14
|
Posted: Sat Dec 21, 2013 2:32 pm Post subject: |
|
|
could anyone tell me how I can bind all those chans to an onjoin event?
I tried
| Code: |
set famchans [split [string trim $family] "\n"]
foreach famchan $famchans {
if {[llength $famchan]>"1"} {
bind join - "[lindex $famchan 1] *" fambot:onjoin
}
}
|
but that doesn't replace the [lindex $famchan 1] and crashes the bot |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Dec 21, 2013 2:33 pm Post subject: inspired by beer. |
|
|
| mrNobody wrote: | | I'm learning a lot of tcl principles by looking at your beer.tcl script, but the lack of comments makes it difficult to decipher sometimes xD |
Nice to hear you gather inspiration from my beer:)
Sorry there are few comments in the script, but at least it's short.
I would be glad to answer any specific questions you have about beer.
You can always contact me here, or at the contact info in beer.tcl _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Last edited by SpiKe^^ on Sat Dec 21, 2013 3:25 pm; edited 2 times in total |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Dec 21, 2013 3:10 pm Post subject: |
|
|
Maybe try this...
| Code: |
proc doJoinBinds {} {
foreach line [split [string trim $::family] "\n"] {
bind join - "[lindex [split [string trim $line]] 1] *" fambot:onjoin
}
}
doJoinBinds
|
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Dec 21, 2013 3:53 pm Post subject: |
|
|
| Code: |
proc doJoinBinds {} {
# unbind any existing onjoin binds #
foreach jbind [binds fambot:onjoin] {
foreach {typ flg name hit prc} $jbind { break }
unbind $typ $flg $name $prc
}
# bind back the current 'family' channels #
foreach line [split [string trim $::family] "\n"] {
bind join - "[lindex [split [string trim $line]] 1] *" fambot:onjoin
}
}
doJoinBinds
|
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
|