egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help split the result

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Reynaldo
Halfop


Joined: 11 May 2005
Posts: 54

PostPosted: Thu Mar 16, 2006 3:15 am    Post subject: Help split the result Reply with quote

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
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Thu Mar 16, 2006 5:51 am    Post subject: Reply with quote

search function is your friend:
http://forum.egghelp.org/viewtopic.php?t=6690#33031
_________________
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
View user's profile Send private message MSN Messenger
Reynaldo
Halfop


Joined: 11 May 2005
Posts: 54

PostPosted: Fri Mar 17, 2006 1:19 am    Post subject: Reply with quote

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 Crying or Very sad
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Mar 17, 2006 5:30 pm    Post subject: Reply with quote

Code:
set output "$wordwrap $word"

Did you mean
Code:
set output [wordwrap $word]

?
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Fri Mar 17, 2006 6:43 pm    Post subject: Reply with quote

btw. if server supports multitargeting of messages I would suggest to use:
[join [channels] ,]
as target Very Happy.
_________________
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
View user's profile Send private message MSN Messenger
Reynaldo
Halfop


Joined: 11 May 2005
Posts: 54

PostPosted: Fri Mar 17, 2006 8:07 pm    Post subject: Reply with quote

Code:

foreach line [wordwrap $word] {
   puthlp "PRIVMSG $chan :$line"
}

i got it! Laughing
Thank you Guys Shocked
Back to top
View user's profile Send private message
Reynaldo
Halfop


Joined: 11 May 2005
Posts: 54

PostPosted: Fri Mar 17, 2006 11:37 pm    Post subject: Reply with quote

There is another problem, message send, too fast, the bot always quit (excess flood). any idea? Crying or Very sad i set the char to 250 Wink
how to make it delay 5seconds each line?
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Fri Mar 24, 2006 1:03 pm    Post subject: Reply with quote

Reynaldo wrote:
There is another problem, message send, too fast, the bot always quit (excess flood). any idea? Crying or Very sad i set the char to 250 Wink
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
View user's profile Send private message MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Aug 03, 2006 2:11 am    Post subject: some enhancement for splitting long lines Reply with quote

I did a little enhancement to this word-wrapper, thought I'd share Smile
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
View user's profile Send private message
Merky
Voice


Joined: 21 Jan 2007
Posts: 17

PostPosted: Wed May 02, 2007 2:37 am    Post subject: Reply with quote

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
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed May 02, 2007 7:24 am    Post subject: Reply with quote

Read the faq about basic file operations (reading/writing files) and use puts instead of puthelp of course.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber