| View previous topic :: View next topic |
| Author |
Message |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Tue Dec 08, 2015 6:50 pm Post subject: Scan Channel list |
|
|
| 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. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Tue Dec 08, 2015 7:15 pm Post subject: |
|
|
In tcl, foreach works on tcl lists, not arrays of variables like some other languages...
| Code: | 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
. |
|
| Back to top |
|
 |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Tue Dec 08, 2015 9:00 pm Post subject: |
|
|
| Worked great thanks SpiKe^^ |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Wed Dec 09, 2015 10:14 am Post subject: |
|
|
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: |
foreach nick [chanlist #somechannel] {
if {[isbotnick $nick]} continue
}
|
2. Or better, just exclude it right away when creating the list:
| Code: |
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed Dec 09, 2015 10:22 am Post subject: |
|
|
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 ! |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Wed Dec 09, 2015 7:04 pm Post subject: |
|
|
| 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
. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Fri Dec 11, 2015 11:22 am Post subject: |
|
|
Bot's name is always first, or at least is should be.
| Quote: |
.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: |
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. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri Dec 11, 2015 1:28 pm Post subject: |
|
|
| caesar wrote: | Bot's name is always first, or at least is should be.
|
That's interesting.
Why?
| Quote: |
Anyway, if you want to be 100% sure about removing it from the right position then proceed with:
| Code: |
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 ! |
|
| Back to top |
|
 |
|