# this is version 2.0 of my i:line finder..
alias iline {
  switch ($0) {
  (-g) {
    if (!gettingilines) {
      @gettingilines=1
      @delarray(ilines)
      ge now creating a list of servers you can connect to.
      ge status will be displayed on the upper statusbar so you can
      ge monitor the progress. we will wait 7 minutes for responses
      ge from all servers before stopping.
      ^window split on
      @ i.tbar = status_format3
      ^wset * status_format3 $(cl) %5 %> %6 
      ^wset * -status_user5
      ^wset * -status_user6
      ^hook _i.q $S *
      ^timer 420 {
        @gettingilines=0
        ^wset * status_format3 $i.tbar
        ^window split $a.topbar
        ge i:line list has been created. use /iline to display,
        ge and /iline -s to save it.}}{
      ge an i:line list is already being created.}}
  (-s) {
  if (numitems(ilines)) {
    if (fexist($a.ilinefile)==1) {
      input_char "replace the existing ilines list? (y/n): " if ([$0]==[y]) {
        savearray $a.ilinefile ilines ge loaded i:line list created $strftime(%x)@$_fixmtime()
        ge the i:line list has been saved in $a.ilinefile}} else {
      savearray $a.ilinefile ilines ge loaded i:line list created $strftime(%x)@$_fixmtime()
      ge the i:line list has been saved in $a.ilinefile}} else {
    ge no i:line list has been created. use /iline -g first.}}
  (-d) {
  if (numitems(ilines)) {
    if (getitem(ilines $1)) {
      @delitem(ilines $1)
      ge i:line \#$1 has been deleted.} else {
      ge i:line \#$1 does not exist.}} else {
    ge no i:line list has been created. use /iline -g first.}}
  (*) {
    if (numitems(ilines)) {
      echo $box.head()
      echo $box.echo_head($(c.hk)[$(c.lc) #$(c.hk)] $(c.hk)[$(c.hw)$numdots(30 server) $(c.hw)$numdots(29 u@h allowed)$(c.hk)])
      ^hook _i.s 0 $numitems(ilines)} else {
      ge no i:line list has been created.  use /iline -g first.}}}}

alias ilinelist iline
alias uniline iline -d $*
alias saveiline iline -s
alias getiline iline -g

on ^hook "_i.s % %" {
  ^local line $1
  ^local cra 0
  ^local rows $winsize()
  while ((line < [$2]) && (cra < rows)) {
    echo $box.echo($(c.hk)[$(c.lc)$[-2]line$(c.hk)] $(c.hk)[$(cl)$numdots(30 $word(0 $getitem(ilines $line))) $(cl)$numdots(29 $restw(1 $getitem(ilines $line)))$(c.hk)])
    @cra++
    @line++}
  if (cra >= rows) {
    @ aaa.next_line = line
    @ aaa.final_line = [$2]
    input_char "-> any key more more, q to quit. " if ([$0] != [q]) {
      ^hook _i.s $aaa.next_line $aaa.final_line} else {
      echo $box.footer()}} else {
    echo $box.footer()}}

on -hook "_i.q*" {
  ^on ^raw_irc "$1 364 *" {
    if ([$[1]3]!=[*]) {
      ^on ^raw_irc "$3 215 *" {
        ${[$N!$_uhost]=~[$4]?[^hook _i.a $0 $4]:}
        ${[$N!$_uhost]=~[$6]?[^hook _i.a $0 $6]:}}
      ^on ^raw_irc "$3 219 *" {
	^on raw_irc -"$0 215 *"
	^on raw_irc -"$0 219 *"}
      ^wset * status_user6 $(c.lc)getting stats$(c.hk): $(cl)$3
      quote stats i $3} else {
      ^hook _i.q $3 $3}
      sleep 1}
  ^on ^raw_irc "$1 365 *" {
    ^on raw_irc -"$0 364 *"
    ^on raw_irc -"$0 365 *"}
  ^wset * status_user6 $(c.lc)getting links$(c.hk): $(cl)$1 $2
  quote links $1 $2}

on -hook "_i.a*" {
  if ([$2]!=[*]) {
    ^wset * status_user5 $(c.lc)i:line found! $(c.lm)\($(cl)$1$(c.hk)\/$(cl)$2$(c.lm)\)$(cl)
    @_i.an=matchitem(ilines $1 *)
    @setitem(ilines ${_i.an>-1?[$_i.an $uniq($getitem(ilines $_i.an) $2)]:[$numitems(ilines) $1-]})}}

alias server {
  if ([$0]==[-i]) {
    if (numitems(ilines)) {
      ^local irs ${isdigit($1)?[$1]:rand($numitems(ilines))}
      if (getitem(ilines $irs)) {
        //server $word(0 $getitem(ilines $irs))} else {
        ge i:line #$irs does not exist.}} else {
      ge no i:line list has been created.}} else {
    //server $*}}

alias splits {
  if (numitems(ilines)) {
    @is.d = is.l = is.c = is.d = is.s = []
    for (@xx=0, xx<numitems(ilines), @xx++) {
      push is.i $word(0 $getitem(ilines $xx)) }
    stack push on 364
    stack push on 365
    ^on ^364 * {
      push is.l $0 $1}
    ^on ^365 * #
    wait for {//links}
    stack pop on 365
    stack pop on 364
    @ is.l = uniq($is.l)
    fe ($pattern(?.* $is.l)) is.a {
      if (pattern($is.a $is.i)) {
        @ is.i = filter($is.a $is.i)
        push is.i $is.a}}
    @ is.c = common($is.i / $is.l)
    @ is.s = diff($is.c / $is.i)
    if (is.s) {
      ge currently split: $is.s} else {
      ge no split servers found.}} else {
    ge you need to create an iline list with /iline -g to use /splits.}}
 
#sjk'97
