This is the new home of the 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.

PLease help with small script edit

Old posts that have not been replied to for several years.

Post by Crypto »

hi -

I have a script that reads a txt file and displays the results in my channel on efnet.

The script is a !bnc script, that gets current bnc ip's from that txt file.

The script works fine now, except I need 2 things added to it. ;O)

1) I need it to only work in 1 channel
2) it needs to read lines till the end of file, now its just setup to read 6 lines
...and the file length will vary depending on how many bncs are up at any given time.

If you could PLEASE help me add this bit, I would appreciate it very much !!!

Here is the tcl now:

# Set this to the filename
set dvs_ccbnc_filename "/glftpd/ftp-data/misc/bnclist.msg"

bind pub -|- !ccbnc dvs_ccbnc_pub:spitlines

proc dvs_ccbnc_pub:spitlines {nick uhost hand chan text} {
global dvs_ccbnc_filename

set fileid [dvs_func:openfile $dvs_ccbnc_filename]
if {$fileid == ""} then {
puthelp "NOTICE $nick :Unable to open file for reading."
return 0
while {![eof $fileid]} {
gets $fileid line
puthelp "NOTICE $nick :$line"
close $fileid

return 1

# Opens file gracefully and returns fileid, "" if failed
proc dvs_func:openfile {file {mode read} {binary 1}} {

switch -- $mode
read - r {
set m r
} write - w {
set m w
} append - a {
set m a

if {$m == "r" && (![file exists $file] || ![file readable $file]) || ($m == "w" || $m == "a") && ![file writable $file] || [catch {set fileid [open $file $m]}]} then {
catch {
# I don't know how the hell it would be possible for $fileid to exist at this point..
if {[info exists fileid]} then {
# But I'm still insane enough to check if it does
close $fileid
return ""

if {$binary} then {
fconfigure $fileid -encoding binary -translation binary
return $fileid

Thanks -
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

To make it one channel only, you could could add the following to it.

Code: Select all

if {[string tolower "#channel"] != [string tolower $chan]} { return }
As for reading only 6 lines, I don't see why. The code sugests that it shoudl read till the end, but you claim it only reads 6 lines. You could paste the exact (with secuity changes, but keep it as original as possible) file, as it may montain some nasty suprises.

Post by Crypto »

Thanks ppslim - BUT, I added:


if {[string tolower "#channel"] != [string tolower $chan]} { return }


And when I rehashed I get this error:

[00:58] can't read "chan": no such variable
while executing
"string tolower $chan"
(file "scripts/ccbnc.tcl" line 6)
invoked from within
"source scripts/ccbnc.tcl"
(file "aiplan9" line 1088)

I will get you the txt file (edited) later today, but what would cause this error above ??

Thanks again !!

Post by Crypto »

Oh .. nevermind, hehe I just added that line in the wrong spot. It is working now. :eek:)

Thanks again !