All pastes #413190 Raw Edit

Stuff

public text v1 · immutable
#413190 ·published 2007-03-28 05:35 UTC
rendered paste body
alias op {
  ; /op nick nick1 nick2
  ; /op #chan nick nick1 nick2
  var %1, %?
  set -n %1 $$1
  if (%1 !ischan) && ($getchan) {
    set -n %1 $ifmatch
    set -n %? $$1-
  }
  elseif (%1 ischan) {
    set -n %? $$2-
  }
  else { [ [ $err.report ] ] /op: what channel? }
  noop $batch(mode %1 +oooo,%?,32,4)
  :error
  if ($error) { [ [ $err.report ] ] }
}

alias batch {
  ; $batch(mode #chan +oooo,nick nick1 nick2,32,4)
  ; do command $1 on tokens in $2 delimited by $chr($3) in batches of $4
  ; this needs stacking and flood protection.
  var %1, %2, %3, %4, %a, %0 = 0
  set -n %1 $$1
  set -n %2 $$2
  set -n %3 $$3
  set -n %4 $calc($$4 - 1)
  tokenize %3 %2

  while (%0 < $0) {
    inc %0
    set -n %a $+($($),%0)
    inc %0 %4
    set -n %a $+(%a,-,%0)
    %1 [ [ %a ] ]
  }

  :error
  if ($error) { [ [ $err.report ] ] }
}

;___[channel/peer data]______________________________________
; current state of channels and occupants.

alias selnicks {
  ; return whitespace delimited list of selected names in channel nicklist.
  var %?
  set -n %? $1
  tokenize 44 $snick($getchan(%?))
  return $1-
}

alias getchan {
  ; return the #channel likely associated with event.
  var %1
  set -n %1 $1
  if (!%1) {
    elseif ($chan) {
      set -n %1 $chan
    }
    if ($target ischan) {
      set -n %1 $target
    }
    elseif ($active ischan) {
      set -n %1 $active
    }
    return %1
  }
  elseif (%1 ischan) {
    return %1
  }
}

alias comchans {
  ; $comchans(nick) returns whitespace delimited list of channels you share with nick.
  ; this needs to account for too many chans for a single line return.
  var %1, %2, %0, %!
  set -n %1 $$1
  set -n %2 $2
  set -n %0 $comchan(%1,0)
  while (%0) { 
    if (%2 == $comchan(%1,%0)) { return $ifmatch }
    set -n %! $comchan(%1,%0) %!
    dec %0
  } 
  return %!
  :error
  if ($error) { [ [ $err.report ] ] }
}

alias allnicks {
  ; returns whitespace delimited list of all names in channel.
  ; this needs to account for too many nicks for a single line return.
  var %chan
  set -n %chan $1
  if (!%chan) {
    if ($target ischan) {
      set -n %chan $target
    }
    elseif ($active ischan) {
      set -n %chan $active
    }
    else { [ [ $err.report ] ] No target #channel. }
  }
  var %x = 1, %h
  while (%x <= $nick(%chan,0)) {
    if ($2) $2- $nick(%chan,%x)
    else %h = %h $nick(%chan,%x)
    inc %x
  }
  if ($isid) return %h
  :error
  if ($error) { [ [ $err.report ] ] }
}


;___[error handler]__________________________________________

alias err {
  ; normal /err calls do this part.
  var %?, %1, %2
  set -n %1 $1
  set -n %2 $2
  set -n %? $3-
  echo $color(info) -st $brak(!) $iif($event,$brak($ifmatch),) $iif($target,$brak($ifmatch),) $iif($error,$ifmatch,) $iif(%?,* $ifmatch,) $+(* /err: ,$chr(40),line %1,$chr(44)) $+(%2,$chr(41)) 
  reseterror | halt

  :error
  ; errors in /err itself do this.
  if ($error) {
    echo $color(info) -st $brak(!) $error
    reseterror | halt
  }
}
alias err.report {
  return err $!scriptline $!nopath($script)
}