egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

lsearch help

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
mrNobody
Voice


Joined: 02 Dec 2013
Posts: 14

PostPosted: Sat Dec 21, 2013 11:58 am    Post subject: lsearch help Reply with quote

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
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sat Dec 21, 2013 12:55 pm    Post subject: Re: lsearch help Reply with quote

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
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat Dec 21, 2013 1:06 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mrNobody
Voice


Joined: 02 Dec 2013
Posts: 14

PostPosted: Sat Dec 21, 2013 1:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Dec 21, 2013 2:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
mrNobody
Voice


Joined: 02 Dec 2013
Posts: 14

PostPosted: Sat Dec 21, 2013 2:14 pm    Post subject: Reply with quote

oh very interesting nml! I'm gonna look into that as well.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Dec 21, 2013 2:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
mrNobody
Voice


Joined: 02 Dec 2013
Posts: 14

PostPosted: Sat Dec 21, 2013 2:32 pm    Post subject: Reply with quote

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
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat Dec 21, 2013 2:33 pm    Post subject: inspired by beer. Reply with quote

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
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat Dec 21, 2013 3:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat Dec 21, 2013 3:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber