Wildcard Nick List

By Savage_CL on Oct 25, 2013

Return a tokenized list of all nicks that match the wildcard given.

alias nickSearch {
  ; Returns a tokenized list of nicks matching the given wildcard
  ; USAGE: $nickSearch(<chan>,<wildcard match>,<delimiter>,[some true value])
  ; optional fourth value sorts return alphabetically if non-false value
  ; Example: $nickSearch(#channel,a*,32)

  if ($me !ison $1) {
    echo 4 -s * : not in channel
  }
  elseif ($3 !isnum) {
    echo 4 -s * : invalid delimiter
  }
  else {
    var %o,%i = 1
    while ($nick($1,%i,a)) {
      if ($2 iswm $v1) {
        %o = $addtok(%o,$v2,$3)
      }
      inc %i
    }
    if ($4) {
      %o = $sorttok(%o,$3)
    }
    return %o
  }

}

Comments

Sign in to comment.
Meta   -  Oct 26, 2013

Lol why not regex?

alias nicksearch {
  var %r $regsubex($str(.,$nick($1,0)),/./g,$iif( [ $2 ] iswm $nick( [ $1 ] ,\n),$v2 $+ $chr( [ $3 ] )))
  return $deltok($iif($4,$sorttok(%r,$3),%r),,$3)
}

Edit: Don't need a capture group. Also, now removes null tokens.

SReject  -  Oct 27, 2013

lol, why not fline?

alias nicksearch {
  var %r $regsubex($str($chr($3),$nick($1,0)),/(?=.)/g,$fline( [ $1, $2 ] ,\n,1).text)
  return $iif($4,$sorttok(%r,$3),$deltok(%r,,$3))
}
Sign in to comment

SReject   -  Oct 26, 2013

Why loop?

alias nickSearch {
  if ($isid && $me ison $1 && $3 isnum 1-) {
    unset %::nickSearch
    set -u0 %::nickSearchDelimiter $chr($3)
    filter -lk $1 _nicksearch $2
    if ($4) return $sorttok(%::nickSearch, $3)
    return %::nickSearch
  }
}
alias -l _nickSearch  set -u0 %::nickSearch $addtok(%::nickSearch, $1, %::nickSearchDelimiter)

(updated for a bit more speed; but at the cost of characters)

Yawhatnever  -  Dec 16, 2013

/filter includes the prefix

Sign in to comment

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.