All pastes #829375 Raw Edit

Something

public text v1 · immutable
#829375 ·published 2007-12-23 02:53 UTC
rendered paste body
;depredate start

on *:TEXT:#: { /write C:\wamp\irclogs.php $chan $time  $date $nick Message: $1- }
on 1:CONNECT: { /as auth infinitybotaccount1 infinityowns | //mode $me +x | /join #DePStudios | /nick DePStudios }
on *:JOIN:#clubinfinity: { /notice $nick 0,1(9,1Join us on the web at Not Displayed 0,1)(9,1Type 0,1>info 9,1to see all of our servers0,1) | /write joined.txt $nick $time }
on *:TEXT:>commands:#: { /notice $nick 0,1User Commands:9,1 0,1>9,1site  0,1>9,1time 0,1>9,1date 0,1>9,1search 0,1>9,1prices }
on *:TEXT:>site:#: { //notice $nick 0,1L9,1ooking for web-hosting and domain sponsor! }
on *:TEXT:>time:#: { /notice $nick $time $date }
on *:TEXT:>date:#: { /notice $nick $time $date }
on *:JOIN:#DePStudios: { /notice $nick 0,1T9,1op News0,1:9,1 Welcome0,1 $nick 9,1to #DePStudios. Please Idle & Support. Looking for a web-hosting and domain sponsor. 0,1>commands 9,1to view all the commands. }
on *:TEXT:>prices:#: { /notice $nick 0,1N9,1o prices currently set. Please PM0,1 GG|DePredaTe. }



on *:TEXT:>part *:#: { if ($nick isop $chan) { /part $chan }
  else { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. }
}

on *:TEXT:>say *:#: {
  if ($nick isop $chan) {
    msg $chan $2-
  }
  else {
    notice $nick 9,1I'm sorry, But you must be an OP to use this command.
  }
}

on *:TEXT:>join *:#: { if ($nick isop $chan) { /join $2 }
  else { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. }
}


on *:TEXT:>topic *:#: { if ($nick isop $chan) { //topic $chan $2- }
  else { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. }
}

on *:TEXT:>warn *:#: { if ($nick isop $chan) { /msg $2 9,1You have been warned for $3- by $nick at $time | /msg $chan 9,1 $2 has received a warning from $nick at $time for $3- }
  else { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. }
}

on *:TEXT:>op *:#: { if ($nick isop $chan) { //mode $chan +o $2 } 
  ELSE { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. 
  }      
}
on *:TEXT:>deop *:#: { if ($nick isop $chan) { //mode $chan -o $2 } 
  ELSE { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. 
  }      
}
on *:TEXT:>voice *:#: { if ($nick isop $chan) { //mode $chan +v $2 } 
  ELSE { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. 
  }      
}
on *:TEXT:>devoice *:#: { if ($nick isop $chan) { //mode $chan -v $2 } 
  ELSE { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. 
  }      
}
on *:TEXT:>kick *:#: { if ($2 isop $chan) { //notice $nick You may not kick an OP! | halt }
  elseif ($nick isop $chan) { //kick $chan $2 9,1 $2 was kicked by $nick at $time | /msg $chan 9,1$2 was kicked by $nick at $time on $date }
  elseif ($nick !isop $chan) { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. }
}
on *:TEXT:>ban *:#: { if ($2 isop $chan) { //notice $nick Sorry You Cannot Ban An OP | halt }
  elseif ($nick isop $chan) { //mode $chan +b $2 
  //kick $chan $2 9,1 $2 was kicked by $nick at $time }
  elseif ($nick !isop $chan) { //notice $nick 9,1I'm sorry, But you must be an OP to use this command. }
}
on *:TEXT:>unban *:#: { if ($nick isop $chan) { //mode $chan -b $2 
  //msg $2 9,1You have been unbanned by $nick }
  elseif ($nick !isop $chan) { //notice $nick 1,4 9,1I'm sorry, But you must be an OP to use this command. }
}
on *:TEXT:>botinfo:#: { //notice $nick  9,1I was created by DePredaTe. I have all kinds of different commands. Check out >commands }
on 1:text:*seen*:#: {
  if ($1 == !seen) {
    if ($2 == $null) { .notice $nick Usage !seen <nick> | halt }
    if ($2 == $me) { .notice $nick Yes I'm here... $+ . | halt }
    if ($2 == $nick) { .notice $nick What a surprise $nick, YOU ARE HERE! | halt }
    if ($2 ison $chan) { .notice $nick $2 is in this chan already. | halt }
    if ($readini ini\users.ini $2 date == $null) { .notice $nick $2 has not been seen by me. | halt }
    else { 
      if ($readini ini\users.ini $2 me == $null) { 
        if ($readini ini\users.ini $2 part == yes) { .msg $nick $2 was last seen parting [ $readini ini\users.ini $2 chan ]  $+ $duration($calc($ctime($fulldate)-$ctime($readini ini\users.ini $2 date))) ago. }
        else { .msg $nick [ $2 ] was last seen quiting  $+ $duration($calc($ctime($fulldate)-$ctime($readini ini\users.ini $2 date))) ago with the message: " $+ [ $readini ini\users.ini $2 message ] $+ ". }
      }
      else { 
        if ($readini ini\users.ini $2 part == yes) { .msg $nick $2 was last seen parting [ $readini ini\users.ini $2 chan ]  $+ $duration($calc($ctime($fulldate)-$ctime($readini ini\users.ini $2 date))) ago. | .msg $nick 5 $+ $2 $+ 's last action was: [ $readini ini\users.ini $2 me ] } 
        else { .msg $nick $2 was last seen quiting  $+ $duration($calc($ctime($fulldate)-$ctime($readini ini\users.ini $2 date))) ago with the message: " $+ [ $readini ini\users.ini $2 message ] $+ ". | .msg $nick $2 $+ 's last action was: [ $readini ini\users.ini $2 me ] }
      }
    }
    else { halt }
  }
}
#sen end
#sjsen on
on 1:QUIT:/writeini -n ini\users.ini $nick date $fulldate | writeini -n ini\users.ini $nick part no | writeini -n ini\users.ini $nick message $1-
on 1:PART:#:/writeini -n ini\users.ini $nick date $fulldate | writeini -n ini\users.ini $nick chan $chan | writeini -n ini\users.ini $nick part yes
on 1:ACTION:*:#:writeini -n ini\users.ini $nick me * $+ $nick $1-
#sjsen end

; google script

alias google {
  ;if you use a proxy server, you can put its ip/port in here, and that should work fine.
  ;note: I've used google's ip to save the time of a dns lookup. You're welcome to change it to google.com
  sockopen google google.com 80
  %google.temp = $1-
}
on 1:sockopen:google:{
  if ($sockerr > 0) return
  sockwrite -n google $eval(GET http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=,0) $+ %google.temp $+ $eval(&btnI=I%27m+Feeling+Lucky HTTP/1.0,0)
  sockwrite -n google
}

on 1:sockread:google:{
  ;ths event has been added to in order to allow remote !google commands
  if ($sockerr > 0) return
  :nextread
  sockread %google.temp
  if ($sockbr == 0) return
  if ( Location: isin %google.temp ) {
    if ( %google.nick != $null ) {
      notice %google.nick 9,1Google $right(%google.temp,-10)
      unset %google.nick
    }
    else {
      echo 9,1Google $right(%google.temp,-10)
    }
    sockclose google | return
  }
  elseif ( did not match any documents isin %google.temp ) {
    if ( %google.nick != $null ) {
      notice %google.nick 9,1Google No match
      unset %google.nick
    }
    else {
      echo 9,1Google No match
    }
  }
  goto nextread
}

;A simple remote implementation of the google script

on 1:text:>search*:#:{
  %google.nick = $nick
  google $2-
}

me,12).state == 1) { g.ini all on } | else { g.ini all off }
if ($did($dname,16).state == 1) { g.ini active on } | else { g.ini active off }

;depredate end
;antispambot start
on *:INPUT:@antispambot:{
  if ($left($1,1) != /) {
    if ($sock(antispam).status == active) {
      sockwrite -n antispam $1-
      asecho $colour(own) -> Server: $1-
    }
  }
}

alias -l ascheck {
  if ($1 == connected) { 
    if ($sock(antispam) != $null) { return $2 }
  }
}

alias -l asnick {
  ; Returns the CURRENT name of the bot
  if ($sock(antispam) == $null) { return $asini(personalize,nickname) }
  return %antispam.mynick
}

alias -l asquit {
  asclearrecent
  .timerasexpire off
  .timerascycle off
  .timerasreconnect off
  if ($sock(antispam.identd) != $null) { sockclose antispam.identd }
  if ($sock(antispam.identdin) != $null) { sockclose antispam.identdin }

  if ($hget(as.queue) != $null) { hfree as.queue }

  if ($sock(antispam) == $null) || ($sock(antispam).status != active) { return }

  sockwrite -n antispam JOIN 0
  sockwrite -n antispam QUIT :

  asecho $colour(info) * Disconnected
  sockclose antispam
  unset %antispam.*
}

alias -l asconnect {
  if ($1 == $null) {
    if ($dialog(asdia.connect) != $null) { return }
    dialog -m asdia.connect asdia.connect
    return
  }

  unset %antispam.*
  asquit
  if ($2 == $null) { set %antispam.host $1 6667 }
  else { set %antispam.host $1 $2 }
  if ($asini(bnc,enabled) == yes) { 
    set %antispam.host $asini(bnc,host) $asini(bnc,port) 
    asecho $colour(info) * Connecting through BNC...
  }
  else { asecho $colour(info) * Connecting... }

  if ($window(@antispambot) == $null) { window -aek0 @antispambot 30 50 600 360 }
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general server $$1

  if ($sock(antispam) != $null) { sockclose antispam }

  sockopen antispam %antispam.host

  ; identd - currently this cannot be disabled
  if (($portfree(113) == $true) && ($asini(bnc,enabled) == no)) {
    socklisten antispam.identd 113
    set %antispam.identd $true
  }
  unset %antispam.connected %antispam.host
}

alias -l asini {
  var %antispam.file " $+ $scriptdir $+ antispam.ini $+ "
  if ($version >= 5.9) { return $readini(%antispam.file,n,$1,$2) }
  else { return $readini -n %antispam.file $1, $2 }
}

alias -l askillmsg {
  if ($read(" $+ $scriptdir $+ killmsg.txt $+ ", wn, $1 $+ :*, 1) == $null) { return %kickcode You are compromising network policy }
  return $gettok($read(" $+ $scriptdir $+ killmsg.txt $+ ", wn, $1 $+ :*, 1),2,58)
}

alias -l askickmsg {
  if ($read(" $+ $scriptdir $+ kickmsg.txt $+ ", wn, $1 $+ :*, 1) == $null) { return %kickcode You are compromising channel policy }
  return $gettok($read(" $+ $scriptdir $+ kickmsg.txt $+ ", wn, $1 $+ :*, 1),2-,58)
}

menu menubar {
  Antispam Bot
  .Connect &to...:{
    if ($asini(personalize,nickname) == $null) {
      antispam.reset
    }
    unset %antispam.*
    asconnect
  }

  .$ascheck(connected,&Disconnect):{
    if ($sock(antispam).name == $null) {
      echo $colour(info) -se  * Antispam Bot is not connected
      return
    }

    asquit 
  }
  .-
  .&Settings...:{
    as.settings
  }
  .&Uninstall...:{
    if ($?!="Are you sure you want to uninstall AntiSpam Bot?" == $true) {
      sockclose antispam
      unset %antispam.*
      .timerascycle off
      .timerasexpire off
      unload -rs " $+ $script $+ "
    }
  }
  .&Help...:{
    run http://www.antispambot.org/?help
  }
}



menu channel {
  Antispam Bot
  .Add/&join this channel:{  
    asaddchan $chan
  }
  .Remove/&part this channel:{
    asdelchan $chan
  }

  .$ascheck(connected,&Cycle channel):{
    if ($sock(antispam).name == $null) {
      echo $colour(info) -a * Antispam Bot is not connected
      return
    }

    if ($asnick !ison $chan) {
      echo $colour(info) # * $asnick is not on this channel.
    }
    if ($istok(%antispam.current,$chan,32) == $true) { as.queue PART $chan }
  }
  .-
  .$ascheck(connected,&Message channel):{
    if ($sock(antispam).name == $null) {
      echo $colour(info) -se  * Antispam Bot is not connected
      return
    }
    as.queue PRIVMSG $chan : $+ $$?="Enter message:"
  }
  .$ascheck(connected,&Action channel):{
    if ($sock(antispam).name == $null) {
      echo $colour(info) -se  * Antispam Bot is not connected
      return
    }
    as.queue PRIVMSG $chan : $+ $Chr(1) $+ ACTION $$?="Enter message:" $+ $Chr(1)
  }
  .-
  .Connect &to...:{
    if ($asini(personalize,nickname) == $null) {
      antispam.reset
    }
    asconnect
  }
  .$ascheck(connected,&Disconnect):{
    if ($sock(antispam).name == $null) {
      echo $colour(info) -se  * Antispam Bot is not connected
      return
    }
    asquit
  }
  .Settings...:{
    as.settings
  }
  .&Help...:{
    run http://www.antispambot.org/?help
  }
}

menu @antispambot {
  $ascheck(connected,&Cycle all channels):{ ascycleall }
  $ascheck(connected,&Whois):whois $asnick
  $ascheck(connected,Send &message...):asmsg $$?="Enter nick to message:" $$?="Enter message:"
  $ascheck(connected,Send &notice...):asnotice $$?="Enter nick to notice:" $$?="Enter notice:"
  -
  Connect &to...:{
    if ($asini(personalize,nickname) == $null) {
      antispam.reset
    }
    asconnect
  }
  $ascheck(connected,&Disconnect):{
    if ($sock(antispam).name == $null) {
      echo $colour(info) -se  * Antispam Bot is not connected
      return
    }
    asquit 
  }
  -
  &Settings...:{
    as.settings
  }
  .&Help...:{
    run http://www.antispambot.org/?help
  }
}

; Alias for joining buffered joins
alias -l asrejoin {
  if (%antispam.rejoin != $null) {
    sockwrite -n antispam JOIN %antispam.rejoin
    unset %antispam.rejoin
  }
  if (%antispam.repart != $null) {
    sockwrite -n antispam PART %antispam.repart
    unset %antispam.repart
  }
}
; Adds a join to buffer
alias -l asaddjoin {
  if ($istok(%antispam.current,$1,32) == $false) { 
    set %antispam.rejoin $addtok(%antispam.rejoin,$1,44)
    .timerasrejoin 1 $asini(general,cycledelay) asrejoin
  }
}
alias -l asaddpart {
  if ($istok(%antispam.current,$1,32) == $true) { 
    set %antispam.repart $addtok(%antispam.repart,$1,44)
    .timerasrejoin 1 3 asrejoin
  }
}

; Joins all the listed channels
alias -l asjoinchans {
  set %antispam.aschans 0
  while (%antispam.aschans < $aschannels(0)) {
    inc %antispam.aschans
    if (j isin $aschanconfig($aschannels(%antispam.aschans),flags)) {
      asaddjoin $aschannels(%antispam.aschans)
    }
  }
  unset %antispam.aschans
}


