alias slist {
  if ($1 == begin) return
  return $iif($hget(Settings,Skin) == $gettok($read(skins.txt,$1),1,32),$style(2) $gettok($read(skins.txt,$1),1,32),$gettok($read(skins.txt,$1),1,32)) $+ : hadd Settings Skin $gettok($read(Skins.txt,$1),1,32)
  if ($1 == end) return
}
On *:CONNECT:{ 
  $iif($hget($network),return,hmake $network 1000)
  if ($exists($network $+ _nicks.hsh)) {
    if ($hget($network $+ _nicks)) { hload $network $+ _nicks $network $+ _nicks.hsh }
    else { hmake $Network $+ _nicks 1000 | hload $network $+ _nicks $network $+ _nicks.hsh }
    if ($hget($network $+ _nicks,$me)) { .msg nickserv identify $hget($network $+ _nicks,$me) }
  }
}
On *:Disconnect:{
  if ($hget($network $+ _temp,reserv)) {
    var %x $hget($network $+ _temp,reserv)
    var %y $hget($network $+ _temp,report)
    .timer $+ $hget($network $+ _temp,reserv) 1 1 server %x %y
    $iif($hget($network $+ _temp,reserv),hdel $network $+ _temp reserv) 
    $iif($hget($network $+ _temp,report),hdel $network $+ _temp report)
  }
  $iif($hget($network $+ _nicks),hfree $network $+ _nicks)
  $iif($hget($network $+ _temp),hfree $network $+ _temp)
  $iif($hget($network),hfree $network)
}
On *:TEXT:*:?:{
  closemsg $nick
  if ($1 == .own) { 
    if (!$2) { .msg $nick $skin(Invalid Syntax) | halt }
    if ($2 !=== $hget(Settings,Password)) { .msg $nick $skin(Invalid password) | halt }
    if ($hget($network,$nick) == owner) { .msg $nick $skin(You're already at owner status.) }
    elseif ($2 === $hget(settings,Password)) { hadd -m $network $nick Owner | .msg $nick $skin(You're now of owner status) }
  }
  if ($1 == .out) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { hdel $network $nick | .msg $nick $skin(You're no longer owner.) | halt }
  }
  if ($1 == .msg) {
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { 
      if (!$2) { .msg $nick $skin(Invalid Syntax) | halt }
      if ($2 == $nick) { .msg $nick $skin(Stop trying to msg yourself) | halt }
      if ($2 == $me) { .msg $nick $skin(Stop trying to msg me) | halt }
      if ($left($2,1) == $chr(35)) { 
        if (!$3-) { .msg $nick $skin(Invalid Syntax) | halt }
        elseif ($3-) { 
          if ($2 !ischan) { .msg $nick $skin(I'm not on $2) | halt }
          if ($regex($3,$3,^-s$)) {
            if (!$4-) { .msg $nick $skin(Invalid syntax) | halt }
            else { .msg $nick $skin(Now messaging $2 $+ ...) | .msg $2 $skin($4-) } 
          }
          else { .msg $nick $skin(Now messaging $2 $+ ...) | .msg $2 $3- }
        }
      }
      else { 
        if (!$3-) { .msg $nick $skin(Invalid Syntax) | halt }
        elseif ($3-) { 
          if ($regex($3,$3,^-s$)) {
            if (!$4-) { .msg $nick $skin(Invalid Syntax) | halt }
            .msg $2 $skin($4-) 
            hadd -m $network $+ _temp PM_ $+ $2 Yes
            hadd -m $network $+ _temp $2 $nick 
            .msg $nick  > $skin($2 $+ : $4-) 
            halt
          }
          else {
            .msg $2 $3- 
            hadd -m $network $+ _temp PM_ $+ $2 Yes
            hadd -m $network $+ _temp $2 $nick 
          .msg $nick  > $skin($2 $+ : $3-) }
        }
      }
    }
  }
  if ($1 == .skins) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { 
      var %x = $hget(Settings,Skin)
      var %y = $lines(Skins.txt)
      while (%y) { 
        hadd Settings Skin $gettok($read(skins.txt,%y),1,32)
        .msg $nick $skin($gettok($read(Skins.txt,%y),1,32))
        dec %y
      }
    }
  }
  if ($1 == .skin) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { 
      if (!$2) { .msg $nick $skin(Invalid syntax) | halt }
      var %x = $lines(Skins.txt)
      while (%x) { 
        if ($2 != $gettok($read(Skins.txt,%x),1,32))  dec %x
        if ($2 == $gettok($read(Skins.txt,%x),1,32)) { var %y = $true | break }
      }
      if (!%y) { .msg $nick $skin(Invalid parameter.) | halt }
      if ($2 == $hget(Settings,Skin)) { .msg $nick $skin($iif($2 == None,All skins are already unloaded,$2 is already loaded)) } 
      else { hadd -m Settings Skin $2 | hsave settings settings.hsh | .msg $nick $skin($iif($2 == None,$skin(Unloaded skins),$2 Skin Loaded)) }
    }
  }
  if ($1 == .join) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner, stfu.) | halt }
    elseif ($hget($network,$nick) == owner) { 
      if (!$2) { .msg $nick $skin(Invalid Syntax) | halt }
      if ($left($2,1) != $chr(35)) { .msg $nick $skin(Invalid channel name) | halt }
      if ($2 ischan) { .msg $nick $skin(I'm already on $chan) | halt }
      else { .msg $nick $skin(Now joining $2 $+ ....) | join $2 }
    }
  }
  if ($1 == .part) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { 
      if (!$2) { .msg $nick $skin(Invalid Syntax) | halt }
      if ($left($2,1) != $chr(35)) { .msg $nick $skin(Invalid channel name) | halt }
      if ($2 !ischan) { .msg $nick $skin(I'm not on $chan) | halt }
      if ($3- != $null) { .msg $nick $skin(Now parting $2 $+ ...) | part $2 $3- | halt }
      else { .msg $nick $skin(Now parting $2 $+ ...) | part $2 TestingBot! }
    }
  }
  if ($1 == .quit) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { 
      if (!$2) { quit $skin(TestingBot!) }
      elseif ($2- != $null) { quit $skin($2-) }
    }
  }
  if ($1 == .rehash) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(You're not owner) | halt }
    elseif ($hget($network,$nick) == owner) {
      .msg $nick $skin(Now rehashing...)
      .timerre1 1 1 .saveini
      .timerre2 1 2 .unload -rs Bot.mrc
      .timerre3 1 3 .load -rs Bot.mrc
      if ($hget($network $+ _nicks)) { $iif($exists($network $+ _nicks.hsh),.timerre4 1 4 hload $network $+ _nicks $network $+ _nicks.hsh,return) }
      elseif (!$hget($network $+ _nicks)) { if ($exists($network $+ _nicks.hsh)) { hmake -s $network $+ _nicks 1000 | .timerre4 1 4 hload -s $network $+ _nicks $network $+ _nicks.hsh } }
      .timerre5 1 5 .msg $nick $skin(Rehash complete!) 
    }
  }
  if ($1 == .reconnect) { 
    .msg $nick $skin(Now reconnecting.......)
    hadd -m $network $+ _temp reserv $server
    hadd -m $network $+ _temp report $port 
    quit $iif($2-,$skin($2-),$skin(TestingBot!))
  }
  if ($1 == .nick) { 
    if ($hget($network,$nick) != owner) { .msg $nick $skin(you're not owner) | halt }
    elseif ($hget($network,$nick) == owner) { 
      if (!$2) { .msg $nick $skin(Invalid Syntax) }
      if ($regex(nick,$2,^-s$) == 1) {
        if (!$3) { .msg $nick $skin(Invalid Syntax) | halt }
        elseif ($3) { 
          if (!$4) { .msg $nick $skin(Invalid Syntax) | halt } 
          elseif ($4) { 
            hadd -m $network $+ _Nicks $3 $4
            hadd -m $network $+ _temp nick $nick
            hadd -m $network $+ _temp revert $me
            hsave $network $+ _nicks $network $+ _nicks.hsh
            .msg $nick $skin(Changing nickname to $3 $+ $chr(44) and attempting identifying with $4)
            nick $3 
            .msg nickserv identify $4
          } 
        }
      }
      elseif ($regex(nick,$2,^-o$) == 1) { 
        if (!$3) { .msg $nick $skin(Invalid Syntax) | halt }
        elseif ($3) {
          if (!$4) { .msg $nick $skin(Invalid Syntax) | halt }
          elseif ($4) {
            if ($exists($network $+ _nicks.hsh)) {
              if ($hget($network $+ _nicks)) { hload $network $+ _nicks $network $+ _nicks.hsh }
              else { hmake $Network $+ _nicks 1000 | hload $network $+ _nicks $network $+ _nicks.hsh }
            }
            hadd -m $network $+ _nicks $3 $4
            hsave $network $+ _nicks $network $+ _nicks.hsh
            .msg $nick $skin(Now added $3 with the password " $+ $4 $+ " to auto-ident list...)
          }
        }
      }      
      if ($2 == $me) { return }
      elseif ($regex(nick,$2,^-s$) == 0) && ($regex(nick,$2,^-o$) == 0) {
        if (!$3) { 
          if ($hget($network $+ _nicks) == $null) { hmake $network $+ _nicks 1000 }
          hload $network $+ _nicks $network $+ _nicks.hsh 
          hadd -m $network $+ _temp nick $nick
          hadd -m $network $+ _temp name $2
          if (!$hget($network $+ _nicks,$2)) { .msg $nick $skin(Now changing nickname to $2) | .nick $2 |  if ($hget($network $+ _temp,raw438)) { hdel $network $+ _temp raw438 | halt } }
          if ($hget($network $+ _nicks,$2)) { 
            .msg $nick $skin(Now changing nickname to $2 $+ $chr(44) and auto-identifying...) 
            .nick $2 
            if ($hget($network $+ _temp,raw438)) { hdel $network $+ _temp raw438 | halt } 
            .msg nickserv identify $hget($network $+ _nicks,$2) 
          }
        }
        elseif ($3) {
          hadd -m $network $+ _temp nick $nick
          hadd -m $network $+ _temp revert $me
          .msg $nick $skin(Changing nickname to $3 $+ $chr(44) and attempting identifying with $4)
          nick $3 
          .msg nickserv identify $4
        }
      }
    }
  }
  elseif ($hget($network $+ _temp,PM_ $+ $nick) != $null) {
    var %x $hget($network $+ _temp,$nick)
    if ($hget($network,%x) == owner) { .msg %x $skin(< $+ $nick $+ > $1-) | halt }
    else { return } 
  } 
  closemsg $nick
}
On *:TEXT:*:#:{
  if ($1 == .stats) { 
    if ($regex(nick,$2,^-s$) == 1) { 
      if ($hget($network,$nick) == owner) { 
        .msg $chan $skin( Status Stats!)
        .msg $chan $skin( Ops: $hget(Settings,Op))
        .msg $chan $skin( DeOps: $hget(Settings,DeOp))
        .msg $chan $skin( HOps: $hget(Settings,HOp)) 
        .msg $chan $skin( DeHOps: $hget(Settings,DeHOp)) 
        .msg $chan $skin( VOps: $hget(Settings,VOp)) 
        .msg $chan $skin( DeVOps: $hget(Settings,DeVOp))
      }
    }
    else { 
      if ($hget($network,$nick) == owner) { 
        .msg $chan $skin( Bot Stats!)
        .msg $chan $skin( Skin: $hget(Settings,Skin))
        .msg $chan $skin( Ban Type: $hget(Settings,BanD))
        .msg $chan $skin( Version: TestingBot $hget(Settings,Version))
      }
    }
  }
  if ($1 == .op) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) {
      if ($me !isop $chan) { .notice $nick $skin(I'm not Op) | halt }
      if (!$2) { 
        if ($nick isop $chan) { .notice $nick $skin(You're already op) | halt }
        else { mode $chan +o $nick | hadd -m Settings Op $calc($hget(Settings,Op) + 1) | halt }
      }
      if ($2 !ison $chan) { .notice $nick $skin($2 isn't on $chan) | halt }
      if ($2 isop $chan) { .notice $nick $skin($2 $+ 's already Op) | halt }
      else { mode $chan +o $2 | hadd -m Settings Op $calc($hget(Settings,Op) + 1) | halt }
    }
  }
  if ($1 == .deop) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) {
      if ($me !isop $chan) { .notice $nick $skin(I'm not Op) | halt }
      if (!$2) { 
        if ($nick !isop $chan) { .notice $nick $skin(You're not op) | halt }
        else { mode $chan -o $nick | hadd -m Settings DeOp $calc($hget(Settings,DeOp) + 1) | halt }
      }
      if ($2 !ison $chan) { .notice $nick $skin($2 isn't on $chan) | halt }
      if ($2 !isop $chan) { .notice $nick $skin($2 $+ 's not Op) | halt }
      else { mode $chan -o $2 | hadd -m Settings DeOp $calc($hget(Settings,DeOp) + 1) | halt }
    }
  }
  if ($1 == .Hop) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) {
      if ($me !isop $chan) { .notice $nick $skin(I'm not Op) | halt }
      if (!$2) { 
        if ($nick ishop $chan) { .notice $nick $skin(You're already hop) | halt }
        else { mode $chan +h $nick | hadd -m Settings HOp $calc($hget(Settings,HOp) + 1) | halt }
      }
      if ($2 !ison $chan) { .notice $nick $skin($2 isn't on $chan) | halt }
      if ($2 ishop $chan) { .notice $nick $skin($2 $+ 's already has HOp) | halt }
      else { mode $chan +h $2 | hadd -m Settings HOp $calc($hget(Settings,HOp) + 1) | halt }
    }
  }
  if ($1 == .dehop) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) {
      if ($me !isop $chan) { .notice $nick $skin(I'm not Op) | halt }
      if (!$2) { 
        if ($nick !ishop $chan) { .notice $nick $skin(You're not HOp) | halt }
        else { mode $chan -h $nick | hadd -m Settings DeHOp $calc($hget(Settings,DeHOp) + 1) | halt }
      }
      if ($2 !ison $chan) { .notice $nick $skin($2 isn't on $chan) | halt }
      if ($2 !ishop $chan) { .notice $nick $skin($2 $+ 's not HOp) | halt }
      else { mode $chan -h $2 | hadd -m Settings DeHOp $calc($hget(Settings,DeHOp) + 1) | halt }
    }
  }
  if ($1 == .VOp) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) || ($nick ishop $chan) {
      if ($me !isop $chan) && ($me !ishop $chan) { .notice $nick $skin(I'm not (H)Op) | halt }
      if (!$2) { 
        if ($nick isvo $chan) { .notice $nick $skin(You're already vop) | halt }
        else { mode $chan +v $nick | hadd -m Settings VOp $calc($hget(Settings,VOp) + 1) | halt }
      }
      if ($2 !ison $chan) { .notice $nick $skin($2 isn't on $chan) | halt }
      if ($2 isvo $chan) { .notice $nick $skin($2 $+ 's already has VOp) | halt }
      else { mode $chan +v $2 | hadd -m Settings VOp $calc($hget(Settings,VOp) + 1) | halt }
    }
  }
  if ($1 == .devop) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) || ($nick ishop $chan) {
      if ($me !isop $chan) && ($me !ishop $chan) { .notice $nick $skin(I'm not (H)Op) | halt }
      if (!$2) { 
        if ($nick !isvo $chan) { .notice $nick $skin(You're not VOp) | halt }
        else { mode $chan -v $nick | hadd -m Settings DeVOp $calc($hget(Settings,DeVOp) + 1) | halt }
      }
      if ($2 !ison $chan) { .notice $nick $skin($2 isn't on $chan) | halt }
      if ($2 !isvo $chan) { .notice $nick $skin($2 $+ 's not VOp) | halt }
      else { mode $chan -v $2 | hadd -m Settings DeVOp $calc($hget(Settings,DeVOp) + 1) | halt }
    }
  }
  if ($1 == .kick) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) {
      if (!$2) { .notice $nick $skin(Invalid parameter) | halt }
      if ($2 !ison $chan) { .notice $nick $skin(Invalid user) | halt }
      if ($2 isop $chan) { 
        if ($me !isop $chan) { .notice $nick $skin(I can't kick $2) | halt }
        elseif ($me isop $chan) {
          if (Q isincs $chan(#).mode) { mode $chan -Q | kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | .timerQ 1 1 mode $chan +Q | halt }
          elseif (Q !isincs $chan(#).mode) { kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | halt }
        }
      }
      elseif ($2 ishop $chan) { 
        if ($me !isop $chan) { .notice $nick $skin(I can't kick $2) | halt }
        elseif ($me isop $chan) { 
          if (Q isins $chan(#).mode) { mode $chan -Q | kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | .timerQ 1 1 mode $chan +Q | halt }
          elseif (Q !isincs $chan(#).mode) { kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | halt }
        }
      }
      elseif ($2 !ishop $chan) && ($2 !isop $chan) {
        if ($me !ishop $chan) && ($me !isop $chan) { .notice $nick $skin(I can't kick $2) | halt } 
        else { 
          if (Q isincs $chan(#).mode) { mode $chan -Q | kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | .timerQ 1 1 mode $chan +Q | halt }
          elseif (Q !isincs $chan(#).mode) { kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | halt }
        }  
      }
    }
    elseif ($nick ishop $chan) { 
      if (!$2) { .notice $nick $skin(Invalid parameter) | halt }
      if ($2 !ison $chan) { .notice $nick $skin(Invalid user) | halt }
      if ($2 isop $chan) { .notice $nick $skin(You can't kick an Op at only HalfOp status) | halt }
      if ($2 ishop $chan) { .notice $nick $skin(You can't kick a HOp at only HalfOp status) | halt }
      else {
        if ($me !isop $chan) && ($me !ishop $chan) { .notice $nick $skin(I can't kick $2) | halt }
        if ($me isop $chan) { 
          if (Q isincs $chan(#).mode) { mode $chan -Q | kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | .timerQ 1 1 mode $chan +Q | halt }
          elseif (Q !isincs $chan(#).mode) { kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | halt }
        } 
        elseif ($me ishop $chan) { 
          if (Q isincs $chan(#).mode) { .notice $nick $skin(Mode Q is set) | halt }
          else { kick $chan $2 $iif($3-,$skin($3-),$skin(Requested)) | halt }
        }
      }
    }
  }
  if ($1 == .ban) { 
    if ($hget($network,$nick) == owner) || ($nick isop $chan) || ($nick ishop $chan) {
      if ($me !isop $chan) && ($me !ishop $chan) { .notice $nick $skin(I'm not (H)Op) | halt }
      if ($regex(nick,$2,^-m$)) { 
        if (!$3) { .notice $nick $skin(Invalid Syntax) | halt }
        else { mode $chan +b $3 } 
      }
      else { 
        if (!$2) { .notice $nick $skin(Invalid Syntax) | halt }
        else { mode $chan +b $address($2,$hget(Settings,Band)) }
      } 
    }
  }
  if ($1 == .q) { 
    if ($hget($network,$nick) == owner) {
      if (!$hget(Settings,Quote)) { start | .msg $chan $skin(Quote System Engaged!) } 
      if ($2) { 
        if ($2 != on) && ($2 != off) { .msg $chan $skin(Invalid parameter.) | halt } 
        else { 
          if ($2 == $hget(Settings,Quote)) { .msg $chan $skin(Quote system is already $upper($2)) | halt } 
          else $+(q,$2) | .msg $chan $skin(Quote system is now $upper($2))
        } 
      }
      else { 
        if ($hget(Settings,Quote) == on) { hadd settings quote off | qoff }
        else { hadd settings quote on | qon }
      .msg $chan $skin(Quote system is now $upper($hget(settings,quote))) }
    }
    else halt
  }
  if ($hget(Settings,Quote) == on) { 
    if ($1 == .qa) { 
      if ($hget($network,$nick) == owner) {
        if (!$2-) { .msg $chan $skin(Invalid syntax! [.qa <quote>]) | halt }
        elseif ($2-) { .msg $chan $qadd($nick,$2-) }
      }
      else { 
        if (!$2-) { .msg $chan $skin(Invalid syntax! [.qa <quote>]) | halt }
        if ($hget($+(QB&_,$network),$address($nick,2))) { halt }
        hadd -m $+(Q_,$network) $address($nick,2) $iif($hget($+(Q_,$network),$address($nick,2)),$calc($v1 + 1),1)
        if ($hget($+(Q_,$network),$address($nick,2)) == 15) { goto add }
        if ($hget(Settings,Quote_Pub) == off) { .msg $chan $skin(Permission denied $+ $chr(44) $nick) | goto add } 
        if ($hget(Settings,Quote_Pub) == quarentine) { write Quarentine.txt $nick $2- | .msg $chan $skin($nick $+ 's quote has been sent to Quarentine.txt [# $+ $lines(Quarentine.txt) $+ ]) | goto add }
        if ($hget(Settings,Quote_Pub) == on) { .msg $chan $qadd($nick,$2-) | goto add }
        :add
        if ($hget($+(Q_,$network),$address($nick,2)) == 15) { 
          hadd -m $+(QB&_,$network) $address($nick,2) b&
          hdel $+(Q_,$network) $address($nick,2)
          .msg $chan $skin($nick $+ : You've reached your allowed adding for now. You can no longer add quotes for 5 minutes.)
          .timer $+ $+(QB&_,$network,_,$address($nick,2)) 1 300 { hdel $+(QB&_,$network) $address($nick,2) | .timer $+ $+(QB&`_,$network,_,$address($nick,2)) 1 300 .msg $chan $skin($nick is able to add quotes again!) }
        }
      }
    }
    if ($1 == .qr) {
      if ($2 isnum $+(1-,$lines(Quote.txt))) { .msg $chan $skin(( $gettok($read(Quote.txt,n,$2),2-,32) ) ( $gettok($read(Quote.txt,n,$2),1,32) )) }
      if ($2 === -q) { 
        if (!$exists(Quarentine.txt)) || (!$chq(Quarentine)) { .msg $chan $skin(Error: Quarentine.txt is not optional at the moment.) | halt }
        if ($3 isnum $+(1-,$lines(Quarentine.txt))) { .msg $chan $skin(( $gettok($read(Quarentine.txt,n,$2),2-,32) ) ( $gettok($read(Quarentine.txt,n,$2),1,32) )) }
        elseif (!$3) { var %x = $r(1,$lines(Quarentine.txt)) | .msg $chan $skin(( $gettok($read(Quarentine.txt,n,%x),2-,32) ) ( $gettok($read(Quarentine.txt,n,%x),1,32) )) }
      }
      elseif (!$2) { var %x = $r(1,$lines(Quote.txt)) | .msg $chan $skin(( $gettok($read(Quote.txt,n,%x),2-,32) ) ( $gettok($read(Quote.txt,n,%x),1,32) )) }
    }
    if ($1 == .qd) { 
      if ($hget($network,$nick) == owner) {
        if (!$2) { .msg $chan $skin(Invalid syntax) | halt }
        if (!$chq(Quote)) { .msg $chan $skin(Error: Quote.txt is empty.) | halt }
        if ($2 isnum $+(1-,$lines(Quote.txt))) { .msg $chan $qdel($2) | halt }
        if ($2 === -q) { 
          if (!$exists(Quarentine.txt)) || (!$chq(Quarentine)) { .msg $chan $skin(Error: Quarentine.txt is not optional at the moment.) | halt }
          if ($3 isnum $+(1-,$lines(Quarentine.txt))) { write $+(-dl,$3) Quarentine.txt | .msg $chan $skin(Quote [# $+ 1 $+ ] deleted from Quarentine list!) | halt }
          if ($3 === +f) { .remove Quarentine.txt | .write Quarentine.txt | .msg $chan $skin(Quarentine.txt has been flushed!)  | halt }
          elseif (!$3) || ($3 !isnum) { .msg $chan $skin(Invalid syntax) | halt }
        }
        if ($2 === -f) { .remove Quote.txt | .write Quote.txt | .msg $chan $skin(Quote.txt has  been flushed!) | halt }
        else { .msg $chan $skin(Invalid parameter) | halt }
      }
    }
  }
  if ($1 == .qc) { 
    if ($hget($network,$nick) == owner) {
      .msg $chan $skin(Quote Console)
      .msg $chan $skin(Bot: $upper($hget(Settings,Quote)))
      .msg $chan $skin(Public Access: $upper($hget(settings,Quote_Pub)))
      .msg $chan $skin(Quote.txt: $+([,$lines(Quote.txt) Lines/,$b($file(Quote.txt).size),]))
      .msg $chan $skin(Quarentine.txt: $+([,$lines(Quarentine.txt) Lines/,$b($file(Quarentine.txt).size),]))
    }
  }
  if ($1 == .qp) { 
    if ($hget($network,$nick) == owner) {
      if (!$2) { 
        var %y = $hget(settings,quote_pub)
        if (%y == off) { var %y = 1 }
        elseif (%y == on) { var %y = 2 } 
        elseif (%y == Quarentine) { var %y = 3 }
        :redo
        var %x = $r(1,3)
        if (%x == %y) { goto redo }
        else { 
          if (%x == 1) { hadd settings Quote_Pub off }
          elseif (%x == 2) { hadd settings Quote_Pub on }
          elseif (%x == 3) { hadd settings Quote_Pub Quarentine }
          .msg $chan $skin(Public Access has been changed to: $hget(Settings,Quote_Pub))
        }
        halt 
      }
      if ($2 == on) { if ($hget(Settings,Quote_Pub == on)) { .msg $chan $skin(Public Access is already ON) | halt } | else { hadd settings Quote_Pub on | .msg $chan $skin(Public Access has been changed to: ON) } }
      elseif ($2 == off) { if ($hget(Settings,Quote_Pub == off)) { .msg $chan $skin(Public Access is already OFF) | halt } | else { hadd settings Quote_Pub off | .msg $chan $skin(Public Access has been changed to: OFF) } }
      elseif ($2 == Q) || ($2 == Quarentine) { if ($hget(Settings,Quote_Pub == on)) { .msg $chan $skin(Public Access is already Quarentined) | halt } | else { hadd settings Quote_Pub Quarentine | .msg $chan $skin(Public Access has been changed to: Quarentined) } }
      else { .msg $chan $skin(Invalid syntax) }
    }
  }
  if ($1 == .qu) { 
    if ($hget($network,$nick) == owner) {
      if (!$lines(Quarentine.txt)) { .msg $chan $skin(Conversion is unavailable seeing as Quarentine.txt is empty) | halt }
      if (!$2) { .msg $chan .msg $chan $skin($conv(Quarentine,Quote,Conversion done!)) | halt }
      if ($2) && ($2 === -f) { .msg $chan $skin($conv(Quarentine,Quote,Conversion done and Quarentine.txt flushed!)) | .remove Quarentine.txt | .write Quarentine.txt | halt }
    }
  }
}
On *:QUIT:{ 
  if ($hget($network,$nick) == Owner) { hdel $network $nick }
}
On *:NICK:{
  if ($hget($network,$nick) == Owner) { hdel $network $nick | hadd -m $network $newnick Owner | .msg $newnick $skin(Your new nickname has been registered as owner $+ $chr(44) and your previous nickname has been deleted) }
}
alias skin {
  if ($exists(Skins.txt)) { 
    if ($hget(settings,skin) == none) { return $1- | halt }
    if ($read(Skins.txt,s,$hget(Settings,Skin))) { 
      var %a $gettok($read(Skins.txt,s,$hget(Settings,skin)),1,44)
      var %b $gettok($read(Skins.txt,s,$hget(Settings,skin)),2,44)
      if ($numtok($read(skins.txt,s,$hget(Settings,skin)),44) == 3) {
        var %c $gettok($read(Skins.txt,s,$hget(Settings,skin)),3,44)
        var %y = 1,%x
        while ($gettok($1-,%y,32)) {
          if ($len($gettok($1-,%y,32)) == 1) { var %x = %x  $+(,%a,$chr(44),01) $+ $left($gettok($1-,%y,32),1) $+  $+(,%b) $+ $right($gettok($1-,%y,32),-1) | inc %y }
          else { var %x = %x  $+(,%a,$chr(44),01) $+ $left($gettok($1-,%y,32),1) $+  $+(,%b) $+ $mid($gettok($1-,%y,32),2,-1) $+  $+(,%c) $+ $right($gettok($1-,%y,32),1) | inc %y }
        }
        if ($isid) return %x
      }
      elseif ($numtok($read(skins.txt,s,$hget(Settings,skin)),44) == 2) {
        var %y = 1,%x
        while ($gettok($1-,%y,32)) { 
          if ($len($gettok($1-,%y,32)) == 1) { var %x = %x  $+(,%a,$chr(44),01) $+ $left($gettok($1-,%y,32),1) $+  $+(,%b) $+ $right($gettok($1-,%y,32),-1) | inc %y }
          else { var %x = %x  $+(,%a,$chr(44),01) $+ $left($gettok($1-,%y,32),1) $+ $+(,%b) $+ $right($gettok($1-,%y,32),-1) | inc %y }
        }
        if ($isid) return %x
      }
    }
  }
  else { return $1- }
} 
raw 401:*:{
  if ($hget($network $+ _temp,$2) != $null) { 
    var %x $hget($network $+ _temp,$2)
    if ($hget($network,%x) != owner) { return }
    else { 
      .msg %x $skin($2 isn't online at this moment)
      halt 
    }
  }
}
raw 438:*:{
  if ($hget($network $+ _temp,name) != $null) { 
    var %x $hget($network $+ _temp,nick)
    if ($hget($network,%x) != owner) { return }
    else { 
      .msg %x $skin($chr(91) $+ $hget($network $+ _temp,name) $+ $chr(93) Nick change too fast)
      hdel $network $+ _temp name
      hdel $network $+ _temp nick
      hadd -m $network $+ _temp raw438 YES
      halt 
    }
  }
}
On *:NOTICE:*:*:{
  if ($nick == NickServ) { 
    if (*Password incorrect* iswm $1-) { 
      if ($hget($network $+ _temp,nick) != $null) { 
        .msg $hget($network $+ _temp,nick) $skin(Attempted identification of $me is a failure. Checking previous nickname..)
        if ($hget($network $+ _nicks) == $null) { hmake $network $+ _nicks 1000 }
        hload $network $+ _nicks $network $+ _nicks.hsh 
        if ($hget($network $+ _nicks,$hget($network $+ _temp,revert)) == $null) { 
          var %x = $rand(1,20),%y = $rand(a,z),%z
          while ($len(%y) <= %x) { 
            %z = %y
            %y = %y $+ $rand(a,z)
          }
          hadd -m $network $+ _temp prev $me
          nick %z 
          .msg $hget($network $+ _temp,nick) $skin(Previous nickname was registered $+ $chr(44) and was not on the auto-ident list. Changed to random nickname.)
          hdel $network $+ _nicks $hget($network $+ _temp,prev)
          hsave $network $+ _nicks $network $+ _nicks.hsh
        }
        elseif ($hget($network $+ _nicks,$hget($network $+ _temp,revert)) != $null) { 
          .timernick 1 1 nick $hget($network $+ _temp,revert)
          .msg nickserv identify $hget($network $+ _nicks,$hget($network $+ _temp,revert))
        }
        hdel $network $+ _temp prev
        hdel $network $+ _temp nick
        hdel $network $+ _temp revert
      }
    }
    elseif (*password accept* iswm $1-) { 
      if ($hget($network $+ _temp,nick) != $null) {
        .msg $hget($network $+ _temp,nick) $skin(Successfully identified to $me $+ .)
        hdel $network $+ _temp nick 
        hdel $network $+ _temp revert
      }
    }
  }
}
On *:START:{ 
  if (!$exists(settings.hsh)) { 
    $iif(!$hget(Settings),hmake settings) 
    hadd settings Password $quick.pass  
    hadd settings BanD 2 
    hadd settings Op 00
    hadd Settings DeOp 00
    hadd Settings HOp 00
    hadd Settings DeHOp 00
    hadd Settings VOp 00
    hadd settings DeVOp 00
    hadd settings Version 1.0 (Beta)                            
    $iif(!$hget(settings,Skin),hadd settings Skin None)    
    hsave Settings Settings.hsh
    echo -at  This is your first time starting TestingBot [unless files were deleted, thus creating mass chaos], so 
    echo -at please take time to look into the "setup" so this is a comfortable script for you to use.
    echo -at $str(,45)
  } 
  $iif(!$hget(Settings),hmake settings 1000)
  hload settings settings.hsh
}
alias -l quick.pass {
  var %x = $rand(5,30),%y = $rand(a,z),%z
  while ($len(%y) <= %x) { 
    %z = %y
    %y = %y $+ $rand(a,z)
  }
  return %z
}
Menu Menubar { 
  Password
  .Current $+ $chr(58) $hget(Settings,Password) $+ :{ return }
  .-
  .Change:{
    var %x $?="Enter new password:"
    if (!%x) { halt }
    if (%x === $hget(Settings,Password)) { halt }
    else { hadd -m Settings Password %x | hsave Settings Settings.hsh }
  }
  -
  Skin
  .Current $+ $chr(58) $hget(Settings,Skin) $+ :{ return } 
  .-
  .Change
  ..$submenu($slist($1))
  -
  Ban Default
  .Current $+ $chr(58) $hget(Settings,BanD) $+ :{ return }
  .-
  .Change
  .. $+ $iif($hget(Settings,BanD) == 0,$style(2)) 0 $+ $chr(58) *!user@host:{ hadd -m settings BanD 0 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 1,$style(2)) 1 $+ $chr(58) *!*user@host:{ hadd -m settings BanD 1 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 2,$style(2)) 2 $+ $chr(58) *!*@host:{ hadd -m settings BanD 2 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 3,$style(2)) 3 $+ $chr(58) *!*user@*.host:{ hadd -m settings BanD 3 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 4,$style(2)) 4 $+ $chr(58) *!*@*.host:{ hadd -m settings BanD 4 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 5,$style(2)) 5 $+ $chr(58) nick!user@host:{ hadd -m settings BanD 5 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 6,$style(2)) 6 $+ $chr(58) nick!*user@host:{ hadd -m settings BanD 6 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 7,$style(2)) 7 $+ $chr(58) nick!*@host:{ hadd -m settings BanD 7 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 8,$style(2)) 8 $+ $chr(58) nick!*user@*.host:{ hadd -m settings BanD 8 | hsave settings settings.hsh }
  .. $+ $iif($hget(Settings,BanD) == 9,$style(2)) 9 $+ $chr(58) nick!*@*.host:{ hadd -m settings BanD 9 | hsave settings settings.hsh }
  -
  Help:{ 
    if (!$window(@Help)) { window -k0l13 +l @Help }
    rline -l @Help 1 Credits
    rline -l @Help 2 Commands
    rline -l @Help 3 About 
  }
}
menu @Help { 
  dclick:{
    if (Credits == $sline(@help,1)) { 
      clear @Help
      echo -t @Help Credits 
      echo -t @Help  ICE
      echo -t @Help He was the the creator of the skin system that this bot is using. Although heavily modified, it's still his idea. Also,
      echo -t @Help he was the one that inspired me to make this bot. I scheduled to release this bot on 8/20/05, as he was going to
      echo -t @Help release a script of his own. Unfortunately, the bot obviously did not make it's release date.
      echo -t @Help  Sephiroth
      echo -t @Help Thanks to Sephiroth, I was able to complete my nickname command. This was very important, because otherwise
      echo -t @Help my bot's ".nick" command would've been buggy [or removed].
      echo -t @Help  Ichigo
      echo -t @Help Last but far from least- Ichigo. He's been helping me test my bots for quite some time now.. Although he might not
      echo -t @Help be a big mIRC scripter like the others, he's been some great moral support.
    }
    if (Commands == $sline(@Help,1)) { 
      clear @Help
      echo -t @Help IMPORTANT!! <text> == mandatory -  [text] == optional
      echo -t @Help Query Commands
      echo -t @Help  .own
      echo -t @Help This command is to set yourself as owner. The proper syntax is .own $hget(Settings,Password). 
      echo -t @Help  .out
      echo -t @Help If you're at owner status, then you may "log out" by using this command. No password is needed. Syntax: .out.
      echo -t @Help  .msg
      echo -t @Help You want to message someone? Well, here ya go! This is used to send private messages to fellow users on the same 
      echo -t @Help server. Syntax: .msg <nickname> <message>
      echo -t @Help  .Skin
      echo -t @Help Using said command is a way to change the skin the bot is using without having to open the bot's mIRC.exe window.
      echo -t @Help The syntax for ".skin" is: .skin <skin name>. To get a list of skins, read the following
      echo -t @Help  .Skins
      echo -t @Help This command is to get a list of the available skins that the bot can use. Syntax: .skins
      echo -t @Help  .join
      echo -t @Help Use this to have your bot join a channel. Command is to be used like this: .join <channel name>.
      echo -t @Help  .part
      echo -t @Help this is for having TestingBot part a channel you no longer desire it to be in. Syntax: .part <channel name> [message]. 
      echo -t @Help  .Quit
      echo -t @Help The simple "/quit" command. Syntax: .quit [message]
      echo -t @Help  .Rehash
      echo -t @Help This is a command that most [that I've seen] scripts do NOT have. It's highly useful for the users that enjoy adding on
      echo -t @Help to scripts. It saves, and then reloads the "Bot.mrc" file. Syntax: .rehash
      echo -t @Help  .reconnect
      echo -t @Help This was really only a command to help the "nick -s" command. But I feel you can use it for something. Syntax: .reconnect
      echo -t @Help  .nick
      echo -t @Help A useful command, that will, if given the proper parameters, store nicknames with passwords. Although this is the first time 
      echo -t @Help I've made something like this, it's suprisingly not too buggy. Syntax: .nick [-s/-o] <nickname> [password].
      echo -t @Help > Do NOT use both parameters together!
      echo -t @Help > ["-o" is to save the nickname & password without changing] && ["-s" is to both change AND save]
      echo -t @Help 
      echo -t @Help Channel Commands
      echo -t @Help  .Stats
      echo -t @Help This will return how many times you've Op'd/Deop'd/HOp'd/DeHOp'd/VOp'd/DeVOp'd a user. Also, it will return the current
      echo -t @Help skin that you're using. It can only be used by an owner. Syntax: .stats
      echo -t @Help  .Op
      echo -t @Help Ops a user. Can be used by fellow Ops and owners. Syntax: .Op <nickname>
      echo -t @Help  .DeOp 
      echo -t @Help DeOps a user. Can be used by fellow Ops and owners. Syntax: .DeOp <nickname>
      echo -t @Help  .HOp
      echo -t @Help HalfOps a user. Can be used by fellow Ops and owners. Syntax: .HOp <nickname>
      echo -t @Help  .DeHOp
      echo -t @Help DeHOps a user. Can be used by fellow Ops and owners. Syntax: .DeHOp <nickname>
      echo -t @Help  .VOp
      echo -t @Help VOps a user. Can be used by fellow HOps/Ops and owners. Syntax: .VOp <nickname>
      echo -t @Help  .DeVOp 
      echo -t @Help DeVOps a user. Can be used by fellow HOps/Ops and owners. Syntax: .DeVOp <nickname>
      echo -t @Help  .Kick
      echo -t @Help Kicks a user. Can be used by Ops [and sometimes HOps] and owners. Syntax: .Kick <nickname> [message]
      echo -t @Help  .Ban
      echo -t @Help Bans a user using the "Default Ban address". To configure this setting, you can check the command bar. 
      echo -t @Help Syntax: .Ban <nickname>
      echo -t @Help 
      echo -t @Help Quote System Commands
      echo -t @Help  .Q
      echo -t @Help To turn your the quote system on or off, you may use this command. In addition, you do not need to actually
      echo -t @Help include "ON" or "OFF," as the script will automatically switch to the opposite status. Syntax: .q [on/off]
      echo -t @Help  .Qc
      echo -t @Help In order to manage your quote files, you need to get some sort of visual. This is it. It lists the status of 
      echo -t @Help the quote system's activity, the public access, as well as the quote file's data. Syntax: .qc
      echo -t @Help  .Qa
      echo -t @Help Adding quotes to the file is as easy as one simple command. Syntax: .qa <quote>
      echo -t @Help  .Qr
      echo -t @Help This reads a desired, or random quote from either to Quarentine file [-q], or the regular file.
      echo -t @Help Syntax: .qr [-q] [#]
      echo -t @Help  .Qd
      echo -t @Help This command can delete, or flush a file in order to keep the quotes organized and appropriate.
      echo -t @Help Specify the "-q" tag to delete from the quarentine list [followed by +f to flush]. Syntax: .qd [-q [+f] -f] [#]
      echo -t @Help  .Qp
      echo -t @Help This toggles the public access to the bot. You can either set it from OFF, to ON, or to QUARENTINE. 
      echo -t @Help Having it on quarentine allows the public to add quotes to a special, quarentined file. You needn't specify
      echo -t @Help what you want to switch it to, as the bot can automatically switch to a different status by itself using just ".qp"
      echo -t @Help Syntax: .qp [on/off/quarentine]
      echo -t @Help  .Qu
      echo -t @Help To converge both the quarentine, and quote.txt files, this is the command to use. The "-f" switch allows you to
      echo -t @Help flush the quarentine.txt file after converging it. Syntax: .qu [-f]
    }
    if (About == $sline(@Help,1)) { 
      clear @Help
      echo -t @Help About
      echo -t @Help  This bot was just a test for me to see if i could create a functional bot within a time limit. This bot did
      echo -t @Help meet my expectations, only providing far fewer commands than i had wished. Please feel free to contact
      echo -t @Help me at the following locations for questions/comments/suggestions/code snippets etc:
      echo -t @Help > Email: Klash240@gmail.com
      echo -t @Help > IRC: irc.unhandledexceptions.com - Look for Pass
      echo -t @Help If positive feedback is received from this bot, I may pull it out from retirement and work on a new, also
      echo -t @Help non-beta version. So, thanks for using the script, and i hope it suits your needs. Let me know what you think!    
    }
  }
}

###########################################################
###QUOTE
###########################################################

alias -l start { hadd -m Settings Quote on | hadd Settings Quote_Pub Off | if (!$exists(Quote.txt)) write Quote.txt | if (!$exists(Quarentine.txt)) write Quarentine.txt }
on *:LOAD:start
alias chq { 
  var %x = $lines($1 $+ .txt)
  while (%x) {
    inc %y
    dec %x
  }
  return %y
}
alias -l conv { 
  var %x = $lines($1 $+ .txt) 
  while (%x) { 
    write $2 $+ .txt $read($1 $+ .txt,%x) 
    dec %x
  }
  return $3-
}
alias qon { hadd Settings Quote on }
alias qoff { .timerQB&* off | $iif($hget($+(Q_,$network)),hfree $+(Q_,$network)) | $iif($hget($+(QB&_,$network)),hfree $+(QB&_,$network)) | hadd Settings Quote Off }
alias -l qadd { write Quote.txt $1 $2- | return $skin(Quote [# $+ $lines(Quote.txt) $+ ] added!) }
alias -l qdel { write $+(-dl,$1) Quote.txt | return $skin(Quote [# $+ $1 $+ ] deleted!) }
alias -l b { if ($1 <= 1024) { return $1 b } | if ($1 >= 1024) { return $int($calc($1 / 1024)) kb } }
