Easy Mode Grabbing!

By LIQUID_NiTrO on May 29, 2005

This snippet is designed to take the pain out of looking for the targets of certain modes, etc. It was set up and tested on UnrealIRCd but should work for most servers.
This is kinda hard to explain, but here we go: what this alias does is take a mode string from the modechars on (so it would start with a + or - and then contain the rest of the mode string) and spits out a tokenized list of all the included modes and their targets in the format [+|-]Modechar:TargetName. If the mode does not have a target, it will say _NOTARG in place of TargetName. There are three ways for it to recognize which modechars have targets and which dont: as a channelmode string (default or the CHAN property), as a usermode string (with the USER property), or it can do a "dumb" evaluation (with the DUMB property) in which it will try to match every modechar with a target as long as one exists for it to match with, and the ones on the end without any matches will be matched with _NOTARG.
You probably didn't understand that, just look at the examples :)
$modetok(+oqQ-v GotOps GotOwner LostVoice) - returns +o:GotOps +q:GotOwner +Q:_NOTARG -v:LostVoice
$modetok(+svw-H +sj-k).user - returns +s:+sj-k +v:_NOTARG +w:_NOTARG -H:_NOTARG
$modetok(+abcde One Two Three).dumb - returns +a:One +b:Two +c:Three +d:_NOTARG +e:_NOTARG

Note: This alias only works provided eight or less modes have been set, which is the limit for one mode command on most networks.

alias modetok {
  if ( $prop == chan ) || ( !$prop ) {
    .echo -q $regex(mt,$1-,/[\+|\-]([a-cefhikl-vzACGKL-OQ-TV\+\-]*)($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))/)
    var %x = 1,%g = $mid($1,1,1),%n = 1
    set -l %f
    while ( %x <= $len($regml(mt,1)) ) {
      if ( $mid($regml(mt,1),%x,1) == + ) || ( $mid($regml(mt,1),%x,1) == - ) {
        %g = $mid($regml(mt,1),%x,1)
        inc %x 1
        continue
      }
      if ( $regex($mid($regml(mt,1),%x,1),/[^vhoaqbekKlLf]/) ) { ;Inside the [] is the list of recognized channel modes which require a target.
        %this = _NOTARG
      }
      else {
        %this = $mid($regml(mt,$calc(%n * 2)),2,99)
        inc %n 1
      }
      %f = $addtok(%f,$+(%g,$mid($regml(mt,1),%x,1),:,%this),32)
      inc %x 1
    }
  }
  elseif ( $prop == user ) {
    .echo -q $regex(mt,$1-,/[\+|\-]([adg-io-tv-xzA-CGHNOR-TVW\+\-]*)($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))/)
    var %x = 1,%g = $mid($1,1,1),%n = 1
    set -l %f
    while ( %x <= $len($regml(mt,1)) ) {
      if ( $mid($regml(mt,1),%x,1) == + ) || ( $mid($regml(mt,1),%x,1) == - ) {
        %g = $mid($regml(mt,1),%x,1)
        inc %x 1
        continue
      }
      if ( $regex($mid($regml(mt,1),%x,1),/[^s]/) ) { ;Inside the [] is the list of recognized user modes which require a target (yep, just one).
        %this = _NOTARG
      }
      else {
        %this = $mid($regml(mt,$calc(%n * 2)),2,99)
        inc %n 1
      }
      %f = $addtok(%f,$+(%g,$mid($regml(mt,1),%x,1),:,%this),32)
      inc %x 1
    }
  }
  elseif ( $prop == dumb ) {
    .echo -q $regex(mt,$1-,/[\+|\-]([a-zA-Z\+\-]*)($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))($|\s([^\s]*))/)
    var %x = 1,%g = $mid($1,1,1),%n = 1
    set -l %f
    while ( %x <= $len($regml(mt,1)) ) {
      if ( $mid($regml(mt,1),%x,1) == + ) || ( $mid($regml(mt,1),%x,1) == - ) {
        %g = $mid($regml(mt,1),%x,1)
        inc %x 1
        continue
      }
      %f = $addtok(%f,$+(%g,$mid($regml(mt,1),%x,1),:,$mid($regml(mt,$calc(%n * 2)),2,99)),32)
      inc %n 1
      inc %x 1
    }
    .echo -q $regsub(%f,/([\+|\-]\w:)(\s|$)/g,$regml(1) $+ _NOTARG,%f)
  }
  return %f
}

Comments

Sign in to comment.
DarthReven   -  Jun 02, 2005

Nice code once again Liquid

 Respond  
PoiXon   -  May 30, 2005

Nice code, i say 8 for me

 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.