Text Overflow Limiting

By Serpentsounds on Feb 14, 2010

This idea is pretty simple, yet I have already found many uses in a short span of time. It focuses on limiting the length of text output, for length cutoffs by an IRC server or other reasons.

The alias limtok should be used as $limtok(text,length,delimiter) similar to other token identifiers, where delimiter is the ASCII value of the character separating the tokens. Text is the input text, and length is the cutoff limit. The identifier will only return up to length characters, but tokens will remain intact (for example, $limtok(monkey monkey monkey,15,32) will just return "monkey monkey" even though 15 characters would continue into the 3rd token).

The cuttext command should be used in an editbox as /cuttext followed by a long string of text. The script calls $limtok() to limit the total message length to 512 bytes (maximum transferable in an IRC command). After that, it will pick up where $limtok() left off to send the remaining text in different messages, if text is remaining. This is used to ensure no data is lost in transmission if you are pasting something obscenely long in a single message. If you need to use this feature in a script, the code should be able to be modified easily enough. If any tokens (words) are greater than the limit, they will be truncated to the limit.

Update 8/29: Improved functionality, the biggest thing being that max message length is now calculated based on your full host rather than estimated.

alias cuttext {
  var %ch $iif($left($1,2) == @#,$mid($1,2),$active),%str $iif($left($1,2) == @#,$2-,$1-),%max $calc(498 - $len(%ch) - $len($address($me,5)))
  while (%str) {
    var %cut $limtok(%str,%max,32)
    msg %ch %cut
    var %str $gettok(%str,$+($calc($numtok(%cut,32) + 1),-),32)

alias limtok {
  if ($len($gettok($1,1,$3)) >= $2) return $left($1,$2)
  var %x 1,%str,%c
  while ($gettok($1,%x,$$3)) {
    var %c $v1
    if ($calc($len(%c) + $len(%str)) <= $2) var %str $+(%str,$chr($3),%c)
    else break
    inc %x
  return $mid(%str,2)


Sign in to comment.
chachin   -  Sep 17, 2011

SO exactly what does this do?

Jethro   -  Aug 23, 2011

The latest mIRC version has the ability to split long text into the next line as a smaller chunk of messages, if it gets too long by the maximum message allowed by your server. It's enabled by default.

I suppose it's useful for those who remain loyal to the old mIRC versions, and who refuse to upgrade for whatever reason.

hxck   -  Aug 23, 2011

Thanks man, we used your snippet in http://www.hawkee.com/snippet/8822/ :)

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.