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.

freebsd and ^M linebreaks while echoing text file to channel

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

freebsd and ^M linebreaks while echoing text file to channel

Post by rvwinkle »

Hello I have found the follwoing simple code to echo the contents of a text file in my channel when triggered.

Code: Select all

set bfile "/www/message.txt"
set cmd "!netstat"
set bwhere 0

bind pub -|- $cmd dumpfile
proc dumpfile {nick handle host chan text } {
global bfile bwhere
set foo [open $bfile r]
while { ! [eof $foo] } {
set line [gets $foo]
if {!$bwhere} {
puthelp "PRIVMSG $chan :$line"
}
}
}
The message.txt file is edited by a php utility that I do not have access to change. The php utility adds a ^M to the bottom of the file everytime someone submits a new entry.
On linux the tcl script I am using ignores the ^M characters and the bot only says the relevant parts but on freebsd i get an empty line for every ^M character. I am currently reading up on regexpr but it still seems daunting to me. Is there a simple way for me to tell the bot to ignore the windows linebreaks?

Thank you for any help you can provide in the regard.

p.s. here is a snippet from the text file so you can see what i mean if needed....Stripping the html code out to would be super awesome but is not required.
Issues with hi-rez - mt=987654.^M
<b><font color=green size=4>Net</font><font color=blue size=4>cool</fon
t> - It's netcool son, netcool. It ain't that hard.^M
^M
^M
^M
^M
^M
^M
^M
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

just add this right after your gets to make it ignore the ^M lines

Code: Select all

if {[string equal ^M $line]} { continue }
Use this to strip all the html codes

Code: Select all

#proc not made by me, can't remember who wrote it =)
proc htmltotext {text} {
  regsub -all -- {<br>} $text "\n" text
  regsub -all -- {</b>|</font>} $text { } text 
  regsub -all -- {<[^>]*>} $text {} text 
  regsub -all -- { |[<*>]} $text { } text
  return $text
}
Elen sila lúmenn' omentielvo
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

dont forget to close $bfile when you are done with it
photon?
r
rvwinkle

stuck on this

Post by rvwinkle »

this is what i have manged so far...

Code: Select all

set bfile "/www/message.txt"
set cmd "!netstat"
set bwhere 0

bind pub -|- $cmd dumpfile
proc dumpfile {nick handle host chan text } {
global bfile bwhere
set foo [open $bfile r]
while { ! [eof $foo] } {
set line [gets $foo]
if {[string equal ^M $line]} { continue }
if {!$bwhere} {
puthelp "PRIVMSG $chan :$line"
}
}
}
it is still displaying the line breaks as empty lines
am i doing it wrong ?
Sorry if this is a newbie mistake
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Yeah it's not really "^M" it's "\r" or something.
r
rvwinkle

getting farther

Post by rvwinkle »

Thanks for the input yesterday

I ended up using a dupe limiter in main eggdrop config as i could never find info on the correct string to use for the filter but it works now and I am interested in implementing the html filter

this is the code i have so far

Code: Select all

set cmd "!netstat"

bind pub -|- $cmd log:pub

proc log:pub {nick handle host chan text } {
  set foo [open "/www/message.txt" "r"]
  foreach line [split [read $foo] \n] {
    puthelp "PRIVMSG $chan :$line"
  }
  close $foo
}
Can anyone provide some pointers on implenting this bit of code on the output?

Code: Select all

#proc not made by me, can't remember who wrote it =)
proc htmltotext {text} {
  regsub -all -- {<br>} $text "\n" text
  regsub -all -- {</b>|</font>} $text { } text
  regsub -all -- {<[^>]*>} $text {} text
  regsub -all -- { |[<*>]} $text { } text
  return $text
}
r
rvwinkle

completed

Post by rvwinkle »

Code: Select all

set cmd "!netstat"
bind pub -|- $cmd log:pub 

#proc not made by me, can't remember who wrote it =)
proc htmltotext {text} {
  regsub -all -- {<br>} $text "\n" text
  regsub -all -- {</b>|</font>} $text { } text
  regsub -all -- {<[^>]*>} $text {} text
  regsub -all -- { |[<*>]} $text { } text
  return $text
}

proc log:pub {nick handle host chan text } {
  set foo [open "/home/rvwinkle/eggdrop1.6.16/scripts/ehco.txt" "r"]
  foreach line [split [read $foo] \n] {
    puthelp "PRIVMSG $chan :[htmltotext $line]"
  }
  close $foo
}
Just in case anyone wanted info on how it was done , the above example works fine to echo the contents of a text file in our irc channel and strip any html code from that file. Seems kind of slow tho, any pointers on making it faster ?
s
spock
Master
Posts: 319
Joined: Thu Dec 12, 2002 8:40 pm

Post by spock »

there have been a few threads in the past discussing the speed of regsub and other solutions. use "string map" wherever possible seems to be a popular conclusion (faster).
photon?
Locked