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.

seeking an example of small string proc...

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

seeking an example of small string proc...

Post by abn0rmal »

does anyone have an example of procedure that cuts one long string into short ones ?
but it should not cut words.
actually i need it because ircd cuts long strings that my eggy tries to msg to chan...
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

somthing like

Code: Select all

proc ml_privmsg {to text} {
  while {$text != ""} {
    puthelp "PRIVMSG $to :[string range $text 0 50]"
    set text [string range $text 51 end]
  }
}
use the command as:

Code: Select all

ml_privmsg "destination" "very very very long line of text"
Note, this can break a word in 2 (placing different portions on different lines).

There are a few changes that could be made, but I can't be bothered.
a
abn0rmal

Post by abn0rmal »

thanx!
I
Iridium

Post by Iridium »

Heh, I wrote this then went out. Mine is a little more complex, as it will not split words down.

Code: Select all

proc splitstring {string strmax} {
	set strlen [string length $string]
	putlog "blah - $strlen | blah - $strmax"
	if {$strlen > $strmax} {
		set curpos 0
		set lstartpos 0
		set lspacepos $strlen
		set final ""
		for {set i 0} {$i <= $strlen} {incr i} {
			putlog "$curpos | $final | $lspacepos | $i | $lstartpos | $strlen"
			if {$i==$strlen} {
				lappend final [string trim [string range $string $lstartpos end]]
				return $final
			}
			if {$curpos >= $strmax} {
				set curpos 0
				lappend final [string trim [string range $string $lstartpos $lspacepos]]
				set lstartpos $lspacepos
			}
			if {[string index $string $i] == " "} {
				set lspacepos $i
			}
			incr curpos
		}
		return $final
	}
	return [list $string]
}
This returns a list containing each line.

E.G.

Code: Select all

foreach z [splitstring "my very very very long line of text that will go on forever until I die" 10] {
  putserv "PRIVMSG #wherever :$z"
}
the function there will output "{my very very very} {long line of text} {that will go on forever} {until I die}"

and the loop will output (in #whatever)

Code: Select all

<botname> my very very very
<botname> long line of text
<botname> that will go on forever
<botname> until I die
Hope that helps.
a
abn0rmal

Post by abn0rmal »

cute :) indeed, thank you...
I
Iridium

Post by Iridium »

No problem
I
Iridium

Post by Iridium »

Oh crap, I just realised I left a putlog in there.. that will make your partyline REALLY spammy..

I suggset you remove all putlogs, I used them to debug..
a
abn0rmal

Post by abn0rmal »

huh... i'll get over it ;)))
#thx again...
W
Wcc
Master
Posts: 278
Joined: Sun Oct 28, 2001 8:00 pm
Location: USA
Contact:

Post by Wcc »

For one, 50 is alittle short to be cutting it to, as a msg can be a total of 512 chars. I'd use 400 to be safe, being that the nick, etc take up space.. Hell, even 300 if needed. Here is the code I use. It will also not split up words.

Code: Select all

proc send_privmsg_wrap_text {dest text} {
  while {[string compare $text ""] != 0} {
    if {[string length $text] <= 400} { putserv "PRIVMSG $dest :$text" ; return }
    putserv "PRIVMSG $dest :[string range $text 0 [set lr [string last " " [string range $text 0 400]]]]"
    set text [string range $text $lr end]
  }
}
a
abn0rmal

Post by abn0rmal »

small && nice code :)
Locked