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.

Split Message in different line

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
b
b00m
Voice
Posts: 3
Joined: Fri Mar 02, 2007 6:40 pm

Split Message in different line

Post by b00m »

Hi guys,
i have a little problem with my eggdrop.
I would want one small tcl that when my egg spam in my channel,if the message in too big, for example contain 200 caracters, i want that split the message in another line, without to cut the words, even split with the spaces, for example.

Please, if u can help me, help me :P

...and excuse me for my english :D
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

b
b00m
Voice
Posts: 3
Joined: Fri Mar 02, 2007 6:40 pm

Post by b00m »

thx for the reply rosc,
i have for example:

bind pub -|- !help pub_help

proc pub_test {nick host handle chan text} {
putserv "PRIVMSG $chan : !bla, !bla2, !bla3, !bla4, !bla5"
}

I increase the process 'proc wordwrap' in my codes?
It's possible only a tcl that allow this split?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Here's an example of using the wrapper from one of my scripts:

Code: Select all

proc nlwordwrap {input} {
        # word wrapper
        set j 0
        set tempdef ""
        foreach line [split $input \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 {$j >= 1} {
                                        set line2 [linsert $line2 end \002(con't)\002]
                                        set j [expr $j -1]
                                }
                                lappend tempdef $line2
                        }
                }       
        }
        return $tempdef
}
To use it, you feed input to it from another proc, like:

Code: Select all

# This line feeds text to the wrapper proc:
set missdesc [nlwordwrap $nlmissdesc]
# This line takes the wrapped text and pumps it out to privmsg:
foreach line $missdesc {
       if {$line != ""} {
                puthelp "PRIVMSG $chan :$line"
       }
}
You could also put the wrapper inside of whatever proc you want:

Code: Select all

# Example from my dream.tcl script, $dreammatch is set when regexp
# gets data from a website:
 
               set j 0;set dhct 0
                foreach line [split $dreammatch \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 {$dhct == 0} {
                                                set line2 [linsert $line2 0 \002[string totitle $text]\002:]
                                                incr dhct
                                                if {$j >= 1} {
                                                        set line2 [linsert $line2 end \002(con't)\002]
                                                        set j [expr $j - 1]
                                                }
                                        } else {
                                                set line2 [linsert $line2 0 \002([string totitle $text] con't)\002]
                                                if {$j >= 1} {
                                                        set line2 [linsert $line2 end \002(con't)\002]
                                                        set j [expr $j - 1]
                                                }
                                        }
                                        puthelp "PRIVMSG $chan :[join $line2]"
                                }
                        }
#######################################################################################################################
b
b00m
Voice
Posts: 3
Joined: Fri Mar 02, 2007 6:40 pm

Post by b00m »

Sorry rosc2122, i try proc nlwordwrap with this in the same tcl and i have this error:
[20:41] Tcl error in file 'eggdrop.conf':
[20:41] can't read "nlmissdesc": no such variable
while executing
"nlwordwrap $nlmissdesc"
invoked from within
"set missdesc [nlwordwrap $nlmissdesc]"
(file "scripts/split.tcl" line 2)
invoked from within
"source scripts/split.tcl"
(file "eggdrop.conf" line 1340)
[20:41] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)


If i use
# Example from my dream.tcl script, $dreammatch is set when regexp
# gets data from a website:
etc....
i have this error:

[20:44] Tcl error in file 'eggdrop.conf':
[20:44] missing close-brace
while executing
"foreach line [split $dreammatch \n] {
if {$line != ""} {
set len 375
..."
(file "scripts/split.tcl" line 5)
invoked from within
"source scripts/split.tcl"
(file "eggdrop.conf" line 1340)
[20:44] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)

I have tried your code but there were some errors and I do not understand why... I would like to have a tlc that I can load into file .conf and my problem is that when the sentence is too long the BOT don't divide the sentence in two part such as two reply but stop it with a [censored] &... I want only that the bot divide the sentence in two part without breaking the WORD...

thank u, and sorry for my english :P
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

The first error was a missing var.. Rename the vars to use whatever you are using.. The second error was a missing close brace, find the missing closed brace and fix it.

Those 2 procs work just fine, you either broke the 2nd one with the missing close brace, or you didn't rename the var in the 1st to suit YOUR script.
Post Reply