| View previous topic :: View next topic |
| Author |
Message |
Reynaldo Halfop
Joined: 11 May 2005 Posts: 54
|
Posted: Thu Mar 16, 2006 3:15 am Post subject: Help split the result |
|
|
i've already grab from web into $result
| Code: | foreach line [split $result "\n"] {
puthlp "PRIVMSG $nick :$notc $line"
} |
but the problem is, some lines in $result is to long. how to make it about max 200 words each lines?. |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
|
| Back to top |
|
 |
Reynaldo Halfop
Joined: 11 May 2005 Posts: 54
|
Posted: Fri Mar 17, 2006 1:19 am Post subject: |
|
|
after parse the html into $word
| Code: |
set output "$wordwrap $word"
foreach x [channels] {
putserv "PRIVMSG $x :$output"
}
proc wordwrap {str {len 70} {splitChr { }}} {
set out [set cur {}]; set i 0
foreach word [split [set str][unset str] $splitChr] {
if {[incr i [string len $word]]>$len} {
lappend out [join $cur $splitChr]
set cur [list $word]
set i [string len $word]
} {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
}
|
seems it's not working  |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Fri Mar 17, 2006 5:30 pm Post subject: |
|
|
| Code: | | set output "$wordwrap $word" |
Did you mean
| Code: | | set output [wordwrap $word] |
? _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Fri Mar 17, 2006 6:43 pm Post subject: |
|
|
btw. if server supports multitargeting of messages I would suggest to use:
[join [channels] ,]
as target . _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
Reynaldo Halfop
Joined: 11 May 2005 Posts: 54
|
Posted: Fri Mar 17, 2006 8:07 pm Post subject: |
|
|
| Code: |
foreach line [wordwrap $word] {
puthlp "PRIVMSG $chan :$line"
}
|
i got it!
Thank you Guys  |
|
| Back to top |
|
 |
Reynaldo Halfop
Joined: 11 May 2005 Posts: 54
|
Posted: Fri Mar 17, 2006 11:37 pm Post subject: |
|
|
There is another problem, message send, too fast, the bot always quit (excess flood). any idea? i set the char to 250
how to make it delay 5seconds each line? |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Fri Mar 24, 2006 1:03 pm Post subject: |
|
|
| Reynaldo wrote: | There is another problem, message send, too fast, the bot always quit (excess flood). any idea? i set the char to 250
how to make it delay 5seconds each line? |
1st:
"PRIVMSG $chan :" is at least 12 characters long, depending on channel maybe even 20. So I'd advise to wrap at around 230-235 chars, if want to keep line size below 256 bytes.
2nd:
if your bot floods on putserv or even on puthelp, you should consider increasing '#define msgrate' in your 'src/mod/server.mod/server.c' (and of course recompile and reinstall). This will however slow down reaction speed of the bot, but better 1s later than ending in being kicked.
Default and advised value is 2, my bots run well with 1 on QuakeNet and EuIRCnet. But might need to be set to 3 or 4 on more strict networks and depending on expected line length (1 assumes you do not exceed 250 characters/line). _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Thu Aug 03, 2006 2:11 am Post subject: some enhancement for splitting long lines |
|
|
I did a little enhancement to this word-wrapper, thought I'd share
| Code: |
############################################################################################################
# If the input came from a msg bind, we set $chan to "privmsg"
# for example:
bind msg - !mytrigger myproc
proc mytrigger {nick uhost hand text} {
# pass the params to 'wrapproc' and set the channelname to "privmsg"
wrapproc $nick $uhost $hand privmsg $text
return
}
bind pub - !mytrigger wrapproc
proc wrapproc {nick uhost hand chan text} {
if {$chan == "privmsg"} {set chan $nick}
# inputtitle would normally be the commandline given with the trigger, such as '!horoscope leo'
# title would be set to 'leo'
# You'd have to do further processing on the $text input of course, to limit its length,
# split it to make it tcl-special char safe, etc.
if {$text != ""} {set inputtitle "$text"} else {set inputtitle "titlefoo"}
# here we grab data into a var, say $sometext, from something like a geturl/regexp operation
set sometext "some real long string of text over 400 chars for example"
# word wrapper
set j 0
set linecount 0
foreach line [split $sometext \n] {
if {$line != ""} {
set len 375
set splitChr " "
set out [set cur {}]; set i 0
foreach word [split $line $splitChr] {
if {[incr i [string len $word]]>$len} {
lappend out [join $cur $splitChr]
set cur [list $word]
set i [string len $word]
incr j
} else {
lappend cur $word
}
incr i
}
lappend out [join $cur $splitChr]
foreach line2 $out {
if {$linecount == 0} {
set line2 [linsert $line2 0 \002[string totitle $inputtitle]\002:]
incr linecount
if {$j >= 1} {
set line2 [linsert $line2 end \002(con't)\002]
set j [expr $j - 1]
}
} else {
set line2 [linsert $line2 0 \002($inputtitle con't)\002]
if {$j >= 1} {
set line2 [linsert $line2 end \002(con't)\002]
set j [expr $j - 1]
}
}
puthelp "PRIVMSG $chan :$line2"
}
}
}
puthelp "PRIVMSG $chan :\[end of $inputtitle output.\]"
}
|
I've been using this for various scripts, like the dream and funny horoscope scripts I made. The final result looks something like:
<TheEntity> Taurus: Everything will suddenly sound good to you today. This may be due to a syringing appointment you have earlier in the week, or it may be become love has just entered your life in the form someone floating down a river in a large plastic swan-type boat. Or it may just be because you've won a serious amount of money and people want to shower you with platitudes. Speaking of (con't)
<TheEntity> (taurus con't) which - you do look amazing today! Parts of you feel like giving up the ghost today, but feeding those parts with ice-cream and bacon bits may revive them, to an extent. Clowns with pickaxes will haunt your dreams tonight and will affect you at around mid-morning the following day. The effect of such dreams will cause you to a) be tired, b) look startled when people slam (con't)
<TheEntity> (taurus con't) the door, or c) be nice to any clowns you meet.
<TheEntity> [end of taurus horoscope] |
|
| Back to top |
|
 |
Merky Voice
Joined: 21 Jan 2007 Posts: 17
|
Posted: Wed May 02, 2007 2:37 am Post subject: |
|
|
how about i split file.txt?
set sometext "some real long string of text over 400 chars for example"
set sometext "file.txt" |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Wed May 02, 2007 7:24 am Post subject: |
|
|
| Read the faq about basic file operations (reading/writing files) and use puts instead of puthelp of course. |
|
| Back to top |
|
 |
|