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.

Frustrated

Old posts that have not been replied to for several years.
Locked
M
MarlbMan
Voice
Posts: 20
Joined: Tue Apr 15, 2003 9:20 pm

Frustrated

Post by MarlbMan »

OK... I have put together a bit of script that reads from a text file which contains the output of a /list. The file contains many lines that look somewhat like this:

<#channel> <# users> <description>
example:
#mychannel 3 test channel

when showchans is typed in channel it should return the first channel with greater than 5 users. If the first channel contains less than 5 users, it should move on until it finds one with greater than five. Currently however, it just returns the first channel in the list. oddly though, the part of the script which makes it move on if the line is blank, works. Here is the script.

Code: Select all

proc showchans {nick uhost hand chan arg} {
global sd_setting
set amount 0
if {(![file exists sdchans.txt]) || (![file readable sdchans.txt])} {
putserv "NOTICE $nick :Unable to read from file sdchans.txt."
return
} else {
if {![string equal {} [lindex [split $arg] 0]]} {
set nick [lindex [split $arg] 0]
}
set fd [open sdchans.txt r]
for {set temp 0} {$temp <= 0} {incr temp} {
gets $fd line
if { (![string equal {} $line]) || (![lindex [split $line] 1] > 5) } {
incr amount
putserv "PRIVMSG #spamwatch :[join [lindex [split $line] 0]]"
}
}
}
close $fd
}


bind pub - showchans showchans

putlog "loaded, testing"
plz help *bangs head on desk*
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Very small mistake in the logic you use to detect it

Code: Select all

if { (![string equal {} $line]) || (![lindex [split $line] 1] > 5) } {
Notice you use of !. There is no need for it.

Secondly.

Notice your "for" command. Why?

In english
Lets count from 0
Keep looping, provided the current count is below or the same as 0.
This will make it only read the first line.

My guress is you want the while loop. When you detect a matching line, use "break" to get out of the loop and stop checking.

Third.

Code: Select all

putserv "PRIVMSG #spamwatch :[join [lindex [split $line] 0]]"
"lindex" returns a string. There is no need to use "join", this may only break things.
Locked