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.

Scan Channel list

Help for those learning Tcl or writing their own scripts.
Post Reply
m
maphex
Voice
Posts: 9
Joined: Fri Feb 10, 2012 5:06 pm

Scan Channel list

Post by maphex »

I already have a script i'm working but part of the puzzle that i cant figure out how to do is i'm using bind cron to run the proc every so often but i want it to scan the channel list and save each user as a variable probable use a foreach and use the variable in the rest of the proc. If anyone can show me the best way yo do this would be great.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

In tcl, foreach works on tcl lists, not arrays of variables like some other languages...

Code: Select all

foreach nick [chanlist #somechannel] {

  ## do something with each nick in the channel ##

}
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
m
maphex
Voice
Posts: 9
Joined: Fri Feb 10, 2012 5:06 pm

Post by maphex »

Worked great thanks SpiKe^^
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

In case you wish to exclude bot from the list you got two options:

1. Inside the foreach loop add a continue instruction if the nick matches bot's name by using the built-in isbotnick function like this:

Code: Select all

foreach nick [chanlist #somechannel] {
	if {[isbotnick $nick]} continue
}
2. Or better, just exclude it right away when creating the list:

Code: Select all

set userList [lreplace [chanlist #somechannel] 0 0]
foreach nick [split $userList] {
	# do something with each nick in the channel
}
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

What if bot's nick is not the first one in the list returned by chanlist ?
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
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

willyw wrote:What if bot's nick is not the first one in the list returned by chanlist ?
Yes, I checked the chanlist return and there is no way to tell where the bots nick will be in that return...
my eggdrop return wrote:[17:11] <SpiKe^^> ;chanlist #pc-mirc-help
[17:11] <Morticia> SpiKe^^: #266 (14 clicks) Tcl: Bogustrivia bogustrivia^ Morticia RayMond kingkong Robby Howitzer SpiKe^^ ZoRoCaShE starr Starr`
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Bot's name is always first, or at least is should be.
.tcl chanlist #eggdrop
Tcl: Bot Pixelz jack3 RockKeyman CRaby Stephe nrt r00tb0y Guest67864 poptix Granis` Lillypad simple Rothgar Broney Freeder_ Kamran vigilant CyBex niko_ KuNgFo0_ sid3windr add_ Biagio zeveroare FireEgl SpiKe^^ thekidd DrPepper SoulesSs Robby thommey Ratler Spike Ritche
Anyway, if you want to be 100% sure about removing it from the right position then proceed with:

Code: Select all

set userList [chanlist #somechannel]
set pos [lsearch -nocase $userList $::botnick]
set userList [lreplace $userList $pos $pos]
and continue with the foreach loop.
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote:Bot's name is always first, or at least is should be.
That's interesting.

Why?
Anyway, if you want to be 100% sure about removing it from the right position then proceed with:

Code: Select all

set userList [chanlist #somechannel]
set pos [lsearch -nocase $userList $::botnick]
set userList [lreplace $userList $pos $pos]
and continue with the foreach loop.
Yep. :)
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