[Bot script] Split message if its overlimit

By [Plornt] on Feb 08, 2010

This is a small alias that splits the message up into several lines if it exceeds the maximum the server can take.

If your server can take more than 452 just change that number

Would like improvements if possible, and by that i dont mean "Oh look i can pipe the script to make it look smaller"

This is generally for use with bots.

;;Created by [Plornt] to solve the issue of too long messages, basic version doesnt carry over formatting to the other lines but im sure you could add that easilly
alias msg {
  if ($len($2-) > 452) {
    var %channel $1, %x 1, %msgnum 1
    tokenize 32 $2-
    while (%x <= $0) {
      if ($len($($+($,%msgnum,-,%x),2)) > 452) {
        msg %channel $($+($,%msgnum,-,$calc(%x - 1)),2)
        var %msgnum %x
      }
      inc %x
    }
  }
  else msg $1-
}

Comments

Sign in to comment.
Atr   -  Feb 12, 2010

I see.. :o

Thanks for that.

 Respond  
PuNkTuReD   -  Feb 10, 2010

lol

 Respond  
Jethro   -  Feb 09, 2010

Not really lol... as I said, "I cannot help it." I used to make that grammatical mistake back when I took my English class and was corrected by my professor. What Atr posted brought back my memory of that faithful school day. :p

 Respond  
PuNkTuReD   -  Feb 09, 2010

wow Jethro_
ever thought about being an english teacher?

 Respond  
Jethro   -  Feb 09, 2010

Nice going with regex, thelmrac.

 Respond  
FordLawnmower   -  Feb 09, 2010

Really nice work Thelmrac :)

 Respond  
TheImrac   -  Feb 09, 2010

I got bored so I did a regex version =)

just change %n to w/e

alias msg {
  var %n = 40,%c = $1, %m = $2-
  while ($regex(%m,/^(?=.{ $+ %n $+ ,})(.{0, $+ %n $+ })[^$\w](.*)$/)) {
    msg %c $regml(1)
    %m = $regml(2)
  }
  msg %c %m
}
 Respond  
Jethro   -  Feb 09, 2010

Atr,> @sunslayer, 'twas a joke between Plornt & I. ;)Between is a preposition. In English, a preposition must be followed by an indirect object pronoun. Me is an indirect object pronoun, and I is a subject pronoun. Therefore, between has to be followed by me, not I.

I can't help but point out the difference. :P

 Respond  
Atr   -  Feb 09, 2010

@sunslayer, 'twas a joke between Plornt & I. ;)

Btw, do my eyes deceive me? Plornt, you're using the $eval variable method! :D

 Respond  
FordLawnmower   -  Feb 08, 2010

It cuts off because you have the outer if -- else conditions and then inside the while loop you have an if with no else so the remainder of that drops through the last "> 452 if" is lost without being sent to the channel.
You should be able to fix it by removing the outer if else and just letting the script message the remaining text when it drops out of the while loop.

alias msg {
  var %channel $1, %x 1, %msgnum 1
  tokenize 32 $2-
  while (%x <= $0) {
    if ($len($($+($,%msgnum,-,%x),2)) > 452) {
      msg %channel $($+($,%msgnum,-,$calc(%x - 1)),2)
      var %msgnum %x
    }
    inc %x
  }
  msg %channel $($+($,%msgnum,-,$calc(%x - 1)),2)
}
 Respond  
sunslayer   -  Feb 08, 2010

@Atr using pipes takes mIRC longer to parse and makes the code in general alot harder to read and shouldn't be used in excess

 Respond  
PuNkTuReD   -  Feb 08, 2010

yea thats the exact problem i did encounter with mine, but i never had a need for this type of script, so that really didnt bother me lmao.

 Respond  
[Plornt]   -  Feb 08, 2010

Ah nice script, and ill add in the improvements in a bit, i was going to do mine like that, infact i did at one point do mine like that, then i realised it was cutting into words so i thought if i make it do the last word it can fit etc

 Respond  
PuNkTuReD   -  Feb 08, 2010

instead of piping several "vars" just use ","

var %a = 1, %b = 2, %c = 3
and even then i dont think the "="'s are needed.

why 452? i think different servers use different limits.

an alias/identifier, would be nice
example:

alias msg.limit return 452

then in script, you can do $msg.limit
and people can edit that alias/identifier as they wish.

oh also, in your description, you should add that the usage is
$chan
and i may be wrong but there is no need to tokensize, since your outgoing msg is already tokened by spaces.

heres a version of this i wrote a while ago

alias check.len {
  var %aa = $1-
  if ($len(%aa) <= 250) { msg $chan %aa }
  else {
    var %a = 250, %b = $len(%aa)
    while (%a <= %b) {
      msg $chan $iif(%a == 250,$left(%aa,%a),$right($left(%aa,%a),$calc(%a - 250)))
      if (%a < %b && $calc(250 + %a) > %b) { msg $chan $right(%aa,$calc(%b - %a)) | halt }
      else { inc %a 250 }
    }
  }
}      
 Respond  
Atr   -  Feb 08, 2010

Oh look I can pipe the script to make it look smaller:

alias msg {
if ($len($2-) > 466) { var %channel $1 | tokenize 32 $2- | var %tot $0 | var %x 1 | var %msgnum 1 | while (%x <= %tot) { if ($len($($+($,%msgnum,-,%x),2)) > 466) { msg %channel $($+($,%msgnum,-,$calc(%x - 1)),2) | var %msgnum %x } | inc %x } } | else msg $1- }

Sorry, couldn't resist. Anywho, nice work Plornt.

 Respond  
[Plornt]   -  Feb 08, 2010

Hang on, fail
Fixed.

 Respond  
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.