#	$eterna: whowas,v 1.2 2001/08/12 15:57:12 mrg Exp $
#
# Tame the WHOWAS history!
# by Mycroft (mycroft@ai.mit.edu)
# 311 312 313 314 316 317 318 319 353 401 changed for 2.2.2 (server == $0)


ALIAS STRIPCHAN {
  assign function_return $strip(#+-*/\\={}[]<>!@$$%^~`,?:|'\". $0-)
}

ALIAS PURGE {
  foreach $0 i
  {
    purge $0.$i
  }
  ^assign -i
  ^assign -$0
}

ALIAS WHOIS {
  purge whowas.$stripchan($0)
  //whois $0
}

ALIAS WHOWAS {
  purge whowas.$stripchan($0)
  //whowas $0
}

ON #^SEND_MSG 69 * {
  purge whowas.$stripchan($0)
}

ON #^SEND_NOTICE 69 * {
  purge whowas.$stripchan($0)
}

ON #^CONNECT 69 * {
  purge whowas
}

ON #^TIMER 69 * {
  foreach whowas i
  {
    if (time() - whowas.$(i).time > 60)
    {
      purge whowas.$i
    }
  }
  assign -i
}

ON ^311 * {
  _whowas_314 is $1-
  assign -whowas.last
}

ON ^319 * {
  echo *** on channels: $1-
}

ON ^301 * {
  echo *** $0 is away: $1-
}

ON ^313 * {
  echo *** $1 is an IRC operator
}

ON ^317 * {
  if ([$2] == [1])
  {
    echo *** $1 has been idle 1 second
  }
  {
    echo *** $1 has been idle $2 seconds
  }
}

ON ^314 * {
  _whowas_start $stripchan($1) $1-
}

ALIAS _WHOWAS_START {
  assign whowas.$0.314 $1-
  assign whowas.$0.time $time()
  assign whowas.last $0 $stripchan($2).$stripchan($3)
}

ON ^312 * {
  if (whowas.last)
  {
    _whowas_do $whowas.last $stripchan($1) $1-
  }
  {
    _whowas_312 $1-
  }
}

ALIAS _WHOWAS_DO {
  if ([$(whowas.$0.past.$1.$2)])
  {
  }
  {
    assign whowas.$0.past.$1.$2 1
    assign whowas.$0.312 $3-
    _whowas_314 was $(whowas.$0.314)
    _whowas_312 $3-
  }
  assign -whowas.last
}

ALIAS _WHOWAS_314 {
  if ([$5] == [*])
  {
    echo *** $2 $0 $3@$4 \($6-)
  }
  {
    echo *** $2 $0 $3@$4 \($6-) on channel $5
  }
}

ALIAS _WHOWAS_312 {
  echo *** on irc via server $1 \($2-)
}