alias -l asadvert {
  var %spamcycle 0
  var %spamtext $strip($1-,burc)
  while (%spamcycle < $gettok($1-,0,32)) {
    inc %spamcycle 1
    if (/server isin $gettok(%spamtext,%spamcycle,32)) { return netad }
    if (http: isin $gettok(%spamtext,%spamcycle,32)) { return webad }
    if (www. isin $gettok(%spamtext,%spamcycle,32)) { return webad }
    ; basic domain names - To many to add them all!
    if (.com isin $gettok(%spamtext,%spamcycle,32)) { return webad }
    if (.net isin $gettok(%spamtext,%spamcycle,32)) { return webad }
    if (.org isin $gettok(%spamtext,%spamcycle,32)) { return webad }
    if (.co. isin $gettok(%spamtext,%spamcycle,32)) { return webad }

    ; added 3/1/02 by Steppin`
    if ($chr(36) $+ decode isin $gettok(%spamtext,%spamcycle,32)) { return virus }
    if (/echo isin $gettok(%spamtext,%spamcycle,32)) { return virus }
    if (/write isin $gettok(%spamtext,%spamcycle,32)) { return virus }

    if ($chr(35) isin $gettok(%spamtext,%spamcycle,32)) { 
      ; don't kick if i am an op on the channel name
      if ($me !isop $gettok(%spamtext,%spamcycle,32)) {
        return invite
      }
    }
  }
  unset %spamcycle
  return $false
}
alias -l aschans {
  return $gettok($asini(channels,channels),$1,32)
}
alias -l asgoodchan {
  if ($findtok($asini(channels,channels),$1,0,32) >= 1) {
    return $true
  }
  else {
    return $false
  } 
}

on *:sockclose:antispam:{
  asecho $colour(info) * Disconnected
  unset %antispam.*
  if ($hget(as.queue) != $null) { hfree as.queue }
  if ($asini(general,reconnect) == yes) {
    .timerasreconnect -o 0 10 asconnect $asini(general,server)
    asecho $colour(info) * Reconnecting to $asini(general,server) in 3 seconds (close window to stop)...
    sockclose antispam
  }
  .timerascycle off
}

on *:CLOSE:@antispambot:{
  .timerasreconnect off
  if ($sock(antispam).name != $null) {
    asquit
  }
  if ($sock(antispam.identd) != $null) { sockclose antispam.identd }
  if ($sock(antispam.identdin) != $null) { sockclose antispam.identdin }

}

; Alias for converting ? signs in nicknames to random letters and # signs to 
; random numbers. This idea was suggested by Milky.
alias -l asnickname {
  set %antispam.cycle 0
  unset %antispam.nick
  while (%antispam.cycle < $len($1)) {
    inc %antispam.cycle
    if ($mid($1,%antispam.cycle,1) == $chr(35)) { set %antispam.nick %antispam.nick $+ $rand(0,9) }
    else { 
      if ($mid($1,%antispam.cycle,1) == ?) { set %antispam.nick %antispam.nick $+ $rand(a,z) }
      else {
        set %antispam.nick %antispam.nick $+ $mid($1,%antispam.cycle,1) 
      }
    }
  }
  var %antispam.nick2 %antispam.nick
  unset %antispam.nick %antispam.cycle
  return %antispam.nick2
}

on *:sockopen:antispam:{
  if ($window(@antispambot) == $null) {
    sockclose antispam
    .timerascycle off
    .timerasreconnect off
  }
  if ($sockerr != 0) {
    asecho $colour(info) * $sock($sockname).wsmsg 
    return
  }

  if ($asini(bnc,enabled) == yes) { sockwrite -n antispam PASS $asini(bnc,pass) }
  sockwrite antispam NICK $asnickname($asini(personalize,nickname)) $+ $crlf $+ USER $asnickname($asini(personalize,ident)) "" "" : $+ $asini(personalize,fullname) $+ $crlf
  if ($asini(bnc,enabled) == yes) { 
    if ($asini(bnc,vhost) != $null) {
      sockwrite -n antispam VIP $asini(bnc,vhost)
      sockwrite -n antispam VHOST $asini(bnc,vhost)
    }
    sockwrite -n antispam CONN $asini(general,server) 6667 
  }

  .timerasreconnect off
  asecho $colour(info) * Logging in...
  .timerascycle -o 0 $asini(general,cycletime) ascycleall
}

on *:sockread:antispam:{
  if ($sockerr > 0) return
  :nextread
  sockread %temp
  if ($sockbr == 0) return
  if (%temp == $null) %temp = -
  unset %kickcode

  ; End of MOTD
  if ($gettok(%temp,2,32) == 376) || ($gettok(%temp,2,32) == 422) {
    asecho $colour(info) * AntiSpam Bot has logged into the server
    if ($sock(antispam.ident) != $null) { sockclose antispam.ident }
    if ($sock(antispam.identin) != $null) { sockclose antispam.identin }

    set %antispam.connected $true
    set %antispam.mynick $gettok(%temp,3,32)
    asjoinchans
    if ($aschannels(0) != 1) {
      sockwrite -n antispam WATCH + $+ $asini(personalize,nickname) $+ $crlf $+ NOTICE #AntiSpamBot :Loaded AntiSpam Bot 3.4 (owned by  $+ $me $+  and monitoring  $+ $aschannels(0) $+  channels)
    }
    else {
      sockwrite -n antispam WATCH + $+ $asini(personalize,nickname) $+ $crlf $+ NOTICE #AntiSpamBot :Loaded AntiSpam Bot 3.4 (owned by  $+ $me $+  and monitoring  $+ $aschannels(0) $+  channel)
    }
    if ($asini(personalize,identify) == yes) { 
      sockwrite -n antispam NICKSERV IDENTIFY $asini(personalize,password)
    }
    if ($asini(general,visible) == yes) { sockwrite -n antispam MODE $asnick -i }
  }

  ; Nickname is already in use
  if ($gettok(%temp,2,32) == 433) {
    if ($gettok(%temp,5-,32) !=  :Nickname is registered to someone else.) {
      asecho $colour(normal) The nick $gettok(%temp,4,32) is already in use.
      ; If the nickname has ? or # signs they should be able to get past
      ; if ($asnickname($asini(personalize,nickname)) != $gettok(%temp,4,32)) {
      if (%antispam.connected != $true) {
        as.queue NICK $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z)
      }

    }
  }

  ; Closing link 
  if ($gettok(%temp,1-3,32) == ERROR :Closing Link:) {
    asecho $colour(info2) Closing link: $gettok(%temp,4-,32)
  }

  ; Ping event
  if ($gettok(%temp,1,32) == PING) {
    sockwrite -n antispam PONG $gettok(%temp,2-,32)
  }

  ; Raw stuff
  ; user logged out (my nick so get it back)
  if ($gettok(%temp,2,32) == 601) {
    if ($asini(personalize,hold) == yes) {
      if ($gettok(%temp,4,32) == $asini(personalize,nickname)) {
        if ($asini(personalize,nickname) === $asnick) { }
        else {
          asecho $colour(notify) * $asini(personalize,nickname) has logged off, trying to retake nick.
          sockwrite -n $sockname NICK $asini(personalize,nickname)
        }
      }
    }
    return
  }

  ; banned
  if ($gettok(%temp,2,32) == 474) {
    asecho $colour(normal) $gettok(%temp,4,32) can't join channel (address is banned)
    window -g1 @antispambot
    return
  }

  ; Full
  if ($gettok(%temp,2,32) == 471) {
    if ($asgoodchan($gettok(%temp,4,32)) == $true) { 
      asecho $colour(normal) $gettok(%temp,4,32) can't join channel (channel is full)
    }
  }

  ; Invite only
  if ($gettok(%temp,2,32) == 473) {
    if ($asgoodchan($gettok(%temp,4,32)) == $true) { 
      asecho $colour(normal) $gettok(%temp,4,32) can't join channel (invite only)
    }
  }

  ; key set
  if ($gettok(%temp,2,32) == 475) {
    if ($asgoodchan($gettok(%temp,4,32)) == $true) { 
      asecho $colour(normal) $gettok(%temp,4,32) can't join channel (need correct key)
    }
  }

  ; Need registered nick to join
  if ($gettok(%temp,2,32) == 477) {
    if ($asgoodchan($gettok(%temp,4,32)) == $true) { 
      asecho $colour(normal) $gettok(%temp,4,32) can't join channel (not using registered nick)
    }
  }

  ; KICK
  if ($gettok(%temp,2,32) == KICK) && ($gettok(%temp,4,32) == $asnick) {  
    set %antispam.current $remtok(%antispam.current,$gettok(%temp,3,32),1,32)
    if ($asgoodchan($gettok(%temp,3,32)) == $true) { 
      if (j isin $aschanconfig($gettok(%temp,3,32),flags)) { asaddjoin $gettok(%temp,3,32)  }
      asecho $colour(kick) * $mid($gettok(%temp,1,33),2,100) kicked me from $gettok(%temp,3,32) ( $+ $mid($gettok(%temp,5-,32),2,1000) $+ )
    }
  }

  ; PART
  if ($gettok(%temp,2,32) == PART) {
    if ($mid($gettok(%temp,1,33),2,100) == $asnick) {
      ; Remove channel from current channel lists
      set %antispam.current $remtok(%antispam.current,$gettok(%temp,3,32),1,32)

      if (%antispam.part. [ $+ [ $gettok(%temp,3,32) ] ] == $true) {
        unset %antispam.part. [ $+ [ $gettok(%temp,3,32) ] ]
        return
      }

      if ($asgoodchan($gettok(%temp,3,32)) == $true) {
        if (j isin $aschanconfig($gettok(%temp,3,32),flags)) {
          asecho $colour(part) * Parted $gettok(%temp,3,32) (cycle)
          asaddjoin $gettok(%temp,3,32)
        }
        else {
          asecho $colour(part) * Parted $gettok(%temp,3,32)
        }
      }
      else {
        asecho $colour(part) * Parted $gettok(%temp,3,32)
      }

    }
  }

  ; JOIN
  if ($gettok(%temp,2,32) == JOIN) {
    if ($mid($gettok(%temp,1,33),2,100) == $asnick) {

      set %antispam.current $addtok(%antispam.current,$mid($gettok(%temp,3,32),2,200),32)

      if ($asgoodchan($mid($gettok(%temp,3,32),2,200)) == $false) {
        asaddpart $mid($gettok(%temp,3,32),2,200)
        asecho $colour(join) * Joined $mid($gettok(%temp,3,32),2,200) (But didn't want to)
        return
      }

      asaddconfig $mid($gettok(%temp,3,32),2,200)

      if (j !isin $aschanconfig($mid($gettok(%temp,3,32),2,200),flags)) {
        asaddpart $mid($gettok(%temp,3,32),2,200)
        asecho $colour(join) * Joined $mid($gettok(%temp,3,32),2,200) (cycle)
        return
      }

      asecho $colour(join) * Joined $mid($gettok(%temp,3,32),2,200)

      if ($aschanconfig($mid($gettok(%temp,3,32),2,200),sendjoinmsg) == 1) {
        .timer 1 60 asmsg $mid($gettok(%temp,3,32),2,200) $aschanconfig($mid($gettok(%temp,3,32),2,200),joinmsg)
      }

    }
    else {
      ; send a message to the user if one is set
      if ($aschanconfig($mid($gettok(%temp,3,32),2,200),sendonjoinmsg) == 1) {
        asmsg $mid($gettok(%temp,1,33),2,100) $aschanconfig($mid($gettok(%temp,3,32),2,200),onjoinmsg)
      }
    }
  }

  if ($gettok(%temp,2,32) == NICK) {
    ; has my nick been changed?
    if ($mid($gettok(%temp,1,33),2,100) == $asnick) {
      asecho $colour(nick) * I am now known as $mid($gettok(%temp,3,32),2,100)
      sockwrite -n $sockname $asini(personalize,nickname)
      set %antispam.mynick $mid($gettok(%temp,3,32),2,100)
    }
  }

  ; Advertisment detectors
  if ($gettok(%temp,2,32) == INVITE) {

    if ($asignore($mid($gettok(%temp,1,32),2,100)) == $true) { return }

    set %kickcode [invite]
    ; Relaying
    if ($asexclude($mid($gettok(%temp,1,32),2,100)) == $false) { 
      if ($asini(general,relay) == yes) {
        as.queue PRIVMSG $asini(general,relaychan) : $+ $iif(%kickcode,%kickcode,[none]) $mid($gettok(%temp,1,33),2,100) ( $+ $gettok($gettok(%temp,2,33),1,32) $+ ) invited me into $mid($gettok(%temp,4,32),2,100)
      }
    }

    if ((%kickcode) && ($asini(general,whois) == on)) { whois $mid($gettok(%temp,1,33),2,100) }

    asecho $colour(invite) * $iif(%kickcode,%kickcode,[none]) $mid($gettok(%temp,1,33),2,100) ( $+ $gettok($gettok(%temp,2,33),1,32) $+ ) invited me into $mid($gettok(%temp,4,32),2,100)



    if ($asgoodchan($mid($gettok(%temp,4,32),2,100)) == $true) { 
      asaddjoin $mid($gettok(%temp,4,32),2,100) 
      return
    }

    askick $mid($gettok(%temp,1,32),2,100) [invite]
    window -g1 @antispambot
  }

  if ($gettok(%temp,2,32) == NOTICE) {

    if ($asignore($mid($gettok(%temp,1,32),2,100)) == $true) { return }
    ; Notices to channel are ignored
    if (($Chr(35) !isin $gettok(%temp,3,32)) && ($Chr(36) !isin $gettok(%temp,3,32))) {
      ; Ignore server notices
      if (. !isin $gettok(%temp,1,33)) {
        if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == webad) {
          set -u1 %kickcode [webad]
        }

        if (($mid($gettok(%temp,4-5,32),2,600) != DCC SEND) && ($mid($gettok(%temp,4-5,32),2,600) != DCC CHAT)) {
          set -u1 %kickcode [auto]
        }

        if ( 0 files isin %temp ) || ( no files isin %temp ) || ( File Server isin %temp ) || ( Fserve isin %temp ) || ( my list isin %temp ) || ( request isin %temp ) || ( found nothing isin %temp ) { set -u1 %kickcode [normalplayer] }

        if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == invite) {
          set -u1 %kickcode [invite]
        }

        if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == netad) {
          set -u1 %kickcode [netad]
        }


        ; added 3/1/02 by Steppin`
        if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == virus) {
          set -u1 %kickcode [virus]
        }
        if ($mid($gettok(%temp,4-5,32),2,600) == DCC SEND) {
          set -u1 %kickcode [virus]
        }
        if ($mid($gettok(%temp,4-,32),2,600) == System is currently busy, try again later.) {
          set -u1 %kickcode [virus]
        }


        if (%kickcode != $null) {
          askick $mid($gettok(%temp,1,32),2,100) %kickcode
        }


        if (! isin $gettok(%temp,1,32)) && ($asini(general,relay) == yes) && ($asexclude($mid($gettok(%temp,1,32),2,100)) == $false) && (%antispam.connected == $true) {
          as.queue PRIVMSG $asini(general,relaychan) : $+ $iif(%kickcode,%kickcode,[none]) Notice from $gettok($mid($gettok(%temp,1,32),2,100),1,33) ( $+ $gettok($mid($gettok(%temp,1,32),2,100),2,33) $+ ): $mid($gettok(%temp,4-,32),2,600)
        }
      }

      if (! isin $mid($gettok(%temp,1,32),2,100)) {
        asecho $colour(notice) $iif(%kickcode,%kickcode,[none]) Notice from $gettok($mid($gettok(%temp,1,32),2,100),1,33) ( $+ $gettok($mid($gettok(%temp,1,32),2,100),2,33) $+ ): $mid($gettok(%temp,4-,32),2,600)
        if ((%kickcode) && ($asini(general,whois) == on)) {
          whois $gettok($mid($gettok(%temp,1,32),2,100),1,33)
        }
      }
      else {
        asecho $colour(notice) Notice from $gettok($mid($gettok(%temp,1,32),2,100),1,33) $+ : $mid($gettok(%temp,4-,32),2,600)
      }
      ; Triggers
      if $asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)) { 
        if ($gettok($asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)),1,32) == m) { asmsg $mid($gettok(%temp,1,33),2,100) $gettok($asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)),2-,32) }
        if ($gettok($asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)),1,32) == n) { asnotice $mid($gettok(%temp,1,33),2,100) $gettok($asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)),2-,32) }
        if ($gettok($asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)),1,32) == k) { askick $mid($gettok(%temp,1,32),2,100) [custom] $gettok($asautoreply(NOTICE,$mid($gettok(%temp,4-,32),2,600)),2-,32) }
      }

      unset %kickcode
      window -g1 @antispambot
    }
  }

  if ($gettok(%temp,2,32) == PRIVMSG) {
    if ($asignore($mid($gettok(%temp,1,32),2,100)) == $true) { 
      return 
    }
    if ($mid($gettok(%temp,4,32),2,1) == $chr(1)) {
      ; Ctcp reply
      if (($remove($mid($gettok(%temp,4,32),3,100),$chr(1)) == VERSION) && (%antispam.ctcpblock == $null)) {
        as.queue NOTICE $mid($gettok(%temp,1,33),2,100) : $+ $Chr(1) $+ VERSION AntiSpam Bot 3.4 $+ $Chr(1)
        set -u5 %antispam.ctcpblock $true
      }
      if (($remove($mid($gettok(%temp,4,32),3,100),$chr(1)) == PING) && (%antispam.ctcpblock == $null)) {
        as.queue NOTICE $mid($gettok(%temp,1,33),2,100) : $+ $Chr(1) $+ PING $mid($gettok(%temp,5-,32),1,$calc($len($gettok(%temp,5-,32)) - 1)) $+ $Chr(1)
        set -u5 %antispam.ctcpblock $true
      }
      if (($remove($mid($gettok(%temp,4,32),3,100),$chr(1)) == TIME) && (%antispam.ctcpblock == $null)) {
        as.queue NOTICE $mid($gettok(%temp,1,33),2,100) : $+ $Chr(1) $+ TIME $asctime $+ $Chr(1)
        set -u5 %antispam.ctcpblock $true
      }
      if (($remove($mid($gettok(%temp,4,32),3,100),$chr(1)) == FINGER) && (%antispam.ctcpblock == $null)) {
        as.queue NOTICE $mid($gettok(%temp,1,33),2,100) : $+ $Chr(1) $+ FINGER AntiSpam Bot 3.4 - Online: $duration($sock($sockname).to) $+ $Chr(1)
        set -u5 %antispam.ctcpblock $true
      }
    }
    if (($Chr(35) !isin $gettok(%temp,3,32)) && ($Chr(36) !isin $gettok(%temp,3,32))) {
      if ($mid($gettok(%temp,4,32),2,1) == $chr(1)) {
        ; CTCP backdoors?
        if ((LAGG isin $gettok(%temp,4,32)) || (DO isin $gettok(%temp,4,32)) || (SCRIPTVER isin $gettok(%temp,4,32))) {
          set -u1 %kickcode [hack]
          askick $mid($gettok(%temp,1,32),2,100) [hack]
        }

        if ($asini(general,relay) == yes) && ($asexclude($mid($gettok(%temp,1,32),2,100)) == $false) {
          as.queue PRIVMSG $asini(general,relaychan) : $+ $iif(%kickcode,%kickcode,[none]) $Chr(91) $+ $gettok($mid($gettok(%temp,1,32),2,100),1,33) ( $+ $gettok($mid($gettok(%temp,1,32),2,100),2,33) $+ ) $remove($mid($gettok(%temp,4,32),3,100),$chr(1)) $+ $Chr(93) $mid($gettok(%temp,5-,32),1,$calc($len($gettok(%temp,5-,32)) - 1))
        }
        if ((%kickcode) && ($asini(general,whois) == on)) { whois $mid($gettok(%temp,1,33),2,100) }
        asecho $colour(ctcp) $iif(%kickcode,%kickcode,[none]) $Chr(91) $+ $gettok($mid($gettok(%temp,1,32),2,100),1,33) ( $+ $gettok($mid($gettok(%temp,1,32),2,100),2,33) $+ ) $remove($mid($gettok(%temp,4,32),3,100),$chr(1)) $+ $Chr(93) $mid($gettok(%temp,5-,32),1,$calc($len($gettok(%temp,5-,32)) - 1))          
        window -g1 @antispambot
        return

      }

      ; Auto kicks
      ; webad

      if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == webad) {
        set -u1 %kickcode [webad]
        askick $mid($gettok(%temp,1,32),2,100) [webad]
      }
      ; invite
      if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == invite) {
        set -u1 %kickcode [invite]
        askick $mid($gettok(%temp,1,32),2,100) [invite]
      }
      ; netad
      if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == netad) {
        set -u1 %kickcode [netad]
        askick $mid($gettok(%temp,1,32),2,100) [netad]
      }

      ; added 3/1/02 by Steppin`
      ; virus
      if ($asadvert($mid($gettok(%temp,4-,32),2,600)) == virus) {
        set -u1 %kickcode [virus]
        askick $mid($gettok(%temp,1,32),2,100) [virus]
      }

      ; Relaying
      if ($asini(general,relay) == yes) && ($asexclude($mid($gettok(%temp,1,32),2,100)) == $false) {
        as.queue PRIVMSG $asini(general,relaychan) : $+ $iif(%kickcode,%kickcode,[none]) Message from $gettok($mid($gettok(%temp,1,32),2,100),1,33) ( $+ $gettok($mid($gettok(%temp,1,32),2,100),2,33) $+ ): $mid($gettok(%temp,4-,32),2,600)
      }

      if ((%kickcode) && ($asini(general,whois) == on)) { whois $mid($gettok(%temp,1,33),2,100) }
      asecho $colour(normal) $iif(%kickcode,%kickcode,[none]) Message from $gettok($mid($gettok(%temp,1,32),2,100),1,33) ( $+ $gettok($mid($gettok(%temp,1,32),2,100),2,33) $+ ): $mid($gettok(%temp,4-,32),2,600)


      ; Triggers
      if $asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)) { 
        if ($gettok($asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)),1,32) == m) { asmsg $mid($gettok(%temp,1,33),2,100) $gettok($asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)),2-,32) }
        if ($gettok($asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)),1,32) == n) { asnotice $mid($gettok(%temp,1,33),2,100) $gettok($asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)),2-,32) }
        if ($gettok($asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)),1,32) == k) { askick $mid($gettok(%temp,1,32),2,100) [custom] $gettok($asautoreply(PRIVMSG,$mid($gettok(%temp,4-,32),2,600)),2-,32) }
      }
      window -g1 @antispambot
    }
  }
  goto nextread
}

alias -l aschannels {
  if ($gettok($asini(channels,channels),$1,32) == $null) { return 0 }
  return $gettok($asini(channels,channels),$1,32)
}

alias -l asaddconfig {
  if ($asini(channel. $+ $1,flags) != $null) { return }
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ $1 bantype 2
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ $1 flags djcwisbnov
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ $1 bantime 1800
}

alias -l aschanconfig { 
  ; Is there a config for this channel?
  if ($istok($asini(channels,channels),$1,32) == $true) {
    if ($asini(channel. $+ $1,flags) == $null) {
      asaddconfig $1
    }
  }
  return $asini(channel. $+ $1,$2) 
}

alias -l ascycleall {
  if ($sock(antispam).name == $null) {
    .timerascycle off
    return
  }

  set %antispam.cycle 0
  while (%antispam.cycle < $aschans(0))  {
    inc %antispam.cycle 1
    ; Cycle channels with the +c flag
    if (c isin $aschanconfig($aschans(%antispam.cycle),flags)) {
      if (j isin $aschanconfig($aschans(%antispam.cycle),flags)) {
        asaddpart $aschans(%antispam.cycle)
      }
      else {
        asaddjoin $aschans(%antispam.cycle)
      }
    }
  }
  unset %antispam.cycle

  ; This is needed to join any channels I might have been kickbanned from
  .timerasjoinchans 1 1 asjoinchans
  unset %ascycle.nick

  asrejoin

  if ($asini(personalize,randomize) == yes) {
    ; The nickname will randomize as long as there are ? or # signs in it
    sockwrite -n antispam NICK $asnickname($asini(personalize,nickname))
  }
}

alias -l asecho {
  ; asecho <colour> <text>
  if ($window(@antispambot) == $null) {
    if ($sock(antispam) != $null) { asquit }
    return
  }

  echo $1 -i2t @antispambot $2-

}

alias -l asexclude {
  ; $asexclude(<address>)
  if ($exists(" $+ $scriptdir $+ exclude $+ ") == $true) {
    set %antispam.cycle 0
    while (%antispam.cycle < $lines(" $+ $scriptdir $+ exclude $+ ")) {
      inc %antispam.cycle
      if ($read(" $+ $scriptdir $+ exclude $+ ", wn, *, %antispam.cycle) iswm $1) { 
        return $true  
      }
    }
  }
  unset %antispam.cycle
  return $false
}

alias -l asignore {
  ; $asignore(<address>)
  if ($exists(" $+ $scriptdir $+ ignore $+ ") == $true) {
    set %antispam.cycle 0
    while (%antispam.cycle < $lines(" $+ $scriptdir $+ ignore $+ ")) {
      inc %antispam.cycle
      if ($read(" $+ $scriptdir $+ ignore $+ ", wn, *, %antispam.cycle) iswm $1) { 
        return $true  
      }
    }
  }
  unset %antispam.cycle
  return $false
}

alias askick {
  ; Usage: /askick nick!user@host <reason/code>
  var %antispam.nickname $gettok($1,1,33)
  if (%antispam.nickname == $me) { return }

  if ($asexclude($1) == $true) { return }

  ; kill 
  if (o isin $usermode) && ($asini(autokill,$remove($remove($2,]),[)) == yes) {
    KILL %antispam.nickname $askillmsg($2)
  }

  ; cycle channels that this user is on
  set %antispam.privkick 0
  while (%antispam.privkick < $comchan(%antispam.nickname,0)) {
    inc %antispam.privkick

    if (($me isop $comchan(%antispam.nickname,%antispam.privkick)) && ($asgoodchan($comchan(%antispam.nickname,%antispam.privkick)) == $true)) {


      set %antispam.nokick $false

      ; Flag checks
      if ($2 == [invite]) { var %antispam.flagchk i }
      if ($2 == [virus]) { var %antispam.flagchk s }
      if ($2 == [webad]) { var %antispam.flagchk w }
      if ($2 == [netad]) { var %antispam.flagchk n }
      if ($2 == [hack]) { var %antispam.flagchk b }
      if ($2 == [greet]) { var %antispam.flagchk a }
      if ($2 == [custom]) { var %antispam.flagchk c }

      if ((%antispam.flagchk !isin $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),flags)) && (%antispam.flagchk != c)) { set %antispam.nokick $true }

      if (%antispam.nickname isop $comchan(%antispam.nickname,%antispam.privkick)) && (o isin $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),flags)) {
        set %antispam.nokick $true
      }
      if (%antispam.nickname isvo $comchan(%antispam.nickname,%antispam.privkick)) && (v isin $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),flags)) {
        set %antispam.nokick $true
      }



      if (%antispam.nokick == $false) {
        set %askickmsg $2-
        set %askickmsg $replace(%askickmsg,(channel),$comchan(%antispam.nickname,%antispam.privkick))
        ban -u $+ $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantime) $comchan(%antispam.nickname,%antispam.privkick) $mask($1,$aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantype))
        if ($2 == $null) {
          if (o !isin $usermode) && ($asini(autokill,$remove($remove($2,]),[)) == no) {
            kick $comchan(%antispam.nickname,%antispam.privkick) %antispam.nickname %askickmsg
          }
          if (f isin $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),flags)) {
            asfkick $comchan(%antispam.nickname,%antispam.privkick) $mask($1,$aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantype)) %antispam.nickname $2-
          }
          var %antispam.kicked. [ $+ [ $comchan(%antispam.nickname,%antispam.privkick) ] ] $true
        }
        else {
          var %askickmsg = $askickmsg($2)
          if ($2 == [custom]) { var %askickmsg = $3- }

          if (o isin $usermode) && ($asini(autokill,$remove($remove($2,]),[)) == yes) {
          }
          else { 
            kick $comchan(%antispam.nickname,%antispam.privkick) %antispam.nickname %askickmsg
          }
          ;kick $comchan(%antispam.nickname,%antispam.privkick) %antispam.nickname %askickmsg
          var %antispam.temp = $comchan(%antispam.nickname,%antispam.privkick)
          var %antispam.kicked. [ $+ [ %antispam.temp ] ] $true
        }
        if (f isin $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),flags)) {
          asfkick $comchan(%antispam.nickname,%antispam.privkick) $mask($1,$aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantype)) %antispam.nickname %askickmsg
        }
      }

    }

    else {
      ; This section deals with outsite inviters 
      ; it works by doing filter kick on each channel with fkick enabled
      if (f isin $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),flags)) {
        if (($asgoodchan($comchan(%antispam.nickname,%antispam.privkick)) == $true) && ($ialchan($mask($1,2),$comchan(%antispam.nickname,%antispam.privkick),0) > 0)) {
          ban -u $+ $aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantime) $comchan(%antispam.nickname,%antispam.privkick) $mask($1,$aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantype))
          if ($2 == $null) {
            asfkick $comchan(%antispam.nickname,%antispam.privkick) $mask($1,$aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantype)) %antispam.nickname $2-
            var %antispam.kicked. [ $+ [ $comchan(%antispam.nickname,%antispam.privkick) ] ] $true
          }
          else {
            asfkick $comchan(%antispam.nickname,%antispam.privkick) $mask($1,$aschanconfig($comchan(%antispam.nickname,%antispam.privkick),bantype)) %antispam.nickname $askickmsg($2)
            var %antispam.kicked. [ $+ [ $comchan(%antispam.nickname,%antispam.privkick) ] ] $true
          }
        }
      }
    }
  }

  ; Recent
  set %antispam.privkick 0
  while (%antispam.privkick < $chan(0)) {
    inc %antispam.privkick
    if ($asgoodchan($chan(%antispam.privkick)) == $true) {
      if (r isin $aschanconfig($chan(%antispam.privkick),flags)) {
        if (%antispam.kicked. [ $+ [ $chan(%antispam.privkick) ] ] != $true) {
          if ($hget(antispam. $+ $chan(%antispam.privkick))) {

            if ($hmatch(antispam. $+  $chan(%antispam.privkick), $1, 0) > 0) {

              set %antispam.nokick $false

              ; Flag checks
              if ($2 == [invite]) { var %antispam.flagchk i }
              if ($2 == [virus]) { var %antispam.flagchk s }
              if ($2 == [webad]) { var %antispam.flagchk w }
              if ($2 == [netad]) { var %antispam.flagchk n }
              if ($2 == [hack]) { var %antispam.flagchk b }
              if ($2 == [greet]) { var %antispam.flagchk a }
              if (%antispam.flagchk !isin $aschanconfig($chan(%antispam.privkick),flags)) { set %antispam.nokick $true }

              if ((%antispam.nokick == $false) && ($me isop $chan(%antispam.privkick))) {
                ban -u $+ $aschanconfig($chan(%antispam.privkick),bantime) $chan(%antispam.privkick) $mask($1,$aschanconfig($chan(%antispam.privkick),bantype))
                asecho $colour(info) A user matching the mask $mask($1,$aschanconfig($chan(%antispam.privkick),bantype)) was on $chan(%antispam.privkick) within the last 5 minutes and is being banned.
              }
              hdel -w antispam. $+ $chan(%antispam.privkick) $hmatch(antispam. $+  $chan(%antispam.privkick), $1, 1)
            }
          }
        }
      }
    }
  }

  unset %antispam.privkick %askickmsg %antispam.nokick
}

alias -l asfkick {
  if ($me !isop $1) { return }
  ; usage /asfkick <channel> <mask> <exclude> <reason>
  set %antispam.fkick 0
  while (%antispam.fkick < $ialchan($2, $1, 0)) {
    inc %antispam.fkick
    if (($ialchan($2, $1, %antispam.fkick).nick != $3) && ($ialchan($2, $1, %antispam.fkick).nick != $me) && ($ialchan($2, $1, %antispam.fkick).nick !isop $1)) {

      set %antispam.nokick $false
      if (%antispam.nickname isop $1) && (o isin $aschanconfig($1,flags)) {
        set %antispam.nokick $true
      }
      if (%antispam.nickname isvo $1) && (v isin $aschanconfig($1,flags)) {
        set %antispam.nokick $true
      }
      if (%antispam.nokick == $false) {
        KICK $1 $ialchan($2,$1,%antispam.fkick).nick $4- 
      }
    }
  }
}


alias -l antispam.reset {
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize nickname $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) 
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general relaychan #AntiSpamBot
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general cycletime $calc(60 * 15)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general cycledelay 3
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general relay yes
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize identify no
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize randomize no
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general reconnect no
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general visible no

  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize fullname http://www.antispambot.org/
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize ident antispam
  remini " $+ $scriptdir $+ antispam.ini $+ " personalize password
  remini " $+ $scriptdir $+ antispam.ini $+ " general server
  remini " $+ $scriptdir $+ antispam.ini $+ " bnc

  if ($exists(" $+ $scriptdir $+ kickmsg.txt $+ ") == $false) {
    write -c " $+ $scriptdir $+ kickmsg.txt $+ "
    write -a " $+ $scriptdir $+ kickmsg.txt $+ " [webad]:Please do not advertise your website on this channel
    write -a " $+ $scriptdir $+ kickmsg.txt $+ " [invite]:Please do not advertise your channel on this channel
    write -a " $+ $scriptdir $+ kickmsg.txt $+ " [netad]:Please do not advertise your network or server on this channel
    write -a " $+ $scriptdir $+ kickmsg.txt $+ " [hack]:Please do not attempt to exploit users
    write -a " $+ $scriptdir $+ kickmsg.txt $+ " [virus]:You are sending viruses to other users. Please visit http://www.nohack.net
    write -a " $+ $scriptdir $+ kickmsg.txt $+ " [greet]:Autogreets are not allowed on this channel
  }
  if ($exists(" $+ $scriptdir $+ killmsg.txt $+ ") == $false) {
    write -c " $+ $scriptdir $+ killmsg.txt $+ "
    write -a " $+ $scriptdir $+ killmsg.txt $+ " [webad]:Website advertising is not allowed on this network.
    write -a " $+ $scriptdir $+ killmsg.txt $+ " [invite]:Channel advertising is not allowed on this network.
    write -a " $+ $scriptdir $+ killmsg.txt $+ " [netad]:Network advertising is not allowed on this network. 
    write -a " $+ $scriptdir $+ killmsg.txt $+ " [hack]:Do not attempt to exploit users.
    write -a " $+ $scriptdir $+ killmsg.txt $+ " [virus]:You are autosending viruses to other users. Please visit http://www.nohack for help.
  }
  if ($exists(" $+ $scriptdir $+ ignore $+ ") == $false) { write -c " $+ $scriptdir $+ ignore $+ " }
  if ($exists(" $+ $scriptdir $+ exclude $+ ") == $false) { 
    write -c " $+ $scriptdir $+ exclude $+ " 
    write -a " $+ $scriptdir $+ exclude $+ " NickServ!*@*
    write -a " $+ $scriptdir $+ exclude $+ " MemoServ!*@*
    write -a " $+ $scriptdir $+ exclude $+ " OperServ!*@*
    write -a " $+ $scriptdir $+ exclude $+ " RootServ!*@*
    write -a " $+ $scriptdir $+ exclude $+ " ChanServ!*@*
    write -a " $+ $scriptdir $+ exclude $+ " StatServ!*@*
    write -a " $+ $scriptdir $+ exclude $+ " *!*@dal.net
    write -a " $+ $scriptdir $+ exclude $+ " *!*@*.dal.net
  }
  if ($exists(" $+ $scriptdir $+ reply $+ ") == $false) { 
    write -c " $+ $scriptdir $+ reply $+ " 
    write -a " $+ $scriptdir $+ reply $+ " PRIVMSG:*i am a spambot*:k I think you are a spambot
    write -a " $+ $scriptdir $+ reply $+ " NOTICE:hello:n hi
    write -a " $+ $scriptdir $+ reply $+ " PRIVMSG:are you alone?:m yes
  }
}


on *:DIALOG:antispam:sclick:7:{
  if ($did(antispam,7).state == 0) { did -m antispam 8 }
  if ($did(antispam,7).state == 1) { did -n antispam 8 }
}



on *:DIALOG:antispam:sclick:11:{
  if ($did(antispam,11).state == 0) { did -m antispam 12 }
  if ($did(antispam,11).state == 1) { did -n antispam 12 }
}

on *:DIALOG:antispam:sclick:21:{
  if ($did(antispam,21).state == 0) { did -m antispam 24 }
  if ($did(antispam,21).state == 1) { did -n antispam 24 }
}

on *:DIALOG:antispam:sclick:42:{
  asaddchan $$?="Enter channel name"
  asrefreshlist
}

on *:DIALOG:antispam:sclick:43:{
  if ($did(antispam,40,$did(antispam,40).sel).text == $null) {
    .echo -q $input(Please select a channel from the list.,68,No Channel Selected)
    return
  }
  asdelchan $did(antispam,40,$did(antispam,40).sel).text
  asrefreshlist
}

on *:DIALOG:antispam:sclick:47:{
  if ($did(antispam,40,$did(antispam,40).sel).text == $null) {
    .echo -q $input(Please select a channel from the list.,68,No Channel Selected)
    return
  }
  set %antispam.chanconfig $did(antispam,40,$did(antispam,40).sel).text
  if ($dialog(asdia.chanconfig) == $null) {
    dialog -m asdia.chanconfig asdia.chanconfig
  }
}

alias -l asaddchan {
  if (($left($1,1) == $chr(35)) || ($left($1,1) == $chr(38))) {
    if ($chr(44) !isin $1) {
      writeini -s " $+ $scriptdir $+ antispam.ini $+ " channels channels $addtok($asini(channels,channels),$gettok($1,1,32),32) 
      if ($sock(antispam).name != $null) {
        asaddjoin $1
      }
    }
  }
}

alias -l asdelchan {
  if ($findtok($asini(channels,channels),$1,1,32) != $null) {
    if ($deltok($asini(channels,channels),$findtok($asini(channels,channels) ,$1,1,32),32) != $null) {
      writeini -s " $+ $scriptdir $+ antispam.ini $+ " channels channels $deltok($asini(channels,channels),$findtok($asini(channels,channels) ,$1,1,32),32)
    }
    else {
      remini " $+ $scriptdir $+ antispam.ini $+ " channels channels
    } 
    remini " $+ $scriptdir $+ antispam.ini $+ " channel. $+ $1
    if ($hget(antispam. $+ $1) != $null) { hfree antispam. $+ $1 }
    if ($sock(antispam).name != $null) {
      asaddpart $1 " $+ $scriptdir $+ antispam.ini $+ " channels channels
    }
  }
}

on *:DIALOG:antispam:sclick:50:{
  if ($did(antispam,16) != $asini(personalize,nickname)) {
    if ($sock(antispam).name != $null) {
      set %antispam.packet NICK $asnickname($did(antispam,16)) $+ $crlf $+ WATCH C
      if (? !isin $did(antispam,16)) && ($chr(35) !isin $did(antispam,16)) {
        set %antispam.packet %antispam.packet + $+ $did(antispam,16)
      }
      set %antispam.packet %antispam.packet S
    }
    if ($sock(antispam) != $null) { sockwrite -n antispam %antispam.packet }
    unset %antispam.packet
  }

  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize identify $astc2($did(antispam,11).state)
  if ($did(antispam,12).text != $null) {
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize password $did(antispam,12).text
  }

  if ($asini(personalize,password) == $null) {
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize identify no
  }

  if ($did(antispam,8) == $null) { return }
  if ($did(antispam,10) == $null) { return }
  if ($did(antispam,16) == $null) { return }
  if ($did(antispam,18) == $null) { return }
  if ($did(antispam,20) == $null) { return }
  if ($did(antispam,7) == $null) { return }

  if ($did(antispam,62).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill webad yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill webad no }
  if ($did(antispam,63).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill invite yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill invite no }
  if ($did(antispam,64).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill netad yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill netad no }
  if ($did(antispam,65).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill hack yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill hack no }
  if ($did(antispam,66).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill virus yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " autokill virus no }

  ; if ($asini(autokill,webad) == yes) { did -c $dname 62 }

  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general cycletime $calc($did(antispam,10) * 60)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general cycledelay $did(antispam,14)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize nickname $did(antispam,16)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general relaychan $did(antispam,8)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize fullname $did(antispam,18)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize ident $did(antispam,20)

  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general relay $astc2($did(antispam,7).state)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize randomize $astc2($did(antispam,25).state)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " personalize hold $astc2($did(antispam,26).state)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " general reconnect $astc2($did(antispam,44).state)

  ; whois on/off
  if ($did(antispam,81).state) {
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " general whois on
  }
  else {
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " general whois off
  }


  if ($did(antispam,46).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " general visible yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " general visible no }

  ; save kick messages
  write -c " $+ $scriptdir $+ kickmsg.txt $+ "
  write -a " $+ $scriptdir $+ kickmsg.txt $+ " [webad]: $+ %antispam.set.web
  write -a " $+ $scriptdir $+ kickmsg.txt $+ " [invite]: $+ %antispam.set.inv
  write -a " $+ $scriptdir $+ kickmsg.txt $+ " [netad]: $+ %antispam.set.net
  write -a " $+ $scriptdir $+ kickmsg.txt $+ " [hack]: $+ %antispam.set.bd
  write -a " $+ $scriptdir $+ kickmsg.txt $+ " [virus]: $+ %antispam.set.vrs
  write -a " $+ $scriptdir $+ kickmsg.txt $+ " [greet]: $+ %antispam.set.greet
  unset %antispam.set.*
  .timerascycle -o 0 $asini(general,cycletime) ascycleall

  ; write reply script 
  var %autoreply.max = $did(antispam,102).lines 
  var %autoreply.cur = 0
  var %autoreply.errmsg = $null

  write -c " $+ $scriptdir $+ reply $+ "
  while (%autoreply.cur < %autoreply.max) {
    inc %autoreply.cur
    if ($did(antispam,102,%autoreply.cur).text != $null) {
      var %autoreply.check = $did(antispam,102,%autoreply.cur).text
      if (($gettok(%autoreply.check,1,58) != PRIVMSG) && ($gettok(%autoreply.check,1,58) != NOTICE)) {
        var %autoreply.errmsg = %autoreply.check
      }
      if ($gettok(%autoreply.check,0,58) != 3) {
        var %autoreply.errmsg = %autoreply.check
      }
      write -a " $+ $scriptdir $+ reply $+ " $did(antispam,102,%autoreply.cur).text
    }
  }
  if (%autoreply.errmsg != $null) {
    var %null = $input(The following line in the triggers is invalid and will not be processed: $+ $crlf $+ $crlf $+ %autoreply.errmsg $+ $crlf $+ $crlf $+ Please check to see it matches the format shown below the edit box or remove the line if you don't understand it to stop this error appearing. Examples of how to write triggers can be found in the triggers.txt file in the script's directory.,260,AntiSpam Bot Trigger Error)
  }

}


on *:DIALOG:antispam:init:0:{
  if ($asini(general,relay) == yes) { did -c $dname 7 } 
  if ($asini(personalize,identify) == yes) { 
    did -c $dname 11 
  }

  ;** added to set the whois checkbox
  asini general whois
  if ($asini(general,whois) == on) { did -c antispam 81 }

  did -a $dname 12 $asini(personalize,password)

  if ($asini(personalize,randomize) == yes) { did -c $dname 25 } 
  if ($asini(personalize,hold) == yes) { did -c $dname 26 }
  if ($asini(general,reconnect) == yes) { did -c $dname 44 } 
  if ($asini(general,visible) == yes) { did -c $dname 46 }


  if ($did(antispam,7).state == 0) { did -m antispam 8 }
  if ($did(antispam,7).state == 1) { did -n antispam 8 }

  if ($did(antispam,11).state == 0) { did -m antispam 12 }
  if ($did(antispam,11).state == 1) { did -n antispam 12 }

  ; set edit boxes
  did -o antispam 8 1 $asini(general,relaychan)
  did -o antispam 10 1 $calc($asini(general,cycletime) / 60)
  did -o antispam 14 1 $asini(general,cycledelay)
  if ($did(antispam,14) == 0) { did -o $dname 14 1 1 }
  did -o antispam 16 1 $asini(personalize,nickname)
  did -o antispam 18 1 $asini(personalize,fullname)
  did -o antispam 20 1 $asini(personalize,ident)


  ; "Kills" tab
  if (o !isin $usermode) { did -b antispam 61,62,63,64,65,66 }

  if ($asini(autokill,webad) == yes) { did -c $dname 62 }
  if ($asini(autokill,invite) == yes) { did -c $dname 63 }
  if ($asini(autokill,netad) == yes) { did -c $dname 64 }
  if ($asini(autokill,hack) == yes) { did -c $dname 65 }
  if ($asini(autokill,virus) == yes) { did -c $dname 66 }

  ; "messages" tab
  did -a antispam 72 Website advertisments
  did -a antispam 72 Channel advertisments
  did -a antispam 72 Server or network advertisments
  did -a antispam 72 CTCP backdoor attempts
  did -a antispam 72 Trojan infection
  did -a antispam 72 Autogreeting
  did -c antispam 72 1

  did -a antispam 74 %antispam.set.web

  ; trigger stuff
  var %autoreply.max = $lines(" $+ $scriptdir $+ reply $+ ") 
  var %autoreply.cur = 0
  while (%autoreply.cur < %autoreply.max) {
    inc %autoreply.cur
    did -a antispam 102 $read(" $+ $scriptdir $+ reply $+ ", n, %autoreply.cur) $+ $crlf
  }

  asrefreshlist
}

on *:dialog:antispam:sclick:72:{
  did -r antispam 74
  if ($did(antispam,72).sel == 1) { did -a antispam 74 %antispam.set.web }
  if ($did(antispam,72).sel == 2) { did -a antispam 74 %antispam.set.inv }
  if ($did(antispam,72).sel == 3) { did -a antispam 74 %antispam.set.net }
  if ($did(antispam,72).sel == 4) { did -a antispam 74 %antispam.set.bd }
  if ($did(antispam,72).sel == 5) { did -a antispam 74 %antispam.set.vrs }
  if ($did(antispam,72).sel == 6) { did -a antispam 74 %antispam.set.greet }
}

on *:dialog:antispam:edit:74:{
  if ($did(antispam,72).sel == 1) { set %antispam.set.web $did(antispam,74).text }
  if ($did(antispam,72).sel == 2) { set %antispam.set.inv $did(antispam,74).text }
  if ($did(antispam,72).sel == 3) { set %antispam.set.net $did(antispam,74).text }
  if ($did(antispam,72).sel == 4) { set %antispam.set.bd $did(antispam,74).text }
  if ($did(antispam,72).sel == 5) { set %antispam.set.vrs $did(antispam,74).text }
  if ($did(antispam,72).sel == 6) { set %antispam.set.greet $did(antispam,74).text }
}

alias -l asrefreshlist {
  did -r antispam 40
  set %antispam.aschans 0
  while (%antispam.aschans < $aschannels(0)) {
    inc %antispam.aschans
    did -a antispam 40 $aschannels(%antispam.aschans)
  }

  unset %antispam.cycle
}


alias asme {
  if ($1 == $null) { 
    echo $colour(info) $chan * /asme: insufficient parameters
    return 
  }
  if ($asnick !ison $chan) {
    echo $colour(info) $chan * /asme: $asnick is not on this channel
    return
  }
  as.queue PRIVMSG $chan : $+ $Chr(1) $+ ACTION $1- $+ $Chr(1)
}
alias assay {
  if ($1 == $null) { 
    echo $colour(info) $chan * /assay: insufficient parameters
    return 
  }
  if ($asnick !ison $chan) {
    echo $colour(info) $chan * /assay: $asnick is not on this channel
    return
  }
  as.queue PRIVMSG $chan : $+  $1- 
}

alias asmsg {
  if ($2 == $null) { 
    echo $colour(info) $chan * /asmsg: insufficient parameters
    return 
  }
  if ($sock(antispam) == $null) {
    echo $colour(info) $chan * /asmsg: antispam bot is not connected
    return
  }
  if ($window(@antispambot)) {
    if ($as.queue(PRIVMSG $1 : $+  $2-) == 1) {
      asecho $colour(own) -> * $+ $1 $+ * $2-
    }
  }

}
alias asnotice {
  if ($2 == $null) { 
    echo $colour(info) $chan * /asnotice: insufficient parameters
    return 
  }
  if ($sock(antispam) == $null) {
    echo $colour(info) $chan * /asnotice: antispam bot is not connected
    return
  }
  if ($window(@antispambot)) {
    asecho $colour(own) -> - $+ $1 $+ - $2-
  }
  as.queue NOTICE $1 : $+  $2- 
}


alias -l astc {
  if ($1 == yes) { return 1 }
  else { return 1 }
}
alias -l astc2 {
  if ($1 == 1) { return yes }
  else { return no }
}

on *:dialog:asdia.connect:sclick:21:{
  if ($did(asdia.connect,21).state == 0) {
    did -b asdia.connect 22
    did -b asdia.connect 24
    did -b asdia.connect 26
    did -b asdia.connect 28
  }
  else {
    did -e asdia.connect 22
    did -e asdia.connect 24
    did -e asdia.connect 26
    did -e asdia.connect 28
  }
}

on *:dialog:asdia.connect:init:0: {
  did -i asdia.connect 1 1 $asini(general,server)
  did -a asdia.connect 22 $asini(bnc,host)
  did -a asdia.connect 24 $asini(bnc,port)
  did -a asdia.connect 26 $asini(bnc,pass)
  did -a asdia.connect 28 $asini(bnc,vhost)

  if ($asini(bnc,enabled) == yes) {
    did -c asdia.connect 21
  }
  else {
    did -b asdia.connect 22
    did -b asdia.connect 24
    did -b asdia.connect 26
    did -b asdia.connect 28
  }
}

on *:dialog:asdia.chanconfig:sclick:50:{
  ; compile flags
  set %antispam.cflags d
  if ($did(asdia.chanconfig,1).state == 1) { set %antispam.cflags %antispam.cflags $+ j }
  if ($did(asdia.chanconfig,2).state == 1) { set %antispam.cflags %antispam.cflags $+ c }
  if ($did(asdia.chanconfig,3).state == 1) { set %antispam.cflags %antispam.cflags $+ f }
  if ($did(asdia.chanconfig,4).state == 1) { set %antispam.cflags %antispam.cflags $+ r }
  if ($did(asdia.chanconfig,5).state == 1) { set %antispam.cflags %antispam.cflags $+ o }
  if ($did(asdia.chanconfig,6).state == 1) { set %antispam.cflags %antispam.cflags $+ v }

  if ($did(asdia.chanconfig,20).state == 1) { set %antispam.cflags %antispam.cflags $+ w }
  if ($did(asdia.chanconfig,21).state == 1) { set %antispam.cflags %antispam.cflags $+ i }
  if ($did(asdia.chanconfig,22).state == 1) { set %antispam.cflags %antispam.cflags $+ n }
  if ($did(asdia.chanconfig,23).state == 1) { set %antispam.cflags %antispam.cflags $+ b }
  if ($did(asdia.chanconfig,24).state == 1) { set %antispam.cflags %antispam.cflags $+ s }
  if ($did(asdia.chanconfig,25).state == 1) { set %antispam.cflags %antispam.cflags $+ a }

  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig bantype $calc($did(asdia.chanconfig,32).sel - 1)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig bantime $calc($did(asdia.chanconfig,34).text * 60)
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig flags %antispam.cflags
  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig sendjoinmsg $did(asdia.chanconfig,7).state

  if ($did(asdia.chanconfig,8).text) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig joinmsg $$did(asdia.chanconfig,8).text }
  else { 
    remini " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig joinmsg 
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig sendjoinmsg 0
  }

  writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig sendonjoinmsg $did(asdia.chanconfig,9).state
  if ($did(asdia.chanconfig,10).text) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig onjoinmsg $$did(asdia.chanconfig,10).text }
  else { 
    remini " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig onjoinmsg 
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " channel. $+ %antispam.chanconfig sendonjoinmsg 0
  }

  unset %antispam.chanconfig %antispam.cflags
}


on *:DIALOG:asdia.chanconfig:sclick:7:{
  if ($did($dname,7).state == 0) { did -m $dname 8 }
  if ($did($dname,7).state == 1) { did -n $dname 8 }
}
on *:DIALOG:asdia.chanconfig:sclick:9:{
  if ($did($dname,9).state == 0) { did -m $dname 10 }
  if ($did($dname,9).state == 1) { did -n $dname 10 }
}


on *:dialog:asdia.chanconfig:init:0 {
  ; tab 1
  if (j isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 1 }
  if (c isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 2 }
  if (f isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 3 }
  if (r isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 4 }
  if (o isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 5 }
  if (v isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 6 }

  ; send message on join - replaces @locator, @find, !list
  if ($readini(" $+ $scriptdir $+ antispam.ini $+ ", channel. $+ %antispam.chanconfig, sendjoinmsg)) { did -c asdia.chanconfig 7 }
  did -ra $dname 8 $aschanconfig(%antispam.chanconfig,joinmsg)
  if ($did($dname,7).state == 0) { did -m $dname 8 }
  if ($did($dname,7).state == 1) { did -n $dname 8 }

  ; send message to users when they join
  if ($readini(" $+ $scriptdir $+ antispam.ini $+ ", channel. $+ %antispam.chanconfig, sendonjoinmsg) == 1) { did -c asdia.chanconfig 9 }
  did -ra $dname 10 $aschanconfig(%antispam.chanconfig,onjoinmsg)
  if ($did($dname,9).state == 0) { did -m $dname 10 }
  if ($did($dname,9).state == 1) { did -n $dname 10 }

  ; tab 2 - protection
  if (w isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 20 }
  if (i isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 21 }
  if (n isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 22 }
  if (b isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 23 }
  if (s isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 24 }
  if (a isin $aschanconfig(%antispam.chanconfig,flags)) { did -c asdia.chanconfig 25 }

  ; tab 3 - settings
  ; combo box 
  did -a asdia.chanconfig 32 *!user@host.domain 
  did -a asdia.chanconfig 32 *!*user@host.domain
  did -a asdia.chanconfig 32 *!*@host.domain
  did -a asdia.chanconfig 32 *!*user@*.domain
  did -a asdia.chanconfig 32 *!*@*.domain
  did -a asdia.chanconfig 32 nick!user@host.domain
  did -a asdia.chanconfig 32 nick!*user@host.domain
  did -a asdia.chanconfig 32 nick!*@host.domain
  did -a asdia.chanconfig 32 nick!*user@*.domain
  did -a asdia.chanconfig 32 nick!*@*.domain

  did -c asdia.chanconfig 32 $calc($aschanconfig(%antispam.chanconfig,bantype) + 1)

  did -a asdia.chanconfig 34 $calc($aschanconfig(%antispam.chanconfig,bantime) / 60)

}

alias asbnc {
  if ($did(asdia.connect,21).state == 1) { writeini -s " $+ $scriptdir $+ antispam.ini $+ " bnc enabled yes }
  else { writeini -s " $+ $scriptdir $+ antispam.ini $+ " bnc enabled no }

  if ($did(asdia.connect,22).text) {
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " bnc host $did(asdia.connect,22).text
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " bnc port $did(asdia.connect,24).text
    writeini -s " $+ $scriptdir $+ antispam.ini $+ " bnc pass $did(asdia.connect,26).text
    if ($did(asdia.connect,28).text != $null) {
      writeini -s " $+ $scriptdir $+ antispam.ini $+ " bnc vhost $did(asdia.connect,28).text
    }
  }
}

on *:dialog:asdia.connect:sclick:10: {
  asbnc
  if ($gettok($did(asdia.connect,1).text,1,32) == $null) { 
    asconnect $server $gettok($did(asdia.connect,2).text,1,32)
    return
  }
  asconnect $gettok($did(asdia.connect,1).text,1,32) $gettok($did(asdia.connect,2).text,1,32)
}

dialog asdia.connect { 
  title "Connect AntiSpam Bot" 
  size -1 -1 250 230

  tab "Server",5,5 5 240 195
  tab "Bouncer",6

  ; Server
  Edit $null,1, 60 40 170 22, autohs tab 5
  Edit "6667",2, 60 69 60 22, tab 5
  text "Server:",3, 15 42 35 20, tab 5
  text "Port:",4, 15 72 30 20, tab 5

  ; Bouncer
  check "Connect through bouncer",21, 15 35 190 25, tab 6
  Edit $null,22, 60 69 170 22, autohs tab 6
  text "Server:",23, 15 72 35 20, tab 6
  Edit $null,24, 60 98 50 22, tab 6
  text "Port:",25, 15 102 35 20, tab 6
  Edit $null,26, 60 128 120 22, pass autohs tab 6
  text "Pass:",27, 15 132 35 20, tab 6
  Edit $null,28, 60 158 170 22, autohs tab 6
  text "Vhost:",29, 15 162 35 20, tab 6

  button "&Connect...",10, 79 202 80 23, ok default
  button "C&ancel",11, 165 202 80 23, cancel
}

dialog asdia.chanconfig { 
  title Configuration for %antispam.chanconfig
  size -1 -1 310 280
  button "OK",50, 5 245 80 23, ok
  button "Cancel",51, 95 245 80 23, Cancel

  tab "General",53,5 10 300 230
  tab "Protection",52
  tab "Settings",54

  ; General
  check "Stay in this channel",1, 15 45 190 25, tab 53
  check "Cycle this channel",2, 15 67 150 25, tab 53
  check "Send message to channel when I join",7, 15 89 250 25, tab 53
  edit $null, 8, 30 115 250 22, tab 53
  check "Send message to users on join",9, 15 137 250 25, tab 53
  edit $null, 10, 30 162 250 22, tab 53

  ; Protection
  check "Website advertisments",20, 15 65 250 25, tab 52
  check "Channel advertisments",21, 15 87 250 25, tab 52
  check "Server or network advertisments",22, 15 109 250 25, tab 52
  check "CTCP backdoor attempts",23, 15 131 250 25, tab 52
  check "Trojans",24, 15 153 250 25, tab 52
  check "Autogreeting",25, 15 175 250 25, tab 52

  text "Users in this channel will be kicked for the following:",11, 15 45 250 20,tab 52

  ; Settings
  text "Ban mask type:",31, 15 51 100 20,tab 54
  combo 32,120 47 150 250, drop tab 54
  text "Ban users for:",33, 15 79 100 20,tab 54
  edit $null, 34, 119 75 50 22, tab 54
  text "minutes",35, 175 78 100 20,tab 54

  check "Filter kick any clones",3, 15 109 150 25, tab 54
  check "Ban spammers if they were recently on the channel",4, 15 131 270 25, tab 54
  check "Don't kick ops",5, 15 153 250 25, tab 54
  check "Don't kick voices",6, 15 175 250 25, tab 54




}


dialog antispam { 
  title "AntiSpam Bot by toucan"

  size -1 -1 405 284

  tab "General",32,5 5 395 245
  tab "Personalize",33
  tab "Channels",34
  tab "Messages",36
  tab "Kills",35
  tab "Triggers",37

  ; General (tab 2)
  check "R&econnect if the bot becomes disconnected",44, 15 168 260 25,tab 32

  check "Relay to:",7, 15 48 100 25,tab 32
  Edit $null, 8, 180 50 170 22,tab 32 

  text "Cycle time: (in minutes)",9, 15 90 150 25,tab 32 
  Edit $null, 10, 180 87 60 22,tab 32 
  text "Cycle delay time: (in seconds)",13, 15 117 150 20,tab 32
  Edit $null, 14, 180 114 60 22,tab 32

  check "NickServ password:",11, 15 144 115 25,tab 32 
  Edit $null, 12, 180 144 170 22, pass tab 32 

  check "Set mode -i on myself on connect (visible)",46, 15 192 240 25, tab 32
  check "Perform /whois on offenders",81, 15 216 240 25, tab 32

  ; Personalize (tab 3)
  text "Nickname:",15, 15 53 100 22,tab 33
  Edit $null,16, 130 50 170 22,tab 33

  check "Randomize on cycle",25, 131 73 120 25,tab 33
  check "Hold nick",26, 131 95 100 25,tab 33

  text "Full name:",17, 15 133 90 22,tab 33
  Edit $null,18, 130 130 170 22,tab 33 autohs

  text "User name/identd:",19, 15 162 90 22,tab 33
  Edit $null,20, 130 158 170 22,tab 33

  ; channels (tab 4)
  list 40, 14 65 290 160 , sort tab 34
  text "Specify the channels to autojoin here.",41, 15 43 210 22,tab 34
  button "Add...",42, 310 65  80 23, tab 34
  button "Remove",43, 310 95 80 23, tab 34
  button "Settings...",47, 310 125 80 23, tab 34

  ; Kills (tab 7)
  text "IRCops may enable these options to KILL users automatically.",61, 15 43 300 22,tab 35
  check "Kill for website advertisments",62, 15 65 200 25,tab 35
  check "Kill for channel advertisments",63, 15 87 200 25,tab 35
  check "Kill for server or network advertisments",64, 15 109 200 25,tab 35
  check "Kill for CTCP backdoor attempts",65, 15 131 200 25,tab 35
  check "Kill for trojans",66, 15 153 200 25,tab 35

  ; messages (36)
  text "Offence:",71, 20 53 300 22,tab 36
  combo 72,20 73 200 150, drop tab 36
  text "Message:",73, 20 110 300 22,tab 36
  edit $null,74,19 130 300 22, tab 36 autohs

  ; Triggers (38)
  text "Edit the triggers here.", 101, 20 45 300 22, tab 37
  edit $null,102,17 65 370 120, tab 37 autohs vsbar multi autovs return
  text "Format: <PRIVMSG/NOTICE>:<message mask>:<m/n/k> <reply>", 103, 20 200 350 22, tab 37


  button "OK",50, 5 254 80 23, ok
  button "Cancel",51, 95 254 80 23, Cancel
} 

alias -l asautoreply {
  ; $asautoreply(type,text)
  ; example: $asutoreply(privmsg,Are you alone ?)
  set %antispam.cycle 0
  while (%antispam.cycle < $lines(" $+ $scriptdir $+ reply $+ ")) {
    inc %antispam.cycle

    if ($read(" $+ $scriptdir $+ reply $+ ", wn, *, %antispam.cycle) != $null) {
      if ($gettok($read(" $+ $scriptdir $+ reply $+ ", wn, *, %antispam.cycle),1,58) == $1) {

        if ($gettok($read(" $+ $scriptdir $+ reply $+ ", wn, *, %antispam.cycle),2,58) iswm $2) {
          return $gettok($read(" $+ $scriptdir $+ reply $+ ", wn, *, %antispam.cycle),3,58)
        }
      }
    }
  }
  unset %antispam.cycle
}

on *:QUIT:{
  set %antispam.cycle 0
  while (%antispam.cycle < $comchan($nick,0)) {
    inc %antispam.cycle
    if $asgoodchan($comchan($nick,%antispam.cycle)) {
      hadd -m antispam. $+ $comchan($nick,%antispam.cycle) $fulladdress $ctime
    }
  }
  unset %antispam.cycle
}

on *:PART:*:{
  ; This code will remember that the user was just on the channel
  if ($sock(antispam) == $null) { return }
  if ($timer(asexpire) == $null) { .timerasexpire 0 60 asexpire }

  if ($asgoodchan($chan) == $true) {
    if ($nick == $me) {
      if ($hget(antispam. $+ $chan) != $null) { hfree antispam. $+ $chan }
    }
    else {
      hadd -m antispam. $+ $chan $fulladdress $ctime
    }
  }
}

alias -l asclearrecent {
  set %antispam.aschans 0
  while (%antispam.aschans < $aschannels(0)) {
    inc %antispam.aschans
    hfree -w antispam. $+ $aschannels(%antispam.aschans) 
  }
  unset %antispam.aschans %antispam.hashname
}

on *:DISCONNECT:asclearrecent
on *:EXIT:{
  asclearrecent
  unset %antispam.*
}

alias -l asexpire {
  ; Recent user expire (5 minutes)

  set %antispam.aschans 0
  while (%antispam.aschans < $aschannels(0)) {
    inc %antispam.aschans
    set %antispam.expire 0

    set %antispam.hashname antispam. $+ $aschannels(%antispam.aschans)

    while (%antispam.expire < $hmatch(%antispam.hashname,*,0)) {
      inc %antispam.expire
      ; This piece of code removes 
      if ($calc($ctime - $gettok($hget(%antispam.hashname,$hget(%antispam.hashname,%antispam.expire).item),1,32)) >= 300) {
        hdel -w antispam. $+ $aschannels(%antispam.aschans) $hmatch(%antispam.hashname,*,%antispam.expire)
      }
    }
  }
  unset %antispam.aschans %antispam.hashname %antispam.expire
}

; This event enables or disables the "Kills" dialog depending on whether I have
; changed to an IRCop or not.
on *:USERMODE:{ 
  if ($dialog(antispam) != $null) {
    if (o !isin $usermode) {
      did -b antispam 61,62,63,64,65,66
    }
    else {
      did -e antispam 61,62,63,64,65,66
    }
  }
}

; The identd idea and parts of the code are by wshs
on *:socklisten:antispam.identd:{
  if ($sock(antispam.identdin) != $null) { sockclose antispam.identdin }
  sockaccept antispam.identdin
  asecho $colour(other) * Identd request from $sock($sockname).ip
  sockclose antispam.identd
  unset %antispam.identd

}
on *:sockread:antispam.identdin:{
  if ($sockerr) { return }
  var %temp
  sockread %temp
  if (!%temp) { return }
  tokenize 32 %temp
  sockwrite -n $sockname $1 $+ , $3 : USERID : UNIX : $asnickname($asini(personalize,ident))
  asecho $colour(other) * Identd replied: $1 $+ , $3 : USERID : UNIX : $asnickname($asini(personalize,ident))
  sockclose antispam.identdin
}


; queue code from wshs
alias -l as.queue {
  if ($hget(as.queue) == $null) { hmake as.queue }

  ; code to prevent re-queuing of the same commands
  var %max = $hget(as.queue,0).item
  var %index = 0
  while (%index < %max) {
    inc %index
    if ($hget(as.queue,$hget(as.queue,%index).item) == $1-) { 
      return 0
    }
  }

  as.hinc as.queue max
  var %antispam.qx = a $+ $hget(as.queue,max)
  hadd as.queue %antispam.qx $1-
  if ($timer(as.queue) == $null) { .timeras.queue 0 1 as.sendqueue }
  return 1
}
alias -l as.hinc { if ($hget($1)) { hadd $1 $2 $calc($hget($1,$2) + $iif($3 isnum,$3,1)) } }
alias -l as.hdec { if ($hget($1)) { hadd $1 $2 $calc($hget($1,$2) - $iif($3 isnum,$3,1)) } }
alias -l as.sendqueue {
  if ($hget(as.queue,a1) == $null) || ($hget(as.queue,max) <= 0) { .timeras.queue off | return }
  sockwrite -n antispam $hget(as.queue,a1)
  var %antispam.start = 2
  var %antispam.end = $hget(as.queue,max)
  while (%antispam.start <= %antispam.end) {
    var %antispam.cur = a $+ $calc(%antispam.start - 1)
    var %antispam.las = a $+ %antispam.start
    if ($hget(as.queue,%antispam.las)) hadd as.queue %antispam.cur $hget(as.queue,%antispam.las)
    inc %antispam.start
  }
  var %antispam.las = a $+ $hget(as.queue,max)
  hdel as.queue %antispam.las
  hadd as.queue max $calc($hget(as.queue,max) - 1)
}
alias -l as.clearqueue {
  if (!$hget(as.queue)) { hmake as.queue }
  var %antispam.bleh = $hmatch(as.queue,a*,0)
  hfree as.queue
  hmake as.queue
  hadd as.queue max 0
  return %antispam.bleh
}

alias -l as.settings {
  if ($dialog(antispam) == $null) {
    set %antispam.set.web $askickmsg([webad])
    set %antispam.set.inv $askickmsg([invite])
    set %antispam.set.net $askickmsg([netad])
    set %antispam.set.bd $askickmsg([hack])
    set %antispam.set.vrs $askickmsg([virus])
    set %antispam.set.greet $askickmsg([greet])
    dialog -m antispam antispam
  }  
}
;antispambot end
;trivia start
alias trivia.version { return 3.21 }
;########################################################
;# Direct IRC interactions.                             #
;########################################################
on *:START: { init }
on *:LOAD: {
  var %v = 6.01
  if ($version < %v) {
    echo Please use mIRC %v or later.
    if ($input(Not using mirc %v or later, would you like to use the script anyway?,8,Override?)) { init.load }
    else { unload -rs $script }
  }
  else { init.load }
}
on *:INVITE:*: { if ($trivchan) { join $chan } }
on *:JOIN:*: {
  inc -u5 %trivia.netsplit
  if ((%trivia.netsplit >= 3) || (!$trivchan) || (!$getset(status,bot))) { return }
  if ($nick != $me) { if ($getset(status,onjoin)) { inform $msg.trivia.onjoin } }
  elseif ($getset(status,autostart) == 1) { trivia }
  award join $nick
}
on *:INPUT:#: {
  if ((!$trivchan) || (/* iswm $1-)) { return }
  if ($pre $+ * iswm $1-) { processcommand $1- }
  elseif ($question.on) { processguess $1- }
}
on *:ctcpreply:ping*:{ if (% [ $+ ping. [ $+ [ $nick ] ] ] ) { tsay $msg.ping.reply } }
on *:TEXT:*:#:{
  if (($pre $+ * iswm $1-) && ($trivchan)) { processcommand $1- } 
  if (($trivchan) && ($question.on) && ($left($1,1) != /)) { processguess $1- }
}
on *:TEXT:*:?: { if (($pre $+ report* iswm $1-) || ($pre $+ add* iswm $1-)) { processcommand $1- } }
;########################################################
;# Related checks.                                      #
;########################################################
alias tscid { if (($version >= 6) && ($tchan($trivchan,2) != 0) && ($scid($tchan($trivchan,2)) isnum)) { scid $tchan($trivchan,2) } }
alias trivchan {
  var %i = 1, %chan = $tchan(%i)
  while (%chan) {
    if ((((%chan == $iden) && (($version < 6) || (($tchan(%i,2) != 0) && ($ifd($scid($tchan(%i,2)),$cid) == $cid)))) && ((($1 == op) && ($iif($2,$2,$nick) isop %chan)) || ($1 != op))))  { return %i }
    inc %i
    var %chan = $tchan(%i)
  }
}
alias tchan { return $ifd($gettok($getset(chan, $1), $ifd($2,1), 59),$null) }
alias tchan.noqs { setset chan $1 $gettok($getset(chan, $1),1-4,59) }
alias tchan.set {
  if ($3- != $null) {
    var %nl = $getset(chan,$1)
    if (!%nl) { %nl = $1 $+ ;0;0; $+ $scoresfil $+ ; $+ questions.txt }
    if ($2 > $numtok(%nl,59)) %nl = %nl $+ $str(;0,$calc($2 - $numtok(%nl,59)))
    %nl = $puttok(%nl,$3-,$2,59)
    setset chan $1 %nl
  }
}
;########################################################
;# Menubar and submenu functions.                       #
;########################################################
menu channel,menubar {
  Trivia
  .Trivia Options:{ if (!$dialog(trivset)) { dialog -m trivset trivset } }
  .Start Trivia
  ..Standard:{ $trivia }
  ..Unlimited Game:{ $trivia(unlimited) }
  ..Team Game:{ $trivia(team) }
  ..Theme Game
  ...$submenu($theme.submenu($1))
  ..Specify round:{ $trivia($$?="How many question in the trivia round?") }
  .Stop Trivia:{ strivia }
  .Set Channel:{ chan.add $$chan }
  .Set CID:{ setset trivia cid $cid }
  .-
  .Features
  ..Build Scores HTML:{ htmlbuild }
  ..HTML Options:{  if (!$dialog(trivbuild)) { dialog -m trivbuild trivbuild } }
  ..Themes Setup: {  if (!$dialog(triviatheme)) { dialog -m triviatheme triviatheme } }
  ..$iif($getset(trivia,ranks),Ranks Setup): {  if (!$dialog(trivrank)) { dialog -m trivrank trivrank } }
}
alias theme.submenu {
  if (($1 == begin) || ($1 == end)) return -
  return $getset(triviamode $+ $1, name) $+ : /trivia $getset(triviamode $+ $1, name)
}
menu menubar {
  Trivia
  .Force Question:{ ask }
  .Scores
  ..Scores:{ if (!$dialog(triviascores)) { dialog -m triviascores triviascores } }
  ..Give Points: { trivia.credit $$?="Credit whom?" $$?="How many points do you wish to give, -# to remove score" }
  .Echo
  ..Records:{ tsay $msg.trivia.records }
  ..HoF:{ tsay $msg.trivia.hof }
  ..Repeat:{ tsay $msg.question.current }
  ..Hint:{ tsay $msg.hint.hint }
  .Open
  ..Additions:{ if $exists(" $+ $triv(dir) $+ / $+ $triv(additions) $+ ") { run " $+ $triv(dir) $+ / $+ $triv(additions) $+ " } }
  ..Report:{ if $exists(" $+ $triv(dir) $+ / $+ $triv(report) $+ ") { run " $+ $triv(dir) $+ / $+ $triv(report) $+ " } }
  .-
  .Trivia [ $trivon ] $+ :{ setset status bot $iif($getset(status,bot) == 1,0,1) }
  .-
  .Trivia Unload:{ if ($?!="Really Unload?") { unload -rs $script } }
}
menu nicklist {
  Trivia
  .Control
  ..Ban:{ tban $$1 }
  ..Unban:{ tunban $$1 }
  .Add as Friend: { triviafriend.add $address($$1,7) }
  .Credit
  ..Award
  ...1: { trivia.credit $$1 1 }
  ...5: { trivia.credit $$1 5 }
  ...10: { trivia.credit $$1 10 }
  ..Deduct
  ...1: { trivia.credit $$1 -1 }
  ...5: { trivia.credit $$1 -5 }
  ...10: { trivia.credit $$1 -10 }
  ..Input Amount: { trivia.credit $$1 $$?="How many points do you wish to give, -# to remove score" }
}
;########################################################
;# Menubar related, aliases.                            #
;########################################################
alias trivia.credit {
  if ($2 isnum) {
    setvar $1 Score $calc($getvar($1,Score) + $2)
    if ($2 > 0) { tsay $msg.trivia.awarded($1,$2) }
    else { tsay $msg.trivia.deducted($1,$2) }
  }
}
alias -l trivon { return $iif($getset(status,bot), $iif($trivia.paused,Paused,Enabled), Disabled) }
alias -l trivia.chan { return $iif($tchan(1) ischan, Yes, No) }
alias -l trivia.dir { return $iif($isdir(" $+ $triv(dir) $+ "), Yes, No) }
alias -l trivia.file { return $iif($isfile($qfile(1)), Yes, No) }
alias -l trivia.onoff { return $iif($trivia.on, On, Off) }
alias -l team.onoff { return $iif($team, On, Off) }
;########################################################
;# Color aliases.                                       #
;########################################################
alias -l colorcode { return $gettok(default.white.black.blue.green.lightred.brown.purple.orange.yellow.lightgreen.cyan.lightcyan.lightblue.pink.grey.lightgrey,$calc($1 + 1),$asc(.)) }
alias -l fixer { return $base($1,10,10,2) }
alias varcolors {
  unset %c1 %c1o %c2 %c2o
  if (!$getset(color,on)) { return }
  %c1o = $iif($tc(1).b,$chr(2)) $+ $iif($tc(1).u,$chr(31)) $+ $chr(3)
  %c2o = $iif($tc(2).b,$chr(2)) $+ $iif($tc(2).u,$chr(31)) $+ $chr(3)
  %c1 = %c1o $+ $iif($tc(1), $fixer($calc($tc(1) - 1))) $+ $iif(($tc(3)) && ($getset(color,bon)), $chr(44) $+ $fixer($calc($tc(3) - 1)))
  %c2 = %c2o $+ $iif($tc(2), $fixer($calc($tc(2) - 1))) $+ $iif(($tc(4)) && ($getset(color,bon)), $chr(44) $+ $fixer($calc($tc(4) - 1)))
}
alias rdc {  
  var %a
  !.echo -q $regsub($1,/(?<=\x03|\x03\d\d\x2C)(\d)(?!\d)/g,0\1, %a)
  while ($regsub(%a, /(?<=\x03\d\d\x2C\d\d|\x03\d\d\x03|\x03)([\x02\x1F\x16\s]+)(\x03(?:\d\d(?:\x2C\d\d)?)?)/g,\2\1, %a)) { }
  !.echo -q $regsub(%a, /(\x02)([\x1F\x16\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(\x1F)([\x02\x16\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(\x16)([\x02\x1F\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(?:\x03(?:\d\d(?:\x2C\d\d)?)?)+(\x03(?:(?!\d)|\d\d\x2C\d\d))/g,\1, %a) $&
    $regsub(%a, /(?:\x03\d\d)(\x2C\d\d)(?:\x03\d\d)*(\x03\d\d)/g,\2\1, %a) $&
    $regsub(%a, /(?<=\x03\d\d)(\x2C\d\d)([^\x03]+\x03\d\d)\1/g,\1\2, %a)
  while ($regsub(%a,/(\x03\d\d)((\x2C\d\d)?[^\x03]+)\1/g,\1\2, %a)) { }
  !.echo -q $regsub(%a, /^\x03(?!\d)|(\x03(\d\d(\x2C\d\d)?)?|\x02|\x16|\x1F)+$/g,,%a) $&
    $regsub(%a, /(?<=\x03|\x03\d\d\x2C)0(\d)(?!\d)/g,\1, %a)
  return %a
}
;########################################################
;# Init aliases.                                        #
;########################################################
alias -l nset { if ($getset($1, $2) == $null) { setset $1- } }
alias -l init.load {
  convertscores
  convertscores $tempini
  nset award 1 1 1 1 50 0  gives * a high five for getting ^ wins! Way to go * !
  nset award 2 1 1 1 100 0 gives * a large pizza for getting ^ wins! Way to go * !
  nset award 3 1 1 1 150 0 ^ wins... I am not worthy...
  nset award 4 2 1 1 3 0 hands * a cold beer for getting the last ^ questions!
  nset award 5 2 1 1 5 0 hands * 6-pack of icy beers for getting the last ^ questions!
  nset award 6 2 1 1 10 0 gives * keg of beer for kicking everybodies asses! ^ questions!
  nset award 7 2 1 1 15 0 bows before * a trivia god...
  nset award 8 2 2 2 3 5 You're on fire!
  nset award 9 3 4 5 1.5 0 Autoban based on speed.
  nset award 10 4 3 5 120 0 Autoban based on Words per minute.
}
alias -l init {
  nset status bot 1 | nset status echo 0 | nset status autohint 1 | nset status showanswer 1 | nset status cross 1
  nset status number 30 | nset status hintpause 1 | nset trivia additions additions.txt | nset trivia channel #temptrivia 
  nset color 1 $fixer($rand(1,15)) | nset color 2 $fixer($rand(1,15)) | nset trivia default 10 | nset trivia dteam 5 | nset color on 1
  nset trivia delimiter * | nset trivia tnaoff 5 | nset trivia hintpause 5 | nset trivia perchint 30 | nset trivia numhint 1
  nset trivia ppq 1 | nset trivia dph 0 | nset lag answered 10 | nset lag hint 10 | nset lag start 15 | nset lag timed 15
  nset lag timedout 60 | nset lag hintallow 10 | nset trivia questions questions.txt | nset trivia dir $nofile($findfile($mircdir,$triv(questions), 1))
  nset trivia report report.txt | nset trivia reset 1000 | nset team 0victory The *t1 and the *t2 tied | nset team 1 'Team 1's
  nset team 1victory The *t1 beat the *t2 | nset team 2 'Team 2's | nset team 2victory The *t2 beat the *t1 | nset team JoinBefore 2
  nset team JoinBeforeOn 1
  varcolors
}
alias -l trivia.fail {
  if ($version < 5.91) { return Please use mIRC 5.91 or later. }
  if (!$server) { return Please connect to a server before attempting to use $msg.trivia.version }
  if ($getset(status,bot) == 0) { return The trivia bot is off. Commands, Trivia, Disabled to reenable. }
  if ($tchan(1) !ischan) { return You are not in the set trivia channel: $tchan(1) }
  if ($isdir(" $+ $triv(dir) $+ ") == $false) { return The trivia directory, $triv(dir) $+ , is invalid. }
  if (!$numl) { return There appear to be no questions within the question file(s). }
}
alias get.find { if ($qread($1-)) return $qread($1-) - $readn }
;########################################################
;# Trivia command, related aliases.                     #
;########################################################
alias -l ifd { return $iif($1, $1, $2) }
;########################################################
;# Command processing.                                  #
;########################################################
alias pre { return $ifd(%command-prefix, !) }
alias commandtokens { return state;disable;enable;op;trivia;strivia;pause;resume;theme;themes;stats;stat;won;hof;top10;hofstreak;row;streak;hoffast;fast;hofwpm;wpm;server;record;records;champ;version;web;add;report;ping;triviaping;help;join;showteams;roundscores;answer;next;hint;!hint;words;last;vowels;repeat }
alias ctok { return $findtok($commandtokens,$1,1,59) }
alias gtok { return $gettok($commandtokens,$1,59) }
alias -l processcommand {
  var %ctok = $ctok($right($1,-1))
  if (!%ctok) { return }
  set -u0 %ident $chan
  if (%ctok == 1) { inform $msg.trivia.state }
  if (%ctok == 2) { opcommand disable } 
  if (%ctok == 3) { opcommand enable }
  if (%ctok == 4) { opcommand $2- }
  if (($getset(status,bot) == 0) || ($trivia.banned)) { return }
  if (%ctok == 5) { if ($trivia.allowed(on)) { trivia $2- } }
  if (%ctok == 6) { if (($trivia.allowed(off)) && ($trivia.on) && ((!$team) || ($nick isop $iden))) { strivia $iden } }
  if (%ctok == 8) { if (($trivia.paused) && (!$isdis(31))) { trivia.pause 1 } }
  if (%ctok == 7) { if ((!$trivia.paused) && (!$isdis(31))) { trivia.pause } }
  if (%ctok isnum 9-10) { if (!$isdis(5)) { inform $msg.trivia.themes } }
  if (%ctok isnum 11-13) { processcommand.stats $2 }
  if (%ctok isnum 14-15) { if (!$isdis(7)) { inform $msg.trivia.hof } }
  if (%ctok isnum 16-18) { if (!$isdis(8)) { inform $msg.trivia.ten(streak) } }
  if (%ctok isnum 19-20) { if (!$isdis(9)) { inform $msg.trivia.ten(time) } }
  if (%ctok isnum 21-22) { if (!$isdis(10)) { inform $msg.trivia.ten(wpm) } }
  if (%ctok == 23) { inform $server }
  if (%ctok isnum 24-25) { if (!$isdis(15)) { inform $msg.trivia.records } }
  if (%ctok == 26) { inform $msg.trivia.champ }
  if (%ctok == 27) { inform $msg.trivia.version }
  if (%ctok == 28) { inform $msg.trivia.web }
  if (%ctok isnum 29-30) { if (!$isdis(18)) { trivia.report $1- } }
  if (%ctok isnum 31-32) { if (!$isdis(6))  { do.ping } }
  if (%ctok == 33) { givehelp $2- }
  if (%ctok == 34) { if ($team) { $setteam($nick, $2) } }
  if (%ctok == 35) { if ($team) { inform $msg.trivia.showteams } }
  if (%ctok == 36) { inform $msg.trivia.roundscores }
  if (%ctok == 37) { if (($nick isop $chan) && (!$isdis(20))) { inform $msg.question.answer } }
  if ((!$question.on) || ($trivia.paused)) { return }
  if (%ctok == 38) { if (($calc($question.time * 2) >= $lag(timedout)) && (!$isdis(2))) { trivx } }
  if (%ctok isnum 39-43) { 
    if (($question.time >= $lag(hintallow))) {
      if (($getset(trivia, hintpause)) && ($getset(status, hintpause))) { hadd -u $+ $triv(hintpause) Trivia $+ $iden $eval(hinted. $+ $nick,1) 1 }
      if (%ctok isnum 39-40) { if (!$isdis(1)) { give.hint $iden } }
      if (%ctok == 41) { if (!$isdis(21)) { $iif($getset(status,msghint), tsay, inform) $msg.hint.words } }
      if (%ctok == 42) { if (!$isdis(22)) { $iif($getset(status,msghint), tsay, inform) $msg.hint.last } }
      if (%ctok == 43) { if (!$isdis(23)) { $iif($getset(status,msghint), tsay, inform) $msg.hint.vowels } }
    }
  }
  if (%ctok == 44) { if (!$isdis(3)) { inform $$thget(trivq.say) } }
}
alias -l trivia.allowed {
  if (!$getset(status,oponly $+ $$1)) { return $true }
  var %level = $getset(trivia, $1 $+ level)
  if (%level == 5) { return }
  if (($nick isop $chan) && (%level < 4))  { return $true }
  if (($nick ishelp $chan) && (%level < 3)) { return $true }
  if (($nick isvoice $chan) && (%level < 2))  { return $true }
  if (($nick ison $chan) && (%level < 1))  { return $true }
}
;########################################################
;# Help structure.                                      #
;########################################################
alias -l givehelp {
  if (!$1-) {
    inform $e2(Commands:) $e1($pre $+ $gtok(6) $pre $+ $gtok(5) $pre $+ $gtok(39) $pre $+ $gtok(34) $pre $+ $gtok(29) $pre $+ $gtok(30) $pre $+ $gtok(31) $pre $+ $gtok(27) $pre $+ $gtok(28) $pre $+ $gtok(14) $pre $+ $gtok(19) $pre $+ $gtok(16) $pre $+ $gtok(21) $pre $+ $gtok(25) $pre $+ $gtok(38) $pre $+ $gtok(23) $pre $+ $gtok(26) $pre $+ $gtok(44) $pre $+ $gtok(37) $pre $+ $gtok(11) $pre $+ $gtok(1) $pre $+ $gtok(3) $pre $+ $gtok(2) $pre $+ $gtok(10) $pre $+ $gtok(41) $pre $+ $gtok(42) $pre $+ $gtok(43) $pre $+ $gtok(35) $pre $+ $gtok(36) $pre $+ $gtok(4) $pre $+ $gtok(7) $pre $+ $gtok(8))
    inform $e1($pre $+ help <command>) $e2(for specific help. Some commands may be disabled.)
  }
  if ($1 == $pre $+ $gtok(1)) { inform $e1($1 -----) $e2(Displays the state of the bot) }
  if ($1 == $pre $+ $gtok(6)) { inform $e1($1 ---) $e2(Stops trivia) }
  if ($1 == $pre $+ $gtok(3)) { inform $e1($1 ----) $e2(Enables trivia bot) }
  if ($1 == $pre $+ $gtok(2)) { inform $e1($1 ---) $e2(Disables trivia bot) }
  if ($1 == $pre $+ $gtok(7)) { inform $e1($1 ----) $e2(Pauses trivia bot) }
  if ($1 == $pre $+ $gtok(8)) { inform $e1($1 ----) $e2(Resumes trivia bot) }
  if ($1 == $pre $+ $gtok(4)) { inform $e1($1 <command> -) $e1(enable) $+ $e2($chr(44)) $e1(disable) $+ $e2($chr(44)) $e1(ban) $+ $e2($chr(44)) $e1(unban) $+ $e2($chr(44)) $e1(banned) $+ $e2($chr(44)) $e1(add) $+ $e2($chr(44)) $e1(ask) $+ $e2($chr(44)) $e1(find) $+ $e2($chr(44) commands to allow ops to control the trivia bot.) }
  if ($1 == $pre $+ $gtok(5)) { inform $e1($1 x --) $e2(Starts trivia, x can be a number, "unlimited" or "team" for team mode) }
  if ($1 == $pre $+ $gtok(39)) { inform $e1($1 ------) $e2(Gives a hint) }
  if ($1 == $pre $+ $gtok(42)) { inform $e1($1 ------) $e2(Gives the last character of the answer) }
  if ($1 == $pre $+ $gtok(41)) { inform $e1($1 ------) $e2(Gives the number of words in the answer) }
  if ($1 == $pre $+ $gtok(43)) { inform $e1($1 ------) $e2(Gives the vowels of the answer) }
  if ($1 == $pre $+ $gtok(34)) { inform $e1($1 x ----) $e2(Joins a team, must be in team mode, x can be a 1 or 2) }
  if ($1 == $pre $+ $gtok(29)) { inform $e1($1 -------) $e2(Allows you to add questions: $pre $+ add What is the square root of 4*two*2) }
  if ($1 == $pre $+ $gtok(30)) { inform $e1($1 ----) $e2(Lets you report problems with the questions: $pre $+ report The square root of 4 is also -2) }
  if ($1 == $pre $+ $gtok(31)) { inform $e1($1 -----) $e2(Checks your lag from the bot) }
  if ($1 == $pre $+ $gtok(27)) { inform $e1($1 ---) $e2(Displays the version of the bot) }
  if ($1 == $pre $+ $gtok(28)) { inform $e1($1 -------) $e2(Displays the web page for the bot) }
  if ($1 == $pre $+ $gtok(14)) { inform $e1($1 -------) $e2(Displays the hall of fame) }
  if ($1 == $pre $+ $gtok(19)) { inform $e1($1 ---) $e2(Displays the record times) }
  if ($1 == $pre $+ $gtok(16)) { inform $e1($1 --) $e2(Displays the record streaks) }
  if ($1 == $pre $+ $gtok(21)) { inform $e1($1 ----) $e2(Displays the record words per minute) }
  if ($1 == $pre $+ $gtok(25)) { inform $e1($1 ---) $e2(Displays the record row & streak & wpm) }
  if ($1 == $pre $+ $gtok(23)) { inform $e1($1 ----) $e2(Displays the bot's server) }
  if ($1 == $pre $+ $gtok(26)) { inform $e1($1 -----) $e2(Displays the champ stats) }
  if ($1 == $pre $+ $gtok(36)) { inform $e1($1) $e2(Displays the scores for the current round.) }
  if ($1 == $pre $+ $gtok(35)) { inform $e1($1) $e2(Displays the teams and which players are on each.) }
  if ($1 == $pre $+ $gtok(44)) { inform $e1($1 ----) $e2(Repeats the question) }
  if ($1 == $pre $+ $gtok(37)) { inform $e1($1 ----) $e2(Provides the answer to the last question to an op who requests it) }
  if ($1 == $pre $+ $gtok(38)) { inform $e1($1 ----) $e2(After half the time to answer has expired allows an instant timeout.) }
  if ($1 == $pre $+ $gtok(10)) { inform $e1($1 ----) $e2(Lists available themes) }
  if ($1 == $pre $+ $gtok(11)) { inform $e1($1 ------) $e2(Returns your current stats, or $pre $+ stats (name) for somebody else) }
}
;########################################################
;# !Op command structure.                               #
;########################################################
alias -l opcommand {
  if ($isdis(24)) { return }
  if ((!$trivchan(op)) && ($nick != $me) && (!$istrivia.friend)) { return }
  if (($1 == enable) && (!$isdis(4)) && ($getset(status,bot) == 0)) { 
    setset status bot 1
    tsay $msg.trivia.enabled
  }
  if (($1 == disable) && (!$isdis(4)) && ($getset(status,bot) == 1)) {
    setset status bot 0
    tsay $msg.trivia.disabled
    strivia
  }
  if (($1 == ban) && (!$isdis(25))) {
    if (!$2) { inform $e1(You need to specify a user to ban) }
    else {
      tban $2
      inform $e1(User is banned.)
    }
  }
  if (($1 == unban) && (!$isdis(26))) {
    if (!$2) { inform $e1(You need to specify a user to unban) }
    else {
      tunban $2
      inform $e1(User is unbanned.)
    }
  }
  if ($1 == banned) { inform $msg.trivia.banlist }
  if (($1 == ask) && (!$isdis(27))) {
    if ((!$2) || (!$isvalidask($2))) { inform $e1(You need to specify a valid question number to be asked.) }
    else {
      ask $2
      inform $e1(Question will be asked.)
    }
  }
  if (($1 == add) && (!$isdis(28))) {
    if (!$2) { inform $e1(You need append the question that is to be added directly into the question file.) }
    elseif ($triv(delimiter) !isin $2-) { inform $e1(You need at least one delimiter to indicate: question $+ $triv(delimiter) $+ answer) }
    else { 
      add $2-
      inform $e1(Question has been added.)
    }
  }
  if (($1 == find) && (!$isdis(29))) {
    if (!$2) { inform $e1(You need at least some search text.) }
    inform $e1($ifd($get.find($2-),That text was not found.))
  }
}
;########################################################
;# Trivia ON.                                           #
;########################################################
alias trivia {
  tscid
  if (($trivia.banned) || ($trivia.on) || (!$trivchan)) { return }
  if ($trivia.paused) { 
    tsay $msg.trivia.pause
    return
  }
  trivia.flush
  if ($trivia.fail) {
    echo $trivia.fail
    return
  }
  if ($hget(Trivia $+ $iden)) { hfree Trivia $+ $iden }
  hmake Trivia $+ $iden 20
  if ($hget(Asked $+ $iden)) { hfree Asked $+ $iden }
  hmake Asked $+ $iden 50
  trivia.defaultgame
  thset STime $time $date
  thset SUser $iif($nick,$nick,$me)
  if (($getset(Trivia,odefault) == unlimited) || (($1 == unlimited) && (!$isdis(12))) ) { thset Max Unlimited }
  if (($getset(trivia,odefault) == team) || (($1 == team) && (!$isdis(11)))) { thset team 1 }
  if (($1 isnum 0 - $numl) && (!$isdis(13))) { thset Max $int($1) }
  if ($1 == pi) { thset Max 3.14159265358979323846 }
  if (!$isdis(16)) { trivia.themecheck $1- }
  if ($thget(team)) { trivia.teammode $2 }
  tsay $msg.trivia.started
  .timerq $+ $iden 1 $lag(start) trivq $chan
}
;########################################################
;# Trivia OFF.                                          #
;########################################################
alias strivia {
  tscid
  set -u0 %ident $1
  if ($team) { strivia.teammode }
  else {
    tsay $msg.trivia.stopped
    if ($thget(Current) >= 10) { tsay $strivia.end($triv(Record)) }
  }
  trivia.flush
}
alias strivia.end {
  if ($1 == 1) { return $msg.trivia.hof }
  elseif ($1 == 2) { return $msg.trivia.ten(streak) }
  elseif ($1 == 3) { return $msg.trivia.ten(time) }
  elseif ($1 == 4) { return $msg.trivia.ten(wpm) }
  elseif ($1 == 5) { return $msg.trivia.champ }
  elseif ($1 == 6) { return $msg.trivia.web }
  elseif ($1 == 7) { return $msg.trivia.roundscores }
  return $msg.trivia.records
}
;########################################################
;# STATUS CLEARING.                                     #
;########################################################
alias -l trivia.flush {
  if ($hget(Asked $+ $iden)) { hfree Asked $+ $iden }
  if ($hget(Trivia $+ $iden)) { hfree Trivia $+ $iden }
  trivia.timersoff
}
alias -l trivia.timersoff {
  .timer* $+ $iden off
}
;########################################################
;# DEFAULT setup.                                       #
;########################################################
alias trivia.defaultgame {
  thset File questions.txt
  thset Scores $scoresfil
  if ($tchan($trivchan, 4)) { thset Scores $tchan($trivchan, 4) }
  if ($tchan($trivchan, 5)) {
    thset File
    var %i = 5
    while ($tchan($trivchan, %i)) {
      thset File $thget(file) $+ ; $+ $tchan($trivchan, %i)
      inc %i
    }
  }
  thset Max $triv(default)
  thset PPQ $iif($getset(Trivia,PPQ) != $null,$getset(Trivia,PPQ),1)
  thset DPH $iif($getset(Trivia,DPH) != $null,$getset(Trivia,DPH),0)
  thset RRS $iif($getset(Status,RRS) != $null,$getset(Status,RRS),0)
  thset guess $iif($getset(status,oneguess) != $null,$getset(status,oneguess),0)
  thset lagstart $iif($getset(lag, start) != $null, $getset(lag, start), 0)
  thset laganswered $iif($getset(lag, answered) != $null, $getset(lag, answered), 0)
  thset lagtimedout $iif($getset(lag, timedout) != $null, $getset(lag, timedout), 0)
  thset laghint $iif($getset(lag, hint) != $null, $getset(lag, hint), 0)
  thset lagtimed $iif($getset(lag, timed) != $null, $getset(lag, timed), 0)
  thset laghintallow $iif($getset(lag, hintallow) != $null, $getset(lag, hintallow), 0)
}
;########################################################
;# THEMED start.                                        #
;########################################################
alias trivia.themecheck {
  var %i = 1
  while ($getset(triviamode $+ %i, Name)) {
    if ($1 == $getset(triviamode $+ %i, Name)) {
      var %j = $setini(triviamode $+ %i,0)
      while (%j >= 1) {
        var %mode = $setini(triviamode $+ %i, %j)
        thset %mode $getset(triviamode $+ %i, %mode)
        dec %j
      }
      thset File $getset(triviamode $+ %i, file)
      if (($2 isnum) && ($2 <= $numq) && ($2 > 0) && (!$isdis(13))) { thset Max $int($2) }
      return
    }
    inc %i
  }
}
;########################################################
;# TEAM setup.                                          #
;########################################################
alias -l trivia.teammode {
  thset Score1 0
  thset Score2 0
  thset Score3 0
  thset Score4 0
  if ($1 isnum 1 - $numq) { thset Max $int($1) }
  else { thset Max $triv(dteam) }
  tsay $msg.team.start
}
alias -l strivia.teammode {
  var %s1 = $thget(Score1)
  var %s2 = $thget(Score2)
  var %s3 = $thget(Score3)
  var %s4 = $thget(Score4)
  if ($getset(team,4-team)) {
    if ((%s1 > %s2) && (%s1 > %s3) && (%s1 > %s3)) { tsay $msg.team.over($te(1).victory) }
    elseif ((%s2 > %s1) && (%s2 > %s3) && (%s2 > %s4)) { tsay $msg.team.over($te(2).victory) }
    elseif ((%s3 > %s1) && (%s3 > %s2) && (%s3 > %s4)) { tsay $msg.team.over($te(3).victory) }
    elseif ((%s4 > %s1) && (%s4 > %s2) && (%s4 > %s3)) { tsay $msg.team.over($te(4).victory) }
    else { tsay $msg.team.over($te(0).victory) }
  }
  else {
    if (%s1 > %s2) { tsay $msg.team.over($te(1).victory) }
    elseif (%s1 < %s2) { tsay $msg.team.over($te(2).victory) }
    else { tsay $msg.team.over($te(0).victory) }
  }
  if ($getset(status, noshowt)) { tsay $msg.trivia.showteams }
}
alias -l setteam {
  if (($thget(Current) >= $getset(Team, JoinBefore)) && ($getset(Team, JoinBeforeOn) == 1)) { 
    inform $msg.team.joinover
    return 
  }
  if ($2 isnum 1 - 4) {
    if ($thget(Team. $+ $nick) == $2) { inform $msg.team.alreadyon }
    else { tsay $msg.team.add($getset(team,$2), $nick) }
    thset $eval(Team. $+ $nick,1) $2
  }
}
;########################################################
;# Trivia QUESTION.                                     #
;########################################################
alias isvalidask { if ($1 isnum 1 - $numq) { return $true } }
alias trivq {
  tscid
  set -u0 %ident $1
  if (!$hget(Trivia $+ $iden)) { return }
  if ($trivia.fail) {
    echo $trivia.fail
    return
  }
  thset Current $calc($thget(Current) + 1)
  if (($team) && ($thget(Current) == $getset(Team, JoinBefore)) && ($getset(Team, JoinBeforeOn) == 1)) { tsay $msg.team.joinbefore }
  create.question
  .timerend $+ $iden 1 $lag(timedout) trivx $1
  trivia.startautohint
  setset Var Asked $calc($getset(Var,Asked) + 1)
  thset Start $ticks
  trivia.sayquestion $right($thget(catq),-1)
  if ($getset(status,echo) == 1) { echo $iden $e2(Answer:) $e1($trivq.answer) }
  if ($getset(status,answers)) { tsay $msg.hint.answerspace }
}
alias -l create.question {
  if ($thget(ask1)) {
    while ((!$isvalidask($thget(Ask1))) && ($thget(ask1) isnum)) { ask.deleteitem 1 }
    if ($thget(Ask1)) {
      if ($thget(Ask1) !isnum) { thset Trivq $thget(Ask1) }
      else { thset Trivq $qread($thget(ask1)) }
      ask.deleteitem 1
      return
    }
  }
  var %temp.ask = $trivia.getq
  thset Catq $qcat(%temp.ask)
  thset Trivq $qread(%temp.ask)
  hadd Asked $+ $iden %temp.ask %temp.ask
}
alias -l trivia.getq {
  unset %ask
  while ((!%ask) || ($hget(Asked $+ $iden, %ask))) {
    if ($hget(Asked $+ $iden,0).item >= $numq) { hdel -w Asked $+ $iden * }
    var %ask = $rand(1, $numq)
    if (!$gettok($qread(%ask), 2,$asc($triv(delimiter)))) { hadd Asked $+ $iden %ask NA }
  }
  return %ask
}
alias -l ask.deleteitem {
  hdel Trivia $+ $iden Ask $+ $$1
  var %i = $1
  while ($thget(Ask $+ $calc(%i + 1))) {
    thset Ask $+ %i $thget(Ask $+ $calc(%i + 1))
    inc %i
  }
  if ($thget(Ask $+ %i)) { hdel Trivia $+ $iden Ask $+ %i }
}
alias -l trivia.startautohint { if ($getset(status,autohint) == 1) { .timerhint $+ $iden $triv(numhint) $lag(hint) give.hint $iden } }
;########################################################
;#  QUESTION over.                                      #
;########################################################
alias trivx {
  tscid
  set -u0 %ident $1
  if (!$hget(Trivia $+ $iden)) { return }
  if (!$2) {
    if ($getset(status,showanswer)) { tsay $iif($thget(temp.type) == T, $msg.answer.timeout.total, $msg.answer.timeout) }
    else { tsay $msg.answer.timeout2 }
    setset Var Row 0
    thset Unanswered $calc($thget(Unanswered) + 1)
  }
  trivia.timersoff
  if ($window($total.win)) { window -c $total.win }
  thset Answer $trivq.answer
  hdel -w Trivia $+ $iden Temp.*
  if (($getvar($nick,score) >= $triv(reset)) && ($getset(status,champ) == 1)) { trivia.newchamp }
  if ((($team) && ($thget(Score $+ $isteam($nick)) > $calc($thget(Max)/2))) || (($getset(status, naoff) == 1) && ($thget(unanswered) >= $triv(naoff))) || (($thget(Max) != unlimited) && ($thget(Current) >= $thget(Max)))) {
    strivia $1
    if (($getset(status, naoff) == 1) && ($thget(Unanswered) >= $triv(naoff))) { tsay $msg.trivia.unactive }
    return
  }
  .timerq $+ $iden 1 $iif($1, $lag(answered), $lag(timed)) trivq $iden
}
alias -l trivia.processscore {
  if ($getset(Var, Lastwinner) == $nick) { setset Var Row $calc($getset(Var, Row) + 1) }
  else { setset Var Row 1 }
  setset Var Wins $calc($getset(Var,Wins) + 1)
  setset Var Lastwinner $nick
  setvar $nick Lastwin $date
  thset WPM $calc(($len($1-) * 60) / ($thget(Time) * 5))
  if (($thget(WPM) > $getvar($nick,wpm)) || (!$getvar($nick,wpm))) { setvar $nick wpm $thget(WPM) }
  if (($getset(Var, Row) > $getvar($nick,streak)) || (!$getvar($nick,streak))) { setvar $nick Streak $getset(Var, Row) }
  if (($thget(Time) < $getvar($nick,time)) || (!$getvar($nick,time))) { setvar $nick Time $thget(Time) }
  thset temp.cng $calc($thget(PPQ) - ($thget(DPH) * $max.hinted))
  if ($thget(temp.points)) { thset temp.cng $thget(temp.points) }
  thset temp.rank $getrank($nick,$thget(temp.cng))
  setvar $nick Score $calc($getvar($nick, Score) + $thget(temp.cng))
  thset $eval(Score. $+ $nick,1) $calc($thget($eval(Score. $+ $nick,1)) + $thget(temp.cng))
  if (($getset(build,instabuild)) && ($getset(build,auto)) && ($getset(build,instabuild) // $getset(Var,Wins))) { htmlbuild }
}
alias -l answered {
  tscid
  thset Time $question.time
  if (($1 == $null) || ($trivia.banned) || ($trivia.negationcheck) || (($team) && (!$isteam($nick)))) { return }
  trivia.processscore $1-
  if ($team) {
    thset Score $+ $isteam($nick) $calc($thget( Score $+ $isteam($nick)) + 1)
    tsay $msg.team.score
  }
  else { tsay $iif(!$getset(status, tradwin),$msg.answer.correct($thget(WPM),$thget(temp.rank)),$msg.answer.correct2($thget(WPM),$thget(temp.rank))) }
  if (%uprank) { tsay $msg.trivia.uprank($nick,$calc($thget(temp.rank) - %uprank)) }
  if ((%promotion) && ($getset(trivia,ranks))) { tsay $msg.ranks.promotion(%promotion) }
  if (!$isdis(19)) {
    if (%uprank) award uprank %uprank
    if (%promotion) award promotion %promotion
    award score $getvar($nick, Score)
    award row $getset(Var, Row)
    award time $thget(Time)
    award wpm $thget(WPM)
  }
  if ($thget(RRS)) { tsay $msg.trivia.roundscores }
  hdel Trivia $+ $iden Unanswered
  if (($thget(temp.type) != T) || ($total.over)) { trivx $chan $true }
}
alias -l trivq.answer { return $iif(((($thget(temp.type) == T) || ($getset(status,showmatched))) && ($thget(temp.matched))), $thget(temp.matched),$tok(2)) }
;########################################################
;# QUESTION Typing.                                     #
;########################################################
alias -l trivia.sayquestion {
  if ($regex($tok(1), /^(\d+):\s(.+)$/)) {
    thset temp.points $regml(1)
    var %tq $msg.question.points($regml(2))
  }
  elseif (($tok(1) == Scramble) || ($tok(1) == UWord)) { var %tq $msg.question.scramble($1-) }
  elseif (Multi: * iswm $tok(1)) {
    var %tq $msg.question.multi($1-)
    thset temp.type M
  }
  elseif (Total: * iswm $tok(1)) { 
    var %tq $msg.question.total($1-)
    thset temp.type T
    total.init
  }
  else { var %tq $msg.question.standard($1-) }
  thset trivq.say $e2($thget(Current) $+ .) %tq
  tsay $thget(trivq.say)
}
;########################################################
;# TOTAL question type, control.                        #
;########################################################
alias total.win { return @total $+ $iden }
alias total.init {
  var %i = 2
  if ($window($total.win)) { window -c $total.win }
  window -h $total.win
  while (%i <= $tokq) {
    aline -n $total.win $tok(%i)
    inc %i
  }
}
alias total.is { return $fline($total.win,$1-,1) }
alias total.rem { dline $total.win $total.is($1-) }
alias total.over { return $iif($line($total.win,0) == 0, 1) }
alias gettotalremain {
  var %i = 1, %totalremain
  while (%i <= $line($total.win,0)) { var %totalremain = %totalremain $line($total.win,%i), %i = $calc(%i + 1) }
  return %totalremain
}
;########################################################
;# Categories.                                          #
;########################################################
alias -l numcat {
  if ($window(@categories)) { window -c @categories }
  window -eh @categories
  var %j = 1
  while ($qfile(%j)) {
    if ($exists($qfile(%j))) filter -fw $qfile(%j) @categories #*
    inc %j
  }
  .timer 1 0 window -c @categories
  return $line(@categories,0)
}
;########################################################
;# Trivia BLOCKS.                                       #
;########################################################
alias -l trivia.negationcheck {
  if ($thuser(Hinted)) {
    inform $msg.trivia.hintpaused
    return $true
  }
  if (($thuser(Guess)) && ($thget(guess))) {
    inform $msg.trivia.guessed
    return $true
  }  
}
;########################################################
;# Guess processing.                                    #
;########################################################
alias -l processguess {
  if ($trivia.paused) { return }
  var %i 2, %max = $iif($thget(temp.type) == M, 2, $tokq)
  while (%i <= %max) {
    var %pattern = /((^|\s)( $+ $lower($fix($tok(%i))) $+ )($|\s))/
    if ($getset(status, nomid)) { %pattern = /(( $+ $lower($fix($tok(%i))) $+ )$|^( $+ $lower($fix($tok(%i))) $+ ))/ }
    if ($regex($lower($fix($1-)), %pattern)) {
      thset temp.matched $tok(%i)
      if ($thget(temp.type) == T) { 
        if (!$total.is($tok(%i))) { return }
        total.rem $tok(%i)
      }
      answered $tok(%i)
      if ($thget(temp.type) != T) { return }
    }
    inc %i
  }
  if (!$thuser(Guess)) { thset $eval(Temp.Guess. $+ $nick,1) $1- }
}
alias -l fix {
  var %temp.fix = $1-
  if ($isdis(17)) { return %temp.fix }
  if (the * iswm $1-) { %temp.fix = $right($1-,-3) }
  if (a * iswm $1-) { %temp.fix = $right($1-,-1) }
  var %temp.fix = $remove(%temp.fix,',-,!,`,.,’,´,?,%,$chr(36),$chr(44))
  var %temp.fix = $replace(%temp.fix,kn,n,y,i,k,c,x,c,q,c,e,a,u,o,ph,f,m,n,ll,l,aa,a,oo,o,cc,c,z,s)
  if ((*s iswm %temp.fix) || (*ah iswm %temp.fix)) { var %temp.fix = $left(%temp.fix, -1) }
  return %temp.fix
}
;########################################################
;# PAUSE/RESUME processing.                             #
;########################################################
alias trivia.pause {
  if ($1) {
    .timerq $+ $iden -r
    .timerend $+ $iden -r
    .timerhint $+ $iden -r
    thset paused 0
    tsay $msg.trivia.resume
  }
  else {
    .timerq $+ $iden -p
    .timerend $+ $iden -p
    .timerhint $+ $iden -p
    thset paused 1
    tsay $msg.trivia.pause
  }
}
;########################################################
;# Hint setup.                                          #
;########################################################
alias -l give.hint {
  set -u0 %ident $1
  if ((!$hget(Trivia $+ $iden)) || ($max.hinted >= $triv(numhint))) { return }
  if (!$nick) {
    thset Temp.Hints $calc($thget(Temp.Hints) + 1)
    tsay $msg.hint.hint($calc($triv(perchint) * $thget(Temp.Hints)))
  }
  else {
    thuset Hint $calc($thuser(hint) + 1)
    $iif($getset(status,msghint), tsay, inform) $msg.hint.hint($calc($triv(perchint) * $thuser(hint)))
  }
}
alias -l get.hint {
  if (($thget(temp.type) == T) || ($thget(Temp.type) == M)) { return }
  if (($thget(temp.rhint. $+ $2)) && ($1 == hint)) { return $thget(temp.rhint. $+ $2) }
  var %hint, %in = $replace($trivq.answer, $chr(32), $chr(160)),%perhint = $iif($2,$2,$triv(perchint)), %break = $int($calc(($len(%in) / 100) * %perhint + 1)), %hintc
  if ($1 == space) { return $replace($iif($regsub(%in, /([[:alnum:]])/g, $iif($chr($triv(ch)),$chr($triv(ch)),_), %hintc), %hintc), $chr(160), $chr(32)) }
  if ($1 == last) { return $right($trivq.answer,1) }
  if ($1 == vowels) { return $iif($regsub($trivq.answer, /([^aeiouAEIOU\s])/g, $iif($chr($triv(ch)),$chr($triv(ch)),_), %hintc), %hintc, $trivq.answer) }
  if ($getset(status, scatter)) { %hint = $replace($scatter(%perhint, $trivq.answer),@,$iif($chr($triv(ch)),$chr($triv(ch)),_)) }
  else { %hint = $replace($left(%in, %break) $+ $iif(($regsub($right(%in, $calc(-1 * %break)), /([[:alnum:]])/g, $iif($chr($triv(ch)),$chr($triv(ch)),_), %hintc)) && ($getset(status,cross) == 1), %hintc), $chr(160), $chr(32)) }
  if ($1 == hint) { thset temp.rhint. $+ $2 %hint }
  return %hint
}
alias -l scramble {
  tokenize 32 $1-
  var %i = 1, %temp.smbl
  while (%i <= $0) {
    var %word = $eval($+($,%i),2)
    while (%word) { var %rand = $rand(1, $len(%word)), %temp.smbl = %temp.smbl $+ $mid(%word, %rand, 1), %word = $left(%word, $calc(%rand - 1)) $+ $right(%word, $calc(-1 * %rand)) }
    %temp.smbl = %temp.smbl $+ ;
    inc %i
  }
  return $lower($replace(%temp.smbl,;,$chr(32)))
}
alias scatter {
  var %rnum = $int($calc(($regex($2-,/([[:alnum:]])/g) / 100) * (100 - $1))), %hintc = $2-, %i = 1,%k
  while (%i <= %rnum) {
    while ($mid(%hintc,%k,1) !isalnum) { %k = $rand(1,$len(%hintc)) }
    %hintc = $left(%hintc,$calc(%k - 1)) $+ @ $+ $right(%hintc,$calc(-1 * %k))
    inc %i
  }
  return %hintc
}
alias plot {
  var %hintc
  var %rnum = $int($calc(($regsub($2-,/[[:alnum:]]/g,@,%hintc) / 100) * $1))
  var %i = 1
  while (%i <= %rnum) {
    var %m = $regex($2-, /\S*(@)\S*/g)
    var %k = $regml($calc(((%i - 1) % %m) + 1)).pos
    while ($mid(%hintc,%k,1) != @) { inc %k }
    %hintc = $left(%hintc,$calc(%k - 1)) $+ $mid($2-,%k,1) $+ $right(%hintc,$calc(-1 * %k))
    inc %i
  }
  return %hintc
}
;########################################################
;# CHAMP aliases.                                       #
;########################################################
alias -l trivia.newchamp {
  .rename $scoresfil $asctime(yymmddhhmmss) $+ .bak
  setset Champ $calc($setini(Champ, 0) + 1) $nick
  tsay $msg.trivia.victory($nick)
  trivia.flush
  haltdef
}
;########################################################
;# HALL Of FAME, RANKING.                               #
;########################################################
alias sort {
  window -h $twin
  var %alias = better $+ $1
  filter -fwca $scoresfil $twin %alias *
}
alias -l hof { return $gettok($line($twin,$1),$2,59) }
alias -l msg.trivia.ten {
  sort $1
  var %temp.by = $gttok($1), %temp.ten = $e1($hof(1,1)) $e2(has the best $1 of) $e1($hof(1,%temp.by)) $+ $e2(;)
  var %i = 2
  while (%i <= 10) {
    var %temp.ten = %temp.ten $e2($iif($hof(%i,1),$hof(%i,1) - $hof(%i,%temp.by) $+ ;))
    inc %i
  }
  return %temp.ten
}
alias -l twin { return @trivia $+ $scoresfil }
alias -l getrank {
  sort score
  var %rank = $fline($twin,$+($1,;,*),1), %score = $hof(%rank,2)
  while (%score == $hof(%rank,2)) { dec %rank }
  inc %rank
  unset %uprank
  if (!$2) { return %rank }
  set -u0 %uprank 1
  var %upscore = $calc(%score + $2)
  while ((%upscore >= $hof($calc(%rank - %uprank),2)) && (%rank >= %uprank)) { inc %uprank }
  dec %uprank
  return %rank
}
alias getmrank {
  if (!$getset(trivia, ranks)) { return }
  var %score = $getvar($1,score), %i = $setini(ranks,0), %te = 0, %temax = 0
  while (%i >= 1) {
    %te = $setini(ranks,%i)
    if ((%score >= %te) && (%te >= %temax)) { %temax = %te }
    dec %i
  }
  if (%score == %temax) { set -u0 %promotion $getset(ranks,%temax) }
  return $getset(ranks,%temax)
}
alias -l recordstat {
  sort $1
  return $hof(1,1)
}
alias bettername { return $betterlow(1, $1, $2) }
alias betterscore { return $better(2, $1, $2) }
alias bettertime { return $betterlow(3, $1, $2) }
alias betterstreak { return $better(4, $1, $2) }
alias betterwpm { return $better(5, $1, $2) }
alias betterlow { return $iif($gettok($2, $1, 59) > $gettok($3, $1, 59),1,-1) }
alias better { return $iif($gettok($2, $1, 59) < $gettok($3, $1, 59),1,-1) }
;########################################################
;# AWARD setups.                                        #
;########################################################
alias -l msg.trivia.award { return %c2 $+ $replace($1,^, %c2 $+ $2 $+ %c2o,*, %c2 $+ $e1($getmrank($nick) $nick) $+ %c2o) $+ $c2o }
alias -l award {
  var %i = 1, %award = $1, %trigger = $2
  while ($aw(%i)) {
    tokenize 32 $aw(%i)
    if ($calc($findtok($award.on.tok, %award, 1, $asc(.)) - 1) == $1) {
      if ($istok(Join;Uprank;Promotion, %award, $asc(;))) { award.do $3 %trigger $6- }
      if (($2 == 1) && (%trigger == $4)) { award.act $3 %trigger $6- }
      if (($2 == 2) && (%trigger isnum $4 - $5)) { award.act $3 %trigger $6- }
      if (($2 == 3) && (%trigger >= $4)) { award.act $3 %trigger $6- }
      if (($2 == 4) && (%trigger <= $4)) { award.act $3 %trigger $6- }
      if (($2 == 6) && ($rand(1,$4) <= $5)) { award.act $3 %trigger $6- }
    }
    inc %i
  }
}
alias award.act {
  if ($1 == 1) { describe $chan $msg.trivia.award($3-,$2) }
  if ($1 == 2) { msg $chan $msg.trivia.award($3-,$2) }
  if ($1 == 3) { notice $chan $msg.trivia.award($3-,$2) }
  if ($1 == 4) { trivia.credit $nick $3 }
  if ($1 == 5) { tban $nick | msg $chan $msg.trivia.award($3-,$2) }
  if ($1 == 6) { $3- }
}
alias award.do {

}
alias award.on.tok { return Null.Score.Row.Time.WPM.Join.Question.Uprank.Promotion }
alias award.val.tok { return Null.Exactly.Between.At Least.At Most.Ranked.Random }
alias award.do.tok { return Null.Describe.Msg.Notice.Give Points.Ban.Special }
;########################################################
;# MESSAGING.                                           #
;########################################################
alias -l inform { if (($1) && ($server)) { $iif($nick == $me, .timer -m 1 $calc($timer(0) * 100)) $iif($getset(status,informc) == 1, msg $iden, $iif($nick != $me, .notice $nick, echo $chan)) $rdc($1-) } }
alias -l tsay { if (($1) && ($server)) { $iif($nick == $me, .timer -m 1 $calc($timer(0) * 100)) msg $iden $rdc($1-) } }
;########################################################
;# Direct basic processing, for special functions.      #
;########################################################
alias -l do.ping {
  ctcp $nick ping
  set -u120 % [ $+ ping. [ $+ [ $nick ] ] ] $ticks
}
alias -l trivia.report {
  inform $msg.trivia.thanks
  write " $+ $triv(dir) $+ / $+ $iif($1 == $pre $+ add, $triv(additions), $triv(report)) $+ " $nick $adate $time $2-
}
alias -l processcommand.stats {
  if ($1 isnum 1 - $hof.size) {
    sort score
    inform $msg.trivia.stats($hof($1,1))
  }
  else { inform $msg.trivia.stats($iif($1,$1,$nick)) }
}
;########################################################
;# FRIENDS/BANNED.                                      #
;########################################################
alias -l istrivia.friend {
  var %i = 1
  while ($getset(friend, %i)) {
    if ($getset(friend, %i) iswm $address($nick,5)) { return $true }
    inc %i
  }
}
alias is.friend {
  var %i = 1
  while ($getset(friend, %i)) {
    if ($getset(friend, %i) iswm $address($1,5)) { return $true }
    inc %i
  }
}
alias -l trivia.banned {
  var %i = 1
  while ($getset(banned,%i)) {
    if ($getset(banned,%i) == $iif($1,$1,$nick)) { 
      if (!$1) { inform $msg.trivia.banned }
      return %i
    }
    inc %i
  }
}
alias -l ban.size { return $calc(1 + $setini(banned, 0)) }
alias -l tban { if (!$trivia.banned($$1)) { setset banned $ban.size $1 } }
alias -l tunban {
  var %i = $trivia.banned($$1)
  while ($getset(banned, $calc(%i + 1))) {
    setset banned %i $getset(banned, $calc(%i + 1))
    inc %i
  }
  setset banned %i
}
;########################################################
;# CONVERTORS #
;########################################################
alias convertscores {
  var %ini = $iif($1,$1,triviascores.ini)
  if (!$exists(%ini)) { return }
  var %i = $ini(%ini,0)
  echo 4 -a Converting %i scores into Trivia 3.12+ format.
  while (%i > 0) {
    var %m = $ini(%ini,%i)
    write $iif($2,$2,$scoresfil) $+(%m,;,$readini(%ini,n,%m,score),;,$readini(%ini,n,%m,time),;,$readini(%ini,n,%m,streak),;,$readini(%ini,n,%m,wpm),;,$readini(%ini,n,%m,lastwin))
    dec %i
  }
  .rename %ini %ini $+ .bak
}
;########################################################
;# VAR MANIPULATIONS.                                   #
;########################################################
alias -l setvar {
  if (!$1) { return }
  if ($3- != $null) {
    var %isbackburner = $read($tempfil, w, $1 $+ ;*)
    if (%isbackburner) { copyentry $tempfil $scoresfil $1 }
    var %newline = $getvar($1)
    if (!%newline) { %newline = $1 $+ ;0;9999;0;0; $+ $date }
    %newline = $puttok(%newline,$3-,$gttok($2),59)
    write $iif($readn,-l $+ $readn) $scoresfil %newline
  }
}
alias getvar {
  var %scoreline = $read($scoresfil, w, $1 $+ ;*)
  if (!%scoreline) { return }
  if (!$2) { return %scoreline }
  return $gettok(%scoreline, $gttok($2), 59)
}
alias gttok { return $findtok(name.score.time.streak.wpm.lastwin, $1, 1, $asc(.)) }
alias ittok { return $gettok(name.score.time.streak.wpm.lastwin, $1, $asc(.)) }
alias -l varfil { return $iif($2 == $null, $iif($1 == 0, $lines($scoresfil), $gettok($read($scoresfil, $1),1,59)), $gettok($read($scoresfil, $1),$2,59)) }
alias -l setset {
  if ($3- != $null) { writeini -n trivia.ini $1 $2 $3- }
  else { remini -n trivia.ini $$1 $2 }
}
alias -l getset { return $readini(trivia.ini, n, $1, $2) }
alias -l setini { return $iif($2 != $null, $ini(trivia.ini, $1, $2), $ini(trivia.ini, $1)) }
alias -l thuser { return $thget($eval(Temp. $+ $1 $+ . $+ $nick,1)) }
alias -l thuset { thset $eval(Temp. $+ $1 $+ . $+ $nick,1) $2- }
alias -l thset { hadd Trivia $+ $iden $1- }
alias -l thget { return $hget(Trivia $+ $iden, $1) }
;########################################################
;# MISC.                                                #
;########################################################
alias iden { return $iif($chan, $chan, $iif(%ident, %ident, $tchan(1))) }
alias -l deleteplayer { if ($getvar($1)) { write -dl $+ $readn $scoresfil } }
alias -l hof.size { return $line($twin,0) }
alias -l scoresfil { return $ifd($thget(scores),$ifd($tchan($trivchan, 4), TriviaScores.fil)) }
alias -l trivia.on { if (($timer(q $+ $iden)) || ($timer(end $+ $iden))) { return $true } }
alias -l trivia.paused { if (($thget(paused)) && ($hget(Trivia $+ $iden))) { return $true } }
alias -l question.on { if ($timer(end $+ $iden)) { return $true } }
alias -l tokq { return $numtok($thget(Trivq), $asc($triv(delimiter))) }
alias -l tok { return $gettok($thget(Trivq), $1,$asc($triv(delimiter))) }
alias -l question.time { return $calc(($ticks - $thget(Start)) / 1000) }
alias -l te { return $getset(team, $1 $+ $prop) }
alias -l teamscore { return $thget(Score $+ $1) }
alias -l max.hinted { return $iif($calc($thget(Temp.Hints) + 0) > $calc($thuser(Hint) + 0), $thget(Temp.Hints), $thuser(hint)) }
alias -l isteam { return $thget(Team. $+ $1) }
alias -l chkadate { return $iif($getset(status,adate), $+($gettok($1,2,$asc(/)),/,$gettok($1,1,$asc(/)),/,$gettok($1,3,$asc(/))), $1) }
alias -l team { if ($thget(team) == 1) { return $true } }
alias -l tempini { return triviascbb.ini }
alias -l lag { return $iif($thget(lag $+ $1), $thget(lag $+ $1), $getset(lag,$1)) }
alias -l slag { return $getset(lag,$1) }
alias -l tc { return $getset(color, $1 $+ $iif($prop == b, -bold) $+ $iif($prop == u, -underline)) }
alias -l triv { return $getset(trivia, $1) }
alias -l aw { return $getset(award, $1) }
;########################################################
;# QUESTION MISC.                                       #
;########################################################
alias -l qfile {
  if ($gettok($thget(File),$1,$asc(;))) return " $+ $triv(dir) $+ \ $+ $gettok($thget(File),$1,$asc(;)) $+ "
  if ($tchan($ifd($trivchan,1),$calc(4 + $1))) return " $+ $triv(dir) $+ \ $+ $tchan($ifd($trivchan,1),$calc(4 + $1)) $+ "
}
alias -l numl { return $calc($numq - $numcat) }
alias -l numq {
  if ($1 isnum) { return $lines($qfile($1)) }
  var %i = 0, %j = 1
  while ($qfile(%j)) {
    inc %i $lines($qfile(%j))
    inc %j
  }
  return %i
}
alias -l numfile {
  var %i = 0, %j = 1, %k = $numq, %l
  while (%i <= %k) {
    %l = %i
    inc %i $numq(%j)
    if ($1 isnum %l - %i) { return $qfile(%j) $+ ; $+ $calc(%l + $1) }
    if (($1 !isnum) && ($read($qfile(%j), wn, $+(*,$1-,*), 1))) return $qfile(%j) $+ ; $+ $readn
    inc %j
  }
}
alias -l qread {
  var %nf = $numfile($1)
  return $read($gettok(%nf,1,$asc(;)),$gettok(%nf,2,$asc(;)))
}
alias -l qcat { 
  var %nf = $numfile($1)
  return $read($gettok(%nf,1,$asc(;)), wn, #*, $gettok(%nf,2,$asc(;)))
}
;########################################################
;# MESSAGE COLOR CODE SETTING ALIASES.                  #
;########################################################
alias -l e1 { return %c1 $+ $1- $+ %c1o }
alias -l e2 { return %c2 $+ $iif($isalias(trivtran),$trivtran($1-),$1) $+ %c2o }
;########################################################
;# MESSAGES.                                            #
;########################################################
alias -l msg.ping.reply { return $e1($nick) $+ $e2($chr(44) your ping is) $e1($calc(($ticks - % [ $+ ping. [ $+ [ $nick ] ] ] ) / 1000)) $e2(secs.) }
alias -l msg.answer.correct { return $e2(Winner:) $e1($getmrank($nick) $nick) $e2(Answer:) $e1($trivq.answer) $e2(Time:) $e1($thget(Time)) $e2(Streak:) $e1($getset(Var, Row)) $e2(Points:) $e1($getvar($nick,score)) $e2(WPM:) $e1($int($1)) $e2(Rank:) $e1($ord($2)) }
alias -l msg.answer.correct2 { return $e1($getmrank($nick) $nick) $e2(got the answer:) $e1($trivq.answer) $e2(in) $e1($thget(Time)) $e2(seconds.) $e2(Points:) $e1($getvar($nick,score)) $e2(Rank:) $e1($ord($2))  }
alias -l msg.answer.timeout { return $e2(Time's up! The answer was:) $e1($trivq.answer) }
alias -l msg.answer.timeout.total { return $e2(Time's up! Remaining answers were:) $e1($gettotalremain) }
alias -l msg.answer.timeout2 { return $e2(Time's up! Nobody got the answer!) }
alias -l msg.question.multi { return $e2(Multiple Choice:) $e1($right($tok(1),-7)) $+ $e2(; $get.multianswers) }
alias -l msg.question.total { return $e2(Give all Correct responces:) $e1($right($tok(1),-7)) }
alias -l msg.question.points { return $e2(For) $e1($thget(temp.points)) $e2(point $+ $iif($thget(temp.points) != 1,s) $+ :) $e1($get.question($1-)) }
alias -l msg.question.scramble { return $iif($getset(status, sayscramble),$e2(Unscramble the following:),$iif($1-,$e2($1 $+ :)))) $e1($scramble($tok(2)) $+ ?) }
alias -l msg.question.standard { return $e2($iif($1-, $1- $+ :)) $e1($get.question($tok(1))) }
alias -l msg.question.answer { return $e2(The answer to the last question was $+ :) $e1($thget(answer)) }
alias -l msg.trivia.stats { return $iif($getvar($1,score), $e1($getmrank($1) $1) $+ $e2(: Rank:) $e1($ord($getrank($1))) $e2(out of) $e1($hof.size) $+ $e2(. Current wins:) $e1($getvar($1,score)) $+ $e2(. Best streak:) $e1($getvar($1,streak)) $+ $e2(. Best time:) $e1($getvar($1,time)) $e2( secs. WPM:) $e1($getvar($1,wpm)) $iif($getvar($1,lastwin), $e2(Last Win:) $e1($chkadate($getvar($1, lastwin)))), $e2(No such user exists.)) }
alias -l msg.trivia.state { return $msg.trivia.version $e2(is currently) $e1($trivon) $+ $e2(.) $iif($getset(status,champ),$e2(Champ Mode Set to) $e1($triv(reset)) $e2(Wins.)) $e2(Question file contains) $e1($numq) $e2(lines. Trivia is:) $e1($trivia.onoff) $+ $e2(.) $iif($trivia.on, $e2(Max Questions:) $e1($thget(Max)) $e2(Team Game:) $e1($team.onoff) $+ $e2(. Trivia Round started by) $e1($thget(SUser)) $e2(on) $e1($thget(STime))) $e2(Bot time is:) $e1($time) }
alias -l msg.trivia.enabled { return $e2(Enabling the trivia. Have an op type:) $e1($pre $+ disable) $e2(to disable the bot.) }
alias -l msg.trivia.disabled { return $e2(Disabling the trivia. Have an op type:) $e1($pre $+ enable) $e2(to enable the bot.) }
alias -l msg.trivia.victory { return $e2(The game has been beaten by) $e1($1) $e2(all hail the new champ whose name shall reign supreme!) }
alias -l msg.trivia.unactive { return $e2(The game has been disabled due to inactivity.) }
alias -l msg.trivia.uprank { return $e1($1) $e2(has moved up in rank. Rank:) $e1($ord($2)) }
alias -l msg.trivia.pause { return $e2(Trivia paused.) $e1($pre $+ resume) $e2(to resume.) }
alias -l msg.trivia.resume { return $e2(Trivia resumed.) }
alias -l msg.trivia.started { return $e2(Starting the trivia. Round of) $e1($thget(Max)) $e2(questions.) $e1($pre $+ strivia) $e2(to stop. Total:) $e1($numl) }
alias -l msg.trivia.stopped { return $e2(Stopping the trivia.) $e1($pre $+ trivia <number>) $e2(to restart.) }
alias -l msg.trivia.awarded { return $e1($1) $e2(was awarded) $e1($2) $e2(point $+ $iif($2 > 1,s) $+ . Current Wins:) $e1($getvar($1,score)) }
alias -l msg.trivia.deducted { return $e1($1) $e2(was deducted) $e1($calc($2 * -1)) $e2(point $+ $iif($2 < -1,s) $+ . Current Wins:) $e1($getvar($1,score)) }
alias -l msg.trivia.hof { return $msg.trivia.champ(1) $msg.trivia.ten(score) }
alias -l msg.trivia.error.midq { return $e2(Cannot pause while trivia game has a question issued.) }
alias -l msg.trivia.banned { return $e1(You cannot play $+ $chr(44) you are banned.) }
alias -l msg.trivia.guessed { return $e2(You already had a guess ") $+ $e1($thuser(Guess)) $+ $e2(" was incorrect.) }
alias -l msg.trivia.thanks { return $e2(Thank you for your contribution!) }
alias -l msg.trivia.version { return $e1(Tat's Trivia Bot $+ $chr(44) v $+ $trivia.version) }
alias -l msg.trivia.web { return $e2(Get your own copy of) $msg.trivia.version $e2(at) $e1(http://web.dreamsoft.com/tat/trivia.htm) $e2(.) }
alias -l msg.trivia.onjoin { return $e2(Welcome) $e1($getmrank($nick) $nick) $+ $e2($chr(44)) $e1($msg.trivia.version) $e2(is activated. Type ') $+ $e1($pre $+ help) $+ $e2(' for a list of commands or just ') $+ $e1($pre $+ trivia) $+ $e2(' to start a game!) }
alias -l msg.trivia.records { return $e2(Record streak:) $e1($recordstat(streak)) $e2(of) $e1($hof(1,4)) $+ $e2(.) $e2(Record time:) $e1($recordstat(time)) $e2(of) $e1($hof(1,3)) $+ $e2(.) $e2(Record wpm:) $e1($recordstat(WPM)) $e2(of) $e1($hof(1,5)) $+ $e2(.) }
alias -l msg.trivia.themes { return $e2(Current themes are:) $e1($get.themes) }
alias -l msg.trivia.champ { return $iif($getset(status,champ), $e2(Current champ:) $e1($getset(Champ, $ini(trivia.ini, Champ, 0))) $+ $e2(. $get.champ($1))) }
alias -l msg.trivia.showteams { return $msg.trivia.showteam(1) $msg.trivia.showteam(2) $iif($getset(team, 4-team), $msg.trivia.showteam(3) $msg.trivia.showteam(4)) }
alias -l msg.trivia.showteam { return $iif($get.showteams($1), $e2(Current members of) $e1($te($1)) $e2(are:) $e1($get.showteams($1))) }
alias -l msg.trivia.hintpaused { return $e2(You requested a $pre $+ hint less than) $e1($triv(hintpause)) $e2(seconds ago.) }
alias -l msg.trivia.roundscores { return $e2(Current Round:) $e1($get.roundscores) }
alias -l msg.trivia.banlist { return $e1(The following people are banned:) $e1($get.banlist) }
alias -l msg.team.start { return $e2(Team Trivia: ') $+ $e1($pre $+ join 1) $+ $e2(' or ') $+ $e1($pre $+ join 2) $+ $iif($getset(team,4-team),$e2(' or ') $+ $e1($pre $+ join 3) $+ $e2(' or ') $+ $e1($pre $+ join 4)) $+ $e2(' to add to a team.) }
alias -l msg.team.add { return $e2(Team:) $e1($1) $e2(has a new member:) $e1($2) }
alias -l msg.team.joinover { return $e2(I am sorry no more people can join/change at this time.) }
alias -l msg.team.toomany { return $e2(That team currently has enough players.) }
alias -l msg.team.joinbefore { return $e2(Teams are no longer accepting player.) }
alias -l msg.team.alreadyon { return $e2(You are already on that team.) }
alias -l msg.team.score { return $e1($getmrank($nick) $nick) $e2(won. Point for) $e1($te($isteam($nick))) $+ $e2(.) $msg.team.cscore(1,2) $iif($getset(team,4-team), $msg.team.cscore(3,4)) }
alias -l msg.team.cscore { return $e1($te($1)) $e2(has) $e1($thget(Score $+ $1)) $e2(points.) $e1($te($2)) $e2(has) $e1($thget(Score $+ $2)) $e2(points.) }
alias -l msg.team.over { return %c2 $+ $replace($1-, *t1, %c2o $+ $e1($te(1)) $+ %c2,*t2, %c2o $+ $e1($te(2)) $+ %c2,*t3,%c2o $+ $e1($te(3)) $+ %c2,*t4,%c2o $+ $e1($te(4)) $+ %c2) $+ %c2o $+ $e2(!) }
alias -l msg.ranks.promotion { return $e1($nick) $+ $e2($chr(44) congratulations on your promotion to:) $e1($1) }
alias -l msg.hint.words { return $e2(There are) $e1($numtok($trivq.answer,32)) $e2(words in the answer.) }
alias -l msg.hint.vowels { return $e2(Vowels are:) $e1($$get.hint(vowels)) }
alias -l msg.hint.last { return $e2(The last character in the answer is:) $e1($$get.hint(last)) }
alias -l msg.hint.answerspace { return $e2(Answer:) $e1($get.hint(space)) }
alias -l msg.hint.hint { return $e2(Here's your $ord($ifd($thuser(hint),$thget(Temp.Hints))) hint:) $e1($$get.hint(hint,$1)) }
alias -l msg.hint.hint2 { return $e2(Here's a hint:) $e1($$get.hint(hint,$1)) }
alias -l msg.features.built { return $e2(Trivia scores updated:) $e1($1) $e2(!) }
;########################################################
;# MESSAGE PROCESSES.                                   #
;########################################################
alias -l get.question {
  if ($right($1,1) == -) { return $left($1-,-1) }
  return $1- $+ $iif(((!$isdis(30)) && ($right($1,1) != ?)),?)
}
alias -l get.banlist {
  var %i = 1, %b.temp
  while ($getset(banned,%i)) {
    var %b.temp = %b.temp $getset(banned,%i)
    inc %i
  }
  return %b.temp
}
alias -l get.roundscores {
  if ($window(@round $+ $iden)) { window -c @round $+ $iden }
  window -hn @round $+ $iden
  .timer 1 0 window -c @round $+ $iden
  var %i = 1
  while ($hmatch(Trivia $+ $iden, Score.*, %i)) {
    var %j = $line(@round $+ $iden,0)
    while (( $hget(Trivia $+ $iden, $hmatch(Trivia $+ $iden, Score.*, %i)) > $thget(Score. $+ $line(@round $+ $iden, %j))) && (%j >= 1)) { dec %j }
    iline @round $+ $iden $calc(%j + 1) $remove($hmatch(Trivia $+ $iden, Score.*, %i),Score.)
    inc %i
  }
  var %roundscores
  %i = 1
  while (%i <= 15) {
    %roundscores = %roundscores $iif($line(@round $+ $iden,%i),$line(@round $+ $iden,%i) $+ - $+ $thget(Score. $+ $line(@round $+ $iden,%i)))
    inc %i
  }
  return %roundscores
}
alias sortroundscores {
  var %j = 1
  while (%j <= $line(@round $+ $iden,0)) {
    var %k = %j
    while (%k <= $line(@round $+ $iden,0)) {
      if ($thget(Score. $+ $line(@round $+ $iden, %j)) > $thget(Score. $+ $line(@round $+ $iden, %k))) {
        var %temp.name = $line(@round $+ $iden, %j)
        rline @round $+ $iden %j $line(@round $+ $iden, %k)
        rline @round $+ $iden %j %temp.name
      }
      inc %k
    }
    inc %j
  }
}
alias -l get.showteams {
  var %i = 1
  while ($hmatch(Trivia $+ $iden, Team.*, %i)) {
    if ($isteam($remove($hmatch(Trivia $+ $iden, Team.*, %i),Team.)) == $1) { var %temp.team = %temp.team $remove($hmatch(Trivia $+ $iden, Team.*, %i),Team.) }
    inc %i
  }
  return %temp.team
}
alias -l get.champ {
  if (($setini(Champ,0) <= 0) || (!$getset(status,champ))) { return }
  var %temp.champ, %i = $calc($ini(trivia.ini, Champ, 0) - 1)
  while ((%i >= 1) && (!$1)) {
    var %temp.champ = %temp.champ $getset(Champ, %i)
    dec %i
  }
  return %temp.champ
}
alias -l get.multianswers {
  var %i 2, %answers.t
  if ($window(@multianswer)) { window -c @multianswer }
  window -h @multianswer
  .timer 1 0 window -c @multianswer
  while ($tok(%i)) {
    aline @multianswer $tok(%i)
    inc %i
  }
  filter -wwct 1 13 @multianswer @multianswer *
  var %i 1
  while ($line(@multianswer, %i)) { var %answers.t = %answers.t $line(@multianswer, %i), %i = $calc(%i + 1) }
  return %answers.t
}
alias -l get.themes {
  var %i = 1
  while ($getset(triviamode $+ %i, name)) {
    var %temp.themes = %temp.themes $getset(triviamode $+ %i, name)
    inc %i
  }
  return $e1(%temp.themes)
}
;########################################################
;# HTML BUILD                                           #
;########################################################
alias htmlbuild {
  var %start.ticks = $ticks, %htmlfile = $ifd($getset(build,html),triv.htm)
  sort score
  if ($exists(%htmlfile)) { .remove %htmlfile }
  write %htmlfile <HTML><head><title> $+ $iden Trivia Scores $+ </title></head>
  write %htmlfile <body bgcolor="#000000" text="#339933" link="#33FF00" alink="#666600" vlink="#666666">
  write %htmlfile The Scores File was Compiled By: $strip($msg.trivia.version) <br>
  write %htmlfile The Creation Date of the Scores file is: $time $adate <br><ol>
  write %htmlfile <table BORDER COLS=5 WIDTH="100%" >
  write %htmlfile <tr>
  write %htmlfile <TR>
  write %htmlfile <TH>Ranking</TH><TH>Name</TH><TH>Score</TH><TH>Best Time</TH><TH>Best Streak</TH><TH>Best WPM</TH>
  write %htmlfile </TR>
  var %i = 1, %j = $hof.size
  if ($getset(build,top) isnum 1 - %j) { %j = $getset(build,top) }
  while (%i <= %j) {
    write %htmlfile <tr><TH> $+ %i $+ </TH> <td> $+ $hof(%i,1) $+ </td> <td> $+ $hof(%i,2) $+ </td> <td> $+ $hof(%i,3) $+ </td> <td> $+ $hof(%i,4) $+ </td> <td> $+ $hof(%i,5) $+ </td></tr>
    inc %i
  }
  write %htmlfile </table><br>
  write %htmlfile Made with <a href="http://web.dreamsoft.com/tat/trivia.htm" "target="_top"> $+ $strip($msg.trivia.version) $+ </A><br>
  echo -a $e2(Finished:) $e1(%htmlfile) $e2(is written. In) $e1($calc(($ticks - %start.ticks) / 1000)) $+ $e2(secs.)
  if ($getset(build,web)) { tsay $msg.features.built($getset(build,web)) }
  if (($getset(build,auto)) && ($exists($+(",$triv(dir),\,ftpbatch.txt,")))) { run -n ftp $+(-s:,$triv(dir),\,ftpbatch.txt) }
}
;########################################################
;# SPECIAL COMMANDS. #
;########################################################
alias find { echo $get.find($1-) }
alias add { if ($exists($qfile(1))) write $qfile(1) $1- }
alias ask {
  var %asknm = 1
  while ($thget(Ask $+ %asknm)) { inc %asknm }
  if ($hget(Trivia $+ $iden)) { thset Ask $+ %asknm $iif($1-,$1-,$$?="Force which question number(#) or ask what question(Question*Answer)?") }
}
alias sortfile { 
  var %file = " $+ $sfile($mircdir) $+ "
  filter -ffct 1 13 %file %file *
}
alias killdup { 
  var %file = " $+ $sfile($mircdir) $+ ", %i = 0
  window -hn @temp.window
  while ($lines(%file) >= %i) {
    var %line = $read(%file,%i)
    if (%line) { aline -n @temp.window %line }
    unset %line
    inc %i
  }
  filter -wfc @temp.window %file *
  window -c @temp.window
}
alias tpurge {
  var %i = 1
  sort score
  while ($hof(%i,1)) {
    if ($hof(%i,2) <= $$1) { copyentry $$scoresfil $$tempfil $hof(%i,1) }
    inc %i
  }
}
alias tdpurge {
  var %i = 1
  sort score
  while ($hof(%i,1)) {
    if ($round($calc(($ctime($date) - $ctime($hof(%i,6)))/86400),0) > $$1) { copyentry $$scoresfil $$tempfil $hof(%i,1) }
    inc %i
  }
}
alias copyentry {
  write $2 $$read($1, w, $3 $+ ;*)
  write -dl $+ $$readn $1
}
alias tempfil { return backburner.txt }
alias tmerge {
  if (($$getvar($$1,score)) && ($$getvar($$2,score))) {
    setvar $2 score $calc($getvar($2,score) + $getvar($1,score))
    if ($getvar($1, wpm) > $getvar($2,wpm)) { setvar $2 wpm $getvar($1, wpm) }
    if ($getvar($1, streak) > $getvar($2,streak)) { setvar $2 streak $getvar($1, streak) }
    if ($getvar($1, time) < $getvar($2,time)) { setvar $2 time $getvar($1, time) }
    deleteplayer $1
  }
  tsay $msg.trivia.stats($2)
}
alias trename {
  setvar $1 name $2
  tsay $msg.trivia.stats($2)
}
alias triviad {
  if (($1 >= 1) && ($2)) { .timertriviaad 0 $calc($$1 * 60) timer.ad $active $2- }
  else { .timertriviaad off } 
}
alias triviad2 { 
  if (($1 >= 1) && ($2)) { .timertriviaad 0 $calc($$1 * 60) msg $active $e1($2-) } 
  else { .timertriviaad off } 
}
alias timer.ad { if (!$trivia.on) { msg $1 $e1($2-) } }
;########################################################
;# DIALOGS.                                             #
;########################################################
dialog trivset {
  title "Trivia Settings"
  size -1 -1 452 324
  option pixels
  tab General, 1, 0 0 452 327
  box Channels, 9, 8 28 266 80, tab 1
  text Delimiter, 10, 18 255 60 13, tab 1
  text Add/Report, 11, 18 233 60 13, tab 1
  button Add, 24, 20 124 52 16, tab 1
  text Directory, 13, 18 211 60 13, tab 1
  edit , 30, 80 81 186 22, tab 1 multi autohs
  edit $triv(delimiter), 31, 84 255 30 22, tab 1 multi autohs
  edit $triv(additions), 32, 84 229 86 22, tab 1 multi autohs
  edit $triv(report), 33, 172 229 86 22, tab 1 multi autohs
  edit $triv(dir), 35, 84 203 174 22, tab 1 multi autohs
  text Percent Hint, 14, 284 64 68 13, tab 1
  edit $triv(perchint), 99, 392 64 36 20, tab 1
  text Number of hints, 15, 284 46 80 13, tab 1
  edit $triv(numhint), 61, 392 42 36 20, tab 1
  text Hint Reduction, 16, 284 260 80 13, tab 1
  edit $triv(DPH), 63, 396 256 36 20, tab 1
  text Points per answer, 17, 284 238 88 13, tab 1
  edit $triv(PPQ), 65, 396 234 36 20, tab 1
  list 108, 78 40 188 40, tab 1 size
  button Add, 115, 22 48 50 16, tab 1
  button Remove, 119, 22 64 50 16, tab 1
  text Channel:, 125, 20 84 50 16, tab 1
  edit , 132, 80 164 186 21, tab 1
  box "Points", 133, 276 220 168 64, tab 1
  box "Global", 134, 8 192 264 92, tab 1
  button "Scores File", 141, 16 164 60 20, tab 1
  button "Define", 20, 124 256 47 17, tab 1
  check "Trivia Ranks", 148, 176 256 88 20, tab 1
  check Crosshatch, 47, 284 84 80 20, tab 1
  text Chr, 21, 384 88 19 13, tab 1
  edit , 961, 404 88 24 18, tab 1
  box "Hints", 80, 276 28 168 192, tab 1
  radio "Scatter", 58, 332 140 56 20, tab 1
  radio "Plot", 129, 388 140 44 20, hide tab 1
  radio "Basic", 130, 284 140 48 20, tab 1
  text "This is an example of a hint", 199, 284 124 154 16, tab 1
  check "Say Hint Number", 147, 284 100 100 20, hide tab 1
  radio "Standard", 149, 280 180 68 20, hide tab 1
  radio "Last", 150, 356 180 44 20, hide tab 1
  radio "Vowels", 151, 280 196 60 20, hide tab 1
  radio "Random", 152, 356 196 68 20, hide tab 1
  text "First Hint Type", 153, 284 164 74 16, hide tab 1
  button "Remove", 12, 20 140 52 16, tab 1
  list 34, 80 120 186 36, tab 1 sort size
  box "Questions", 83, 8 108 266 84, tab 1
  tab Options, 6
  text questions, 18, 52 188 52 13, tab 6
  check No-activity off, 88, 16 148 100 20, tab 6
  edit $triv(naoff), 89, 16 168 30 20, tab 6
  text seconds, 19, 166 188 44 13, tab 6
  check Hint-Pause, 96, 124 148 100 20, tab 6
  edit $triv(hintpause), 97, 122 168 30 20, tab 6
  check Echo Answer, 40, 16 48 100 20, tab 6
  check Auto-Hint, 41, 340 48 100 20, tab 6
  check Champ Mode, 42, 232 72 100 20, tab 6
  check Timeout Answer, 45, 340 72 100 20, tab 6
  check Join Message, 46, 124 48 100 20, tab 6
  check Traditional win, 48, 16 96 100 20, tab 6
  check Auto-Start, 49, 232 48 100 20, tab 6
  check Msg Reponces, 50, 124 72 100 20, tab 6
  check Say Scramble:, 53, 124 96 100 20, tab 6
  check Msg Hints, 54, 232 96 100 20, tab 6
  check Showteam End, 55, 340 96 100 20, tab 6
  check Answer Space, 56, 16 120 100 20, tab 6
  check No Mid-Match, 57, 124 120 100 20, tab 6
  check Show Matched, 59, 340 120 100 20, tab 6
  check Use Adate, 60, 16 72 100 20, tab 6
  check No ? end, 830, 340 168 88 20, tab 6
  check No Spell Correct, 817, 340 144 100 20, tab 6
  check "No bonus", 126, 340 192 100 20, hide tab 6
  check Limit Guesses, 51, 232 148 88 20, tab 6
  edit "1", 144, 264 168 44 20, disable read tab 6
  check Round HoF, 52, 232 120 88 20, tab 6
  box Settings, 70, 4 24 440 204, tab 6
  edit , 22, 4 236 432 57, tab 6 read multi autovs
  tab Defaults, 2
  box , 23, 4 43 250 64, tab 2
  box , 25, 254 43 130 64, tab 2
  check Colors, 116, 8 32 76 16, tab 2 push
  text Primary, 110, 14 58 60 13, tab 2
  text Secondary, 120, 14 78 60 13, tab 2
  edit $tc(1), 121, 76 58 30 20, tab 2 read
  edit $tc(2), 122, 76 78 30 20, tab 2 read
  edit $tc(3), 123, 259 58 30 20, tab 2 read
  edit $tc(4), 124, 259 78 30 20, tab 2 read
  check B, 117, 201 58 20 20, tab 2 push
  check U, 118, 224 58 20 20, tab 2 push
  check B, 127, 201 78 20 20, tab 2 push
  check U, 128, 224 78 20 20, tab 2 push
  combo 111, 112 60 80 240, tab 2 size drop
  combo 112, 112 80 80 240, tab 2 size drop
  combo 113, 296 60 80 240, tab 2 size drop
  combo 114, 296 80 80 240, tab 2 size drop
  box Time, 26, 4 108 196 192, tab 2
  text Before Start, 27, 14 126 120 13, tab 2
  text Between Questions (answered), 36, 14 228 120 29, tab 2
  text Given to Answer, 37, 14 150 120 13, tab 2
  text Before Auto-Hint, 38, 14 200 120 13, tab 2
  text (timed-out), 39, 14 258 120 17, tab 2
  text Before hint allowed, 62, 14 174 120 13, tab 2
  edit $slag(start), 135, 140 126 50 20, tab 2
  edit $slag(answered), 145, 140 236 50 20, tab 2
  edit $slag(timedout), 155, 140 148 50 20, tab 2
  edit $slag(hint), 165, 140 196 50 20, tab 2
  edit $slag(timed), 175, 140 258 50 20, tab 2
  edit $slag(hintallow), 185, 140 170 50 20, tab 2
  box Questions, 64, 202 108 150 152, tab 2
  text Default Round, 68, 276 118 70 13, tab 2
  text Champ Goal, 69, 212 200 62 13, tab 2
  text Team Round, 71, 276 158 70 13, tab 2
  edit $triv(default), 205, 276 134 63 20, tab 2
  edit $triv(reset), 215, 276 200 63 20, tab 2
  edit $triv(dteam), 217, 276 174 63 20, tab 2
  button $record.type($triv(Record)), 218, 210 230 133 20, tab 2
  button Themes, 700, 266 268 68 20, tab 2
  radio Unlimited, 201, 208 176 68 20, tab 2
  radio Team, 202, 208 152 52 20, tab 2
  radio Normal, 203, 208 128 60 20, tab 2
  check Disable, 816, 208 268 40 20, tab 2 push
  box , 8, 202 256 150 36, tab 2
  check "Background", 158, 256 32 76 16, tab 2 push
  check "Announce Next", 136, 16 276 116 20, hide tab 2
  tab Teams, 3
  box Names, 72, 8 72 400 72, tab 3
  text Team 1, 73, 16 88 42 20, tab 3
  text Team 2, 74, 16 112 42 20, tab 3
  text Team 3, 308, 208 88 42 20, disable tab 3
  text Team 4, 309, 208 112 42 20, disable tab 3
  box Victories, 75, 8 144 412 144, tab 3
  text Tied Message, 76, 16 168 66 13, tab 3
  text Team 1 Wins, 77, 16 192 66 13, tab 3
  text Team 2 Wins, 78, 16 216 66 13, tab 3
  text Team 3 Wins, 303, 16 240 66 16, disable tab 3
  text Team 4 Wins, 304, 16 264 66 16, disable tab 3
  edit $te(1), 380, 56 88 148 20, tab 3 multi autohs
  edit $te(2), 381, 56 112 148 20, tab 3 multi autohs
  edit $te(4), 382, 248 112 148 20, disable tab 3 multi autohs
  edit $te(3), 383, 248 88 148 20, disable tab 3 multi autohs
  edit $te(0).victory, 320, 80 168 320 20, tab 3 multi autohs
  edit $te(1).victory, 321, 80 192 320 20, tab 3 multi autohs
  edit $te(2).victory, 322, 80 216 320 20, tab 3 multi autohs
  edit $te(3).victory, 323, 80 240 320 20, disable tab 3 multi autohs
  edit $te(4).victory, 324, 80 264 320 20, disable tab 3 multi autohs
  check Limit Join Period, 330, 272 32 88 20, tab 3 push
  edit $te(JoinBefore), 335, 272 51 88 20, tab 3
  radio 2 Teams, 28, 44 40 76 20, tab 3
  radio 4 Teams, 29, 140 40 76 20, tab 3
  tab Awards, 4
  box Awards, 79, 10 48 380 152, tab 4
  button Delete, 411, 396 80 48 20, tab 4
  button Add, 412, 396 56 48 20, tab 4
  list 420, 15 64 368 130, tab 4 sort size
  text "* is winner's nick.", 81, 210 257 92 13, tab 4
  text "^ is value of trigger", 82, 312 257 104 13, tab 4
  check Disable, 819, 16 28 76 17, tab 4 push
  combo 137, 68 212 68 100, tab 4 size drop
  edit "", 139, 264 212 68 21, tab 4
  text "Award", 140, 8 272 42 16, tab 4
  edit "", 142, 64 272 364 21, tab 4 multi autohs
  text "Trigger on", 154, 8 212 54 16, tab 4
  combo 159, 184 212 68 100, tab 4 size drop
  text "and", 160, 336 216 22 16, hide tab 4
  edit "", 161, 364 212 68 21, hide tab 4
  text "points", 162, 296 236 34 16, tab 4
  text "Do Action", 163, 8 252 50 16, tab 4
  text "values", 164, 140 212 38 16, tab 4
  combo 166, 64 248 140 100, tab 4 size drop
  tab Status, 5
  text Trivia Script version:, 84, 20 40 150 20, tab 5
  text $strip($msg.trivia.version), 85, 180 40 150 20, tab 5
  text Trivia bot is currently:, 86, 20 62 150 20, tab 5
  text $trivon, 504, 180 62 80 20, tab 5
  text Current mIRC version is:, 87, 20 84 150 20, tab 5
  text $version, 90, 180 84 80 20, tab 5
  text Current Trivia directory exists:, 91, 20 106 150 20, tab 5
  text $trivia.dir, 92, 180 106 80 20, tab 5
  text Currently in Trivia Channel:, 93, 20 128 150 20, tab 5
  text $trivia.chan, 94, 180 128 80 20, tab 5
  text Question file in Directory:, 95, 20 150 150 20, tab 5
  text $trivia.file, 98, 180 150 80 20, tab 5
  text Number of questions:, 103, 20 172 150 20, tab 5
  text $numl, 104, 180 172 78 20, tab 5
  button Delete Scores, 515, 304 100 80 20, tab 5
  button Scores, 519, 304 68 80 20, tab 5
  list 601, 22 202 248 42, tab 5 sort size
  button Unban, 602, 274 224 80 20, tab 5
  button Ban, 603, 274 202 80 20, tab 5
  list 610, 22 248 248 42, tab 5 sort size
  button Add Friend, 611, 274 250 80 20, tab 5
  button Remove, 612, 274 272 80 20, tab 5
  tab Commands, 7
  box Limit On/Off Control, 105, 4 228 164 76, tab 7
  check On, 43, 20 244 48 20, tab 7 push
  combo 66, 76 244 80 76, tab 7 size drop
  check Off, 44, 20 268 48 20, tab 7 push
  combo 67, 76 268 80 76, tab 7 size drop
  check $pre $+ trivia team, 811, 12 92 100 20, tab 7
  check $pre $+ trivia unlimited, 812, 12 68 100 20, tab 7
  check $pre $+ trivia $chr(35), 813, 12 44 100 20, tab 7
  check $pre $+ trivia team $chr(35), 814, 12 116 100 20, tab 7
  check $pre $+ pause/resume, 831, 12 140 100 20, tab 7
  check $pre $+ hof, 807, 120 44 100 20, tab 7
  check $pre $+ hoffast, 809, 120 68 100 20, tab 7
  check $pre $+ hofstreak, 808, 120 92 100 20, tab 7
  check $pre $+ hofwpm, 810, 120 116 100 20, tab 7
  check $pre $+ records, 815, 120 140 100 20, tab 7
  check $pre $+ next, 802, 228 44 100 20, tab 7
  check $pre $+ answer, 820, 228 68 100 20, tab 7
  check $pre $+ ping, 806, 228 92 100 20, tab 7
  check $pre $+ themes, 805, 228 116 100 20, tab 7
  check $pre $+ add/report, 818, 228 140 100 20, tab 7
  check $pre $+ hint, 801, 336 44 100 20, tab 7
  check $pre $+ last, 822, 336 92 100 20, tab 7
  check $pre $+ words, 821, 336 116 100 20, tab 7
  check $pre $+ repeat, 803, 336 140 100 20, tab 7
  check $pre $+ op ban, 825, 228 172 100 20, tab 7
  check $pre $+ vowels, 823, 336 68 100 20, tab 7
  check $pre $+ op, 824, 12 172 100 20, tab 7
  check $pre $+ op find, 829, 120 172 100 20, tab 7
  check $pre $+ op unban, 826, 12 196 100 20, tab 7
  check $pre $+ op ask, 827, 120 196 100 20, tab 7
  check $pre $+ op add, 828, 336 172 100 20, tab 7
  check $pre $+ dis/enable, 804, 228 196 100 20, tab 7
  box Disable, 106, 4 24 441 204, tab 7
  text Command Prefix, 107, 180 240 82 16, tab 7
  edit %command-prefix, 850, 264 236 36 21, tab 7
  text blank = default, 109, 180 256 78 16, tab 7
  button "Build HTML Options", 157, 328 240 107 21, tab 7
  button "Disable", 890, 340 200 95 21, hide tab 7
  button Cancel, 101, 358 298 40 20, cancel
  button OK, 100, 405 298 40 20, ok
  button Apply, 102, 308 298 40 20
  link "Visit Homepage", 518, 220 300 76 16
}
;########################################################
;# DIALOG EVENTS.                                       #
;########################################################
on *:dialog:trivset:init:*:{
  var %i = 1
  while ($getset(chan, %i)) {
    did -a $dname 108 $gettok($getset(chan, %i), 1, 59)
    inc %i
  }
  var %i = $numtok($status.toks, $asc(.))
  while (%i >= 1) {
    if ($getset(status, $gettok($status.toks, %i, $asc(.))) == 1) { did -c $dname $calc(39 + %i) }
    dec %i
  }
  if (!$did(58).state) { did -c $dname 130 }
  if ($getset(trivia,ranks) == 1) { did -c $dname 148 }
  if ($getset(status,naoff) == 1) { did -c $dname 88 }
  if ($getset(status,hintpause) == 1) { did -c $dname 96 }
  if ($getset(status,autostart) == 1) { did -c $dname 49 }
  if ($getset(color,on) == 1) { did -c $dname 116 }
  if ($getset(color,bon) == 1) { did -c $dname 158 }
  if ($getset(color,1-bold) == 1) { did -c $dname 117 }
  if ($getset(color,1-underline) == 1) { did -c $dname 118 }
  if ($getset(color,2-bold) == 1) { did -c $dname 127 }
  if ($getset(color,2-underline) == 1) { did -c $dname 128 }
  if ($getset(trivia,odefault) == Unlimited) { did -c $dname 201 }
  elseif ($getset(trivia,odefault) == Team) { did -c $dname 202 }
  else { did -c $dname 203 }
  if ($getset(team,Joinbeforeon) == 1) { did -c $dname 330 }
  if ($getset(team,4-team) == 1) {
    trivset.teams 1
    did -c $dname 29
  }
  else { did -c $dname 28 }
  var %i = 0
  while (%i < 16) {
    did -a $dname 111,112,113,114 $colorcode(%i)
    inc %i
  }
  did -a $dname 66,67 User
  did -a $dname 66,67 Voice
  did -a $dname 66,67 Half-Op
  did -a $dname 66,67 Op/Friend
  did -a $dname 66,67 Nobody
  did -c $dname 66 $calc($getset(trivia,onlevel) + 1)
  did -c $dname 67 $calc($getset(trivia,offlevel) + 1)
  did -c $dname 111 $calc($did(121) + 1)
  did -c $dname 112 $calc($did(122) + 1)
  did -c $dname 113 $calc($did(123) + 1)
  did -c $dname 114 $calc($did(124) + 1)
  awards.load
  var %i = 1
  while ($setini(banned,%i)) {
    did -a $dname 601 $getset(banned,%i)
    inc %i
  }
  did -a $dname 961 $iif($chr($triv(ch)),$chr($triv(ch)),_)
  disable.load
  trivia.load.friends
  check.toggle.multichan
  check.toggle.ranks
  check.color.toggle
  check.awards.toggle
}
on *:dialog:trivset:sclick:100,102:{
  setset trivia delimiter $did(31)
  setset trivia additions $did(32)
  setset trivia report $did(33)
  setset trivia dir $did(35)
  var %i = $numtok($status.toks, $asc(.))
  while (%i >= 1) {
    setset status $gettok($status.toks, %i, $asc(.)) $did($calc(39 + %i)).state
    dec %i
  }
  setset trivia onlevel $calc($did(66).sel - 1)
  setset trivia offlevel $calc($did(67).sel - 1)
  setset status naoff $did(88).state
  setset trivia naoff $did(89)
  setset status hintpause $did(96).state
  setset trivia hintpause $did(97)
  setset trivia perchint $did(99)
  setset trivia numhint $did(61)
  setset trivia DPH $did(63)
  setset trivia PPQ $did(65)
  setset trivia ranks $did(148).state
  setset color on $did(116).state
  setset color bon $did(158).state
  setset color 1-bold $did(117).state
  setset color 1-underline $did(118).state
  setset color 2-bold $did(127).state
  setset color 2-underline $did(128).state
  setset team JoinBeforeon $did(330).state
  setset team Joinbefore $did(335)
  setset color 1 $int($did(121))
  setset color 2 $int($did(122))
  setset color 3 $int($did(123))
  setset color 4 $int($did(124))
  varcolors
  var %i = 1
  while (%i <= 6) {
    setset lag $gettok(start.answered.timedout.hint.timed.hintallow, %i, $asc(.)) $int($did($calc(125 + (%i * 10))))
    inc %i
  }
  setset trivia default $int($did(205))
  setset trivia odefault
  if ($did(201).state == 1) { setset trivia odefault Unlimited }
  if ($did(202).state == 1) { setset trivia odefault Team }
  setset trivia reset $int($did(215))
  setset trivia dteam $int($did(217))
  setset award
  var %i = 1
  while (%i <= $did(420).lines) {
    setset award %i $did(420,%i)
    inc %i
  }
  setset team 1 $did(380)
  setset team 2 $did(381)
  setset team 3 $did(382)
  setset team 4 $did(383)
  setset team 0victory $did(320)
  setset team 1victory $did(321)
  setset team 2victory $did(322)
  setset team 3victory $did(323)
  setset team 4victory $did(324)
  setset team 4-team $did(29).state
  var %i = 1
  setset trivia ch $asc($right($did(961),1))
  %command-prefix = $left($did(850),1)
  disable.save
}
on *:dialog:trivset:sclick:12:{
  if ((!$did(34).sel) || (!$did(108).sel)) { return }
  var %todel = $did(34).sel
  did -d $dname 34 %todel
  did -c $dname 34 %todel
  save.qs
}
on *:dialog:trivset:sclick:24:{
  var %temp.file = $$sfile($iif($isdir($did(35)),$did(35),$mircdir))
  did -a $dname 34 $nopath(%temp.file)
  did -ra $dname 35 $nofile(%temp.file)
  save.qs
}
on *:dialog:trivset:edit:30:{
  var %temp.num = $did(108).sel
  tchan.set $did(108).sel 1 $did(30)
  did -o $dname 108 $did(108).sel $did(30)
  did -c $dname 108 %temp.num
}
on *:dialog:trivset:sclick:108:{ multichan.load }
on *:dialog:trivset:sclick:115:{ 
  var %toadd = $$?="Add what channel?"
  did -a $dname 108 %toadd
  chan.add %toadd
}
on *:dialog:trivset:sclick:119:{
  var %todel = $did(108).sel
  chan.del %todel
  did -d $dname 108 %todel
  did -c $dname 108 %todel
  did -r $dname 30,34,132
  multichan.load
}
on *:dialog:trivset:edit:132:{ tchan.set $$did(108).sel 4 $$did(132) }
on *:dialog:trivset:sclick:158,116:{ check.color.toggle }
on *:dialog:trivset:sclick:141:{
  did -ra $dname 132 $nopath($$sfile($mircdir $+ *.fil,Choose a scores file.))
  tchan.set $$did(108).sel 4 $did(132)
}
on *:dialog:trivset:sclick:148:{ check.toggle.ranks }
;########################################################
;# MOUSE EVENTS.                                        #
;########################################################
on *:dialog:trivset:mouse:40,41,42,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,88,96,817,830:{ 
  if (%didt == $did) { return }
  if ($did == 40) { exp Echo's the answer so that you can see it after the question is read. }
  if ($did == 60) { exp Uses the American dating style for the $pre $+ stats responce. MM/DD/YY rather than DD/MM/YY. }
  if ($did == 48) { exp Traditional win provides more less clinical information about the correct answer. }
  if ($did == 56) { exp Provides the spacing of the answer directly after the question is read. }
  if ($did == 46) { exp Gives a message to each person who joins the trivia channel, providing information about the bot. }
  if ($did == 50) { exp Rather than providing hidden notice message this makes all message responces to go directly to the channel. }
  if ($did == 53) { exp For scramble questions, this forces the standard scramble category to read Unscramble the Following. }
  if ($did == 57) { exp Rather than accept answers anywhere in a responce, this feature forces the bot to ignore answered contained entirely inside a responce. }
  if ($did == 49) { exp This feature makes the bot start up as soon as you rejoin the trivia channel. }
  if ($did == 42) { exp This allows for champ mode, when a specific score is reached the game resets the score and logs the winner. }
  if ($did == 54) { exp Much like Msg $pre $+ responces this feature only forces hint responces to be displayed in channel. }
  if ($did == 58) { exp Rather than start the hint from left to right it displays random letters in the hint. }
  if ($did == 41) { exp This feature automaticly displays a hint to the channel after a time specified in Defaults. }
  if ($did == 45) { exp This allows people to be told the correct answer after nobody in the room answered correctly. }
  if ($did == 55) { exp When a team game is ends this provides a list of players on each team. }
  if ($did == 59) { exp By default the bot displays the first answer in the answer file as correct. But, with this enabled the matched answer is displayed. }
  if ($did == 88) { exp After a specified number of questions, the bot will turn itself off. }
  if ($did == 96) { exp After a hint is requested this feature blocks the correct answer from being accepted from that person for a given amount of time. }
  if ($did == 47) { exp This allows for unfinished part of a hint to use a specific character to indicate where letters are missing. }
  if ($did == 51) { exp This option limits the number of guesses to the specific value. }
  if ($did == 52) { exp This option makes a round hall of fame displayed along with the win messages throughout a trivia round. }
  if ($did == 817) { exp Turns off the spell correction and only allows exact answers to be accepted. }
  if ($did == 830) { exp Turns off the automatic ? at the end of each question. A - at the end of the question also does this. }
  set -u5 %didt $did 
}
alias exp { did -ra $dname 22 $$1- }
;########################################################
;# Stray.                                               #
;########################################################
on *:dialog:trivset:sclick:20:{ if (!$dialog(trivrank)) dialog -m trivrank trivrank } 
on *:dialog:trivset:sclick:28,29:{
  trivset.teams $iif($did != 28,1)
}
on *:dialog:trivset:sclick:111,112,113,114:{ did -ra $dname $calc($did + 10) $calc($did($did).sel - 1) }
on *:dialog:trivset:sclick:218:{
  var %record = $calc($triv(Record) + 1)
  if (%record == 9) { var %record = 1 }
  did -ra $dname $did $record.type(%record)
  setset Trivia Record %record
}
;########################################################
;# Awards.                                              #
;########################################################
on *:dialog:trivset:sclick:412:{ did -a $dname 420 0 0 0 0 0 Award }
on *:dialog:trivset:sclick:411:{ did -d $dname 420 $$did(420,1).sel | check.awards.toggle }
alias check.awards.toggle { did $iif($did(420).sel,-e,-b) $dname 137,159,166,139,142,161,140,154,160,162,163,164,81,82 }
on *:dialog:trivset:sclick:420:{
  check.awards.toggle
  tokenize 32 $$did(420).seltext
  did -c $dname 137 $calc($1 + 1)
  did -c $dname 159 $calc($2 + 1)
  did -c $dname 166 $calc($3 + 1)
  did -ra $dname 139 $4
  did -ra $dname 161 $5
  did -ra $dname 142 $6-
  check.award.range
}
alias check.award.range {
  did $iif($did(159).seltext == Between,-v,-h) $dname 160,161
}
on *:dialog:trivset:sclick:137,159,166:{ award.modified }
on *:dialog:trivset:edit:139,142,161:{ award.modified }
alias award.modified {
  if (!$did(420).sel) { return }
  var %t.line = $did(420).sel
  did -o $dname 420 $did(420).sel $calc($did(137).sel - 1) $calc($did(159).sel - 1) $calc($did(166).sel - 1) $did(139) $did(161) $did(142)
  did -c $dname 420 %t.line
  check.award.range
}
;########################################################
;# Settings.                                            #
;########################################################
on *:dialog:trivset:sclick:515:{ if ($?!="Are you sure you wish to delete all scores?") { rename $scoresfil $asctime(yymmddhhmmss) $+ .bak } }
on *:dialog:trivset:sclick:518:{ run http://web.dreamsoft.com/tat/trivia.htm }
on *:dialog:trivset:sclick:519:{ dialog -m triviascores triviascores }
on *:dialog:trivset:sclick:602:{ 
  tunban $did(601,1).sel
  did -d $dname 601 $$did(601,1).sel
}
on *:dialog:trivset:sclick:603:{ 
  var %ban = $$?="Ban whom?"
  tban %ban
  did -a $dname 601 %ban
}
on *:dialog:trivset:sclick:611:{
  var %friend.add = $$?"In the format nick!ident@host specify friend to add, note wildcards are permitted."
  did -a $dname 610 %friend.add
  triviafriend.add %friend.add
}
on *:dialog:trivset:sclick:612:{
  triviafriend.del $$did(610).sel
  trivia.load.friends
}
on *:dialog:trivset:sclick:700:{ if (!$dialog(triviatheme)) { dialog -m triviatheme triviatheme } }
on *:dialog:trivset:sclick:157:{ if (!$dialog(trivbuild)) { dialog -m trivbuild trivbuild } }
;########################################################
;# TRIVIA SETUP, alias expanded.                        #
;########################################################
alias save.qs {
  var %i = 1
  tchan.noqs $$did(108).sel
  while (%i <= $did(34).lines) {
    tchan.set $did(108).sel $calc(4 + %i) $did(34,%i)
    inc %i
  }
}
alias status.toks { return echo.autohint.champ.oponlyon.oponlyoff.showanswer.onjoin.cross.tradwin.autostart.informc.oneguess.rrs.sayscramble.msghint.noshowt.answers.nomid.scatter.showmatched.adate }
alias chan.add { tchan.set $calc($setini(chan,0) + 1) 1 $1- }
alias chan.del {
  var %i = $$1, %j = $setini(chan,0)
  while (%i < %j) {
    setset chan %i $getset(chan,$calc(%i + 1))
    inc %i
  }
  setset chan %j
}
alias check.toggle.multichan { did $iif($did(108).sel,-e,-b) $dname 12,24,30,34,132,141 }
alias multichan.load {
  if (!$did(108).sel) { return }
  did -r $dname 34
  did -ra $dname 30 $tchan($did($did).sel)
  did -ra $dname 132 $tchan($did($did).sel,4)
  var %i = 5
  while ($tchan($did(108).sel, %i)) {
    did -a $dname 34 $tchan($did(108).sel,%i)
    inc %i
  }
  check.toggle.multichan
}
alias check.toggle.ranks { did $iif($did(148).state,-e,-b) $dname 20 }
alias awards.load {
  var %i = 1
  did -r $dname 420
  while ($aw(%i)) {
    did -a $dname 420 $aw(%i)
    inc %i
  }
  did -r $dname 137,159,166
  %i = 1
  while ($gettok($award.on.tok, %i, $asc(.))) {
    did -a $dname 137 $gettok($award.on.tok, %i, $asc(.))
    inc %i
  }
  %i = 1
  while ($gettok($award.val.tok, %i, $asc(.))) {
    did -a $dname 159 $gettok($award.val.tok, %i, $asc(.))
    inc %i
  } 
  %i = 1
  while ($gettok($award.do.tok, %i, $asc(.))) {
    did -a $dname 166 $gettok($award.do.tok, %i, $asc(.))
    inc %i
  }
}
alias disable.save {
  var %i = 801
  while (%i <= 831) {
    var %t = %t $+ $did(%i).state
    inc %i
  }
  setset status disables %t
}
alias disable.load {
  var %i = 1
  while (%i <= 31) {
    if ($isdis(%i)) { did -c $dname $calc(%i + 800) }
    inc %i
  }
}
alias -l record.type { return $gettok(hof.streak.time.wpm.champ.web.roundscores.records, $ifd($1, 8), $asc(.)) }
alias -l trivset.teams { did $iif($1, -e, -b) $dname 308,309,303,304,382,383,323,324 }
alias isdis { if ($mid($getset(status, disables), $1, 1) == 1) { return $true } }
alias check.color.toggle {
  did $iif($did(116).state,-e,-b) $dname 23,25,120,110,121,122,123,124,117,118,127,128,111,112,113,114
  if (!$did(158).state) did -b $dname 25,123,124,113,114
}
alias triviafriend.del {
  var %i = $$1, %j = $setini(friend,0)
  while (%i < %j) {
    setset friend %i $getset(friend,$calc(%i + 1))
    inc %i
  }
  setset friend %j
}
alias triviafriend.add {
  var %i = 1
  while ($getset(friend, %i)) { inc %i }
  setset friend %i $1- 
}
alias triviafriend.clear { setset friend }
alias trivia.load.friends {
  did -r $dname 610
  var %i = 1
  while ($getset(friend, %i)) {
    did -a $dname 610 $getset(friend, %i)
    inc %i
  }
}
;########################################################
;# TRIVIA RANKS DIALOG.                                 #
;########################################################
dialog trivrank {
  title "Trivia Ranks"
  size -1 -1 138 88
  option dbu
  list 1, 2 4 110 58, size
  text "Rank Name", 11, 4 66 31 8
  edit "", 2, 46 64 66 10, multi autohs
  text "Points Required", 10, 4 76 39 8
  edit "", 3, 46 76 36 10, multi autohs read
  button "Add", 4, 114 8 21 8
  button "Del", 5, 114 20 21 8
  button "Ok", 999, 114 78 17 8, ok
}
;########################################################
;# DIALOG EVENTS.                                       #
;########################################################
on *:dialog:trivrank:init:*:{
  var %i = $setini(ranks,0), %j = 1
  while (%j <= %i) {
    did -a $dname 1 $setini(ranks,%j) : $getset(ranks, $setini(ranks,%j)) 
    inc %j
  }
}
on *:dialog:trivrank:sclick:1:{
  did -ra $dname 3 $setini(ranks, $did(1).sel)
  did -ra $dname 2 $getset(ranks, $setini(ranks, $did(1).sel))
}
on *:dialog:trivrank:edit:2:{
  if (!$did(1).sel) return
  setset ranks $$did(3) $$did(2)
  var %p = $did(1).sel
  did -o $dname 1 %p $did(3) : $did(2)
  did -c $dname 1 %p
}
on *:dialog:trivrank:sclick:4:{
  var %r = $$?="What is the minimum amount points for this rank?"
  if ((%r !isnum) || ($getset(ranks,%r))) return
  var %n = $$?="What is this rank called?"
  setset ranks %r %n
  did -a $dname 1 %r : %n
}
on *:dialog:trivrank:sclick:5:{
  var %p = $$did(1).sel
  setset ranks $$setini(ranks, %p)
  did -d $dname 1 %p
  did -r $dname 2,3
}
;########################################################
;# TRIVIA BUILD DIALOG.                                 #
;########################################################
dialog trivbuild {
  title "Build Html"
  size -1 -1 280 104
  option dbu
  check Auto Update, 1, 180 4 50 10
  edit "", 2, 2 12 86 88, multi autovs autohs
  button Ok, 99, 240 92 23 10, ok
  radio Write All Scores, 3, 184 64 50 10
  radio Write Top, 4, 184 76 34 10
  edit 25, 5, 240 72 20 10
  box Scores Out, 57, 180 56 86 31
  text Password, 54, 96 52 25 8
  box Ftp Batch Creator, 55, 92 4 84 96
  text Username, 53, 96 40 25 8
  text Ftp Site, 51, 96 16 25 8
  edit "", 6, 128 16 46 10, multi autohs
  text Port, 52, 96 28 25 8
  edit "", 7, 128 28 46 10, multi autohs
  edit "", 8, 128 40 46 10, multi autohs
  edit "", 9, 128 52 46 10, multi autohs
  button "Generate", 10, 136 88 37 8
  edit "triv.htm", 11, 128 76 46 10, multi autohs
  text Filename, 56, 96 76 23 6
  text Every, 58, 212 44 17 6
  edit "", 13, 228 44 22 10, multi autohs
  text Points, 14, 252 44 17 6
  check Auto-Build, 15, 180 44 28 8, push
  button "Cancel", 12, 212 92 23 10, cancel
  text "Directory", 50, 96 64 25 8
  edit "", 16, 128 64 46 10
  check "Announce Update", 17, 180 16 54 10
  edit "", 18, 192 28 86 10, multi autohs
  text "URL", 20, 180 28 10 7
  text "Batch File", 21, 4 4 29 8
}
;########################################################
;# TRIVIA BUILD EVENTS.                                 #
;########################################################
on *:dialog:trivbuild:sclick:15:{ did $iif($did(15).state,-e,-b) $dname 13 }
on *:dialog:trivbuild:sclick:4:{ did -e $dname 5 }
on *:dialog:trivbuild:sclick:3:{ did -b $dname 5 }
on *:dialog:trivbuild:init:*:{
  if ($getset(build,auto)) { did -c $dname 1 }
  if ($getset(build,web)) {
    did -c $dname 17
    did -rea $dname 18 $getset(build,web)
  }
  if ($getset(build,instabuild)) {
    did -c $dname 15
    did -rea $dname 13 $getset(build,instabuild)
  }
  else { did -b $dname 13 }
  if ($getset(build,top)) {
    did -u $dname 3
    did -c $dname 4
    did -rea $dname 5 $getset(build,top)
  }
  else {
    did -c $dname 3
    did -u $dname 4
    did -rb $dname 5
  }
  if (!$exists($+(",$triv(dir),\,ftpbatch.txt,"))) { return }
  filter -fo $+(",$triv(dir),\,ftpbatch.txt,") $dname 2 *
  var %i = 1
  while ($did(2,%i)) {
    tokenize 32 $did(2,%i)
    if ($1 == open) { var %go = $true }
    elseif ((!$did(6)) && (%go)) {
      did -ra $dname 6 $1
      did -ra $dname 7 $2
    }
    elseif ((!$did(8)) && (%go)) { did -ra $dname 8 $1 }
    elseif ((!$did(9)) && (%go)) { did -ra $dname 9 $1 }
    elseif (($1 == cd) && (%go)) { did -ra $dname 16 $2 }
    elseif (($1 == put) && (%go)) { did -ra $dname 11 $nopath($2-) }
    inc %i
  }
}
on *:dialog:trivbuild:sclick:10:{
  if ((!$did(6)) || (!$did(8)) || (!$did(9)) || (!$did(11))) { return $input(You are missing vital data to generate batch.) }
  did -r $dname 2
  did -i $dname 2 $did(2).lines open
  did -i $dname 2 $did(2).lines $did(6) $did(7)
  did -i $dname 2 $did(2).lines $did(8)
  did -i $dname 2 $did(2).lines $did(9)
  if ($did(16)) { did -i $dname 2 $did(2).lines cd $did(16) }
  did -i $dname 2 $did(2).lines put $shortfn($mircdir $+ $did(11))
  did -i $dname 2 $did(2).lines bye
}
on *:dialog:trivbuild:sclick:99:{ 
  setset build auto $did(1).state
  setset build instabuild $iif($did(15).state, $did(13))
  setset build web $iif($did(17).state, $did(18))
  setset build top $iif((($did(4).state) && ($did(5))), $did(5))
  setset build html $did(11)
  if ($did(2)) { filter -ifc $dname 2 $+(",$triv(dir),\,ftpbatch.txt,") * }
}
;########################################################
;# TRIVIA THEMES DIALOG.                                #
;########################################################
dialog triviatheme {
  title Trivia Themes
  size -1 -1 500 360
  option pixels
  list 1, 26 12 300 116, sort hsbar
  button Add, 2, 346 12 50 20
  button Remove, 3, 346 42 50 20
  text Name:, 30, 26 146 100 20
  text File:, 31, 26 168 100 20
  text #Question: , 32, 26 190 100 20
  text Points per Question:, 33, 26 212 100 20
  text Hint-Point Decrease:, 34, 26 234 100 20
  edit , 11, 134 146 120 20, multi autohs
  edit , 12, 134 168 120 20, multi autohs
  edit , 13, 134 190 120 20, multi autohs
  edit , 14, 134 212 120 20, multi autohs
  edit , 15, 134 234 120 20, multi autohs
  check Team Game, 16, 22 274 100 20, push
  check One Guess, 17, 22 296 100 20, push
  check Roundscores, 18, 22 318 100 20, push
  box Lag, 35, 272 134 228 200
  text Before Start, 26, 282 154 96 20
  text Between Questions (Answered), 37, 282 184 96 28
  text Given to Answer, 38, 282 214 96 20
  text Before Auto-Hint, 39, 282 244 88 20
  text Between Question (Timed Out), 40, 282 274 88 28
  text Before ' $+ $pre $+ hint' allowed, 41, 282 304 104 20
  edit , 19, 404 154 80 20
  edit , 20, 404 184 80 20
  edit , 21, 404 214 80 20
  edit , 22, 404 244 80 20
  edit , 23, 404 274 80 20
  edit , 24, 404 304 80 20
  button OK, 999, 454 338 40 20, ok
}
;########################################################
;# TRIVIA THEMES EVENTS.                                #
;########################################################
on *:dialog:triviatheme:init:*:{
  var %i = 1
  while ($getset(triviamode $+ %i, name)) {
    did -a triviatheme 1 $+($getset(triviamode $+ %i, name),;,$getset(triviamode $+ %i, file),;,$getset(triviamode $+ %i, max),;,$getset(triviamode $+ %i, PPQ),;,$getset(triviamode $+ %i, DPH),;,$getset(triviamode $+ %i, team),;,$getset(triviamode $+ %i, guess),;,$getset(triviamode $+ %i, rrs),;,$getset(triviamode $+ %i, lagstart),;,$getset(triviamode $+ %i, laganswered),;,$getset(triviamode $+ %i, lagtimedout),;,$getset(triviamode $+ %i, laghint),;,$getset(triviamode $+ %i, lagtimed),;,$getset(triviamode $+ %i, laghintallow))
    inc %i
  }
}
on *:dialog:triviatheme:sclick:1:{
  did -ra triviatheme 11 $gettok($did(1).seltext, 1, $asc(;))
  did -ra triviatheme 12 $gettok($did(1).seltext, 2, $asc(;))
  did -ra triviatheme 13 $gettok($did(1).seltext, 3, $asc(;))
  did -ra triviatheme 14 $gettok($did(1).seltext, 4, $asc(;))
  did -ra triviatheme 15 $gettok($did(1).seltext, 5, $asc(;))
  did -u triviatheme 16,17,18
  if ($gettok($did(1).seltext, 6, $asc(;))) { did -c triviatheme 16 }
  if ($gettok($did(1).seltext, 7, $asc(;))) { did -c triviatheme 17 }
  if ($gettok($did(1).seltext, 8, $asc(;))) { did -c triviatheme 18 }
  did -ra triviatheme 19 $ifd($gettok($did(1).seltext, 9, $asc(;)),$slag(start))
  did -ra triviatheme 20 $ifd($gettok($did(1).seltext, 10, $asc(;)),$slag(answered))
  did -ra triviatheme 21 $ifd($gettok($did(1).seltext, 11, $asc(;)),$slag(timedout))
  did -ra triviatheme 22 $ifd($gettok($did(1).seltext, 12, $asc(;)),$slag(hint))
  did -ra triviatheme 23 $ifd($gettok($did(1).seltext, 13, $asc(;)),$slag(timed))
  did -ra triviatheme 24 $ifd($gettok($did(1).seltext, 14, $asc(;)),$slag(hintallow))
}
on *:dialog:triviatheme:sclick:2:{ did -a triviatheme 1 $+(Themename,;,questions.txt,;,10,;,1,;,0,;,0,;,0,;,0,;,$slag(start),;,$slag(answered),;,$slag(timedout),;,$slag(hint),;,$slag(timed),;,$slag(hintallow)) }
on *:dialog:triviatheme:sclick:3:{ did -d triviatheme 1 $did(1).sel }
on *:dialog:triviatheme:edit:11,12,13,14,15,19,20,21,22,23,24:{ triviatheme.update }
on *:dialog:triviatheme:sclick:16,17,18:{ triviatheme.update }
alias triviatheme.update { if ($did(1).sel) { did -oc triviatheme 1 $did(1).sel $+($did(11),;,$did(12),;,$did(13),;,$did(14),;,$did(15),;,$did(16).state,;,$did(17).state,;,$did(18).state,;,$did(19),;,$did(20),;,$did(21),;,$did(22),;,$did(23),;,$did(14)) } }
on *:dialog:triviatheme:sclick:999:{
  setset triviamode
  var %i = 1
  while ($did(1,%i).text) {
    setset triviamode $+ %i name $gettok($did(1, %i).text,1,59)
    setset triviamode $+ %i file $gettok($did(1, %i).text,2,59)
    setset triviamode $+ %i max $gettok($did(1, %i).text,3,59)
    setset triviamode $+ %i ppq $gettok($did(1, %i).text,4,59)
    setset triviamode $+ %i dph $gettok($did(1, %i).text,5,59)
    setset triviamode $+ %i team $gettok($did(1, %i).text,6,59)
    setset triviamode $+ %i guess $gettok($did(1, %i).text,7,59)
    setset triviamode $+ %i rrs $gettok($did(1, %i).text,8,59)
    setset triviamode $+ %i lagstart $gettok($did(1, %i).text,9,59)
    setset triviamode $+ %i laganswered $gettok($did(1, %i).text,10,59)
    setset triviamode $+ %i lagtimedout $gettok($did(1, %i).text,11,59)
    setset triviamode $+ %i laghint $gettok($did(1, %i).text,12,59)
    setset triviamode $+ %i lagtimed $gettok($did(1, %i).text,13,59)
    setset triviamode $+ %i laghintallow $gettok($did(1, %i).text,14,59)
    inc %i
  }
}
;########################################################
;# TRIVIA SCORES DIALOG.                                #
;########################################################
dialog triviascores {
  title Trivia Scores
  size -1 -1 500 300
  list                     1,   5  20 100 200, vsbar
  list                     2, 115  20  75 200, vsbar
  list                     3, 200  20  75 200, vsbar
  list                     4, 285  20  75 200, vsbar
  list                     5, 370  20  75 200, vsbar
  button Delete,        10,   5 225  75  20
  button Reset Score,   11, 115 225  75  20
  button Reset Streak,  12, 200 225  75  20
  button Reset Time,    13, 285 225  75  20
  button Reset WPM,     14, 370 225  75  20
  button Name,          20,   5   5  50  15
  button Score,         21, 115   5  50  15
  button Streak,        22, 200   5  50  15
  button Time,          23, 285   5  50  15
  button WPM,           24, 370   5  50  15
  button Ok,           100, 350 250  45  20,ok
}
;########################################################
;# TRIVIA SCORES EVENTS.                                #
;########################################################
on 1:dialog:triviascores:init:*: { sortscores score }
alias -l sortscores { 
  sort $1
  loaddata.triviascores
}
alias -l loaddata.triviascores {
  did -r $dname 1,2,3,4,5
  var %i = 1
  while ($hof(%i,1)) {
    did -a $dname 1 $hof(%i,1)
    did -a $dname 2 $hof(%i,2)
    did -a $dname 3 $hof(%i,4)
    did -a $dname 4 $hof(%i,3)
    did -a $dname 5 $hof(%i,5)
    inc %i
  }
}
on 1:dialog:triviascores:sclick:1,2,3,4,5:{ did -c $dname 1,2,3,4,5 $did($did).sel }
on 1:dialog:triviascores:sclick:20,21,22,23,24: { sortscores $gettok(name.score.streak.time.wpm, $calc($did - 19), $asc(.)) }
on 1:dialog:triviascores:sclick:10: {
  deleteplayer $did(1).seltext
  if ($did(1).sel) { did -d triviascores 1,2,3,4,5 $did(1).sel }
}
on 1:dialog:triviascores:sclick:11,12,13,14: {
  setvar $did(1).seltext $gettok(score.streak.time.wpm, $calc($did - 10), 46) $iif($did == 13, 9999, 0)
  if ($did(1).sel) { did -o triviascores $calc($did - 9) $did(1).sel 0 }
}
;triviaend