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 

Scan Channel list

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


Joined: 10 Feb 2012
Posts: 9

PostPosted: Tue Dec 08, 2015 6:50 pm    Post subject: Scan Channel list Reply with quote

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


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

PostPosted: Tue Dec 08, 2015 7:15 pm    Post subject: Reply with quote

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


Joined: 10 Feb 2012
Posts: 9

PostPosted: Tue Dec 08, 2015 9:00 pm    Post subject: Reply with quote

Worked great thanks SpiKe^^
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Dec 09, 2015 10:14 am    Post subject: Reply with quote

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


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Dec 09, 2015 10:22 am    Post subject: Reply with quote

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


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

PostPosted: Wed Dec 09, 2015 7:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri Dec 11, 2015 11:22 am    Post subject: Reply with quote

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


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Dec 11, 2015 1:28 pm    Post subject: Reply with quote

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. Smile
_________________
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
View user's profile Send private message
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