;@@@
;@@@ DreamBot IRC Bot 5.4
;@@@ File description: owner commands
;@@@ Design & coding: DreamBot development team
;@@@ (C) Copyright 2004-2006 DreamBot development team. All rights reserved. 
;@@@

;@@@ Private message commands @@@
on 500:text:shutdown:?: {
  amsg Bye!
  quit $dbver(text) $+ . Get it at: $dbver(site)
  exit
}
alias _gatherchan {
  set %nick $1
  set %cmax $comchan(%nick,0)
  set %c2 0
  unset %temp
  :next
  inc %c2
  if %c2 > %cmax { goto end }
  if $comchan(%nick,%c2) !== $null { set %temp %temp $+ $chr(44) $+ $comchan(%nick,%c2) | goto next }
  :end
  return %temp
}
on 500:text:*restart*:#: {
  if $1 == %c $+ restart {
    msg $chan restart? okay.
    amsg I'll be right back...
    partall Restarting
    set %rejoin_channels $_gatherchan($me)
    .timer 1 3 server -j %rejoin_channels
  }
}
on 500:text:restart:?: {
  amsg I'll be right back...
  set %rejoin_channels $_gatherchan($me)
  partall
  .timer 1 3 server -j %rejoin_channels
}
on 500:text:listops:?: {
  if ($exists(ini\oplines.txt) == $false) { .msg $nick Operators database does not exist. | halt }
  set %op.count 0
  .msg $nick $cl Listing bot operators:
  :showop
  inc %op.count
  if ($read(ini\oplines.txt,%op.count) == $null) { halt }
  .msg $nick $cl  $read(ini\oplines.txt, %op.count)  is a bot $readini(ini\oper.ini,$read(ini\oplines.txt,%op.count),Level) $+ .
  goto showop
}
on 500:Text:rehash*:?: {
  .msg $nick Removed $findfile($mircdir\ini, *#*.ini,*, remove $1- ) storage files. Rehash complete.
}
on 500:Text:cmdchr*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me cmdchr <command character>. | halt }
  if ($len($2) > 1) { .msg $nick The command character must be only ONE character. | halt }
  if ($2 !== $null) {
    if ($2 == %c) { .msg $nick New command character same as old one. | halt }
    if ($2 !== %c) { .unset %c | set %c $2 | .msg $nick New command character is $2 $+ . }
  }
}
on 500:text:cycle*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me cycle <#channel> | halt }
  if ($2 !== $null) {
    if ($me !ison $2) { .msg $nick I'm not on $2 $+ . | halt }
    else { hop $2 }
  }
}
on 500:Text:nick*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me nick <nickname to use>. | halt }
  if ($2 !== $null) { 
    if ($2 === $me) { .msg $nick I already have that nick. | halt }
    else { //nick $2 | .msg $nick Nickname change attempt completed. }
  }
}
on 500:text:getpass*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me getpass <nick>. | closemsg $nick | halt }
  if ($2 !== $null) {
    if ($readini(ini\oper.ini, $2, Level) == $null) { .msg $nick $2 is not a bot operator. | closemsg $nick | halt }
    if ($readini(ini\oper.ini, $2, Password) == $null) { .msg $nick $2 does not have a password. | closemsg $nick | halt }
    if ($readini(ini\oper.ini, $2, Password) !== $null) { .msg $nick $2 $+ 's password is $readini(ini\oper.ini, $2, Password) $+ . | closemsg $nick | halt }
  }
}
on 500:text:*mode*:?: {
  if ($1 == mode) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me mode <#channel> <modes>. | halt }
    if ($2 !== $null) { 
      if ($me !ison $2) { .msg $nick I'm not on $2 $+ . | closemsg $nick | halt }
      if ($me !isop $2) && ($me !ishop $2) { .msg $nick I'm not oped in $2 $+ . | closemsg $nick | halt }
      if ($3 == $null) { .msg $nick No modes specified. | closemsg $nick | halt }
      if (($me ison $2) && ($3 !== $null)) { mode $2 $3- | .msg $nick Added mode $3- to $2 $+ . | closemsg $nick }
    }
  }
  if ($1 == automode) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me automode <#channel> <on|off> <modes>. | halt }
    if ($3 == $null) { .msg $nick Command incomplete. Syntax: /msg $me automode <#channel> <on|off> <modes>. | halt }
    if ($3 == on) {
      if ($4 == $null) { .msg $nick You must specify modes to set. | halt }
      if ($4 !== $null) { .writeini -n ini\channels.ini $2 SModes $4- | .msg $nick Saved channel modes for $2 are now $4- $+ . | halt }
    }
    if ($3 == Off) { .writeini -n ini\channels.ini $2 SModes Off | .msg $nick Auto modes for $2 are now disabled. | halt }
  }
}

on 500:text:quit:?: { quit $dbver(text) $+ . Get it at: $dbver(site) | closemsg $nick }
on 500:text:jump*:?: { 
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me jump <server> <port>. | closemsg $nick | halt }
  if ($2 !== $null) {
    if ($2 == $server) { .msg $nick I'm currently on that server. ( $+ $server $+ ). | closemsg $nick | halt }
    if ($2 !== $server) {
      if ($3 == $null) { quit Changing servers. | //server $2 | closemsg $nick | halt }
      if ($3 !== $null) { quit Changing servers. | //server $2 $+ : $+ $3 | closemsg $nick | halt }
    }
  }
}
on 500:text:join*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me join <#channel> [key]. | closemsg $nick | halt }
  if ($2 !== $null) {
    if ($me ison $2) { .msg $nick I'm already on that channel. | closemsg $nick | halt }
    if ($me !ison $2) { .join $2 $3 | .msg $nick Join attempt on $2 completed. | closemsg $nick | halt }
  }
}
on 500:text:part*:?: {
  if (($1 == partall) && ($2 == $null)) { partall | halt }
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me part <#channel>. | closemsg $nick | halt }
  if ($2 !== $null) {
    if ($me !ison $2) { .msg $nick I'm not on that channel. | closemsg $nick | halt }
    if ($me ison $2) { .part $2 | .msg $nick Left channel $2 $+ . | closemsg $nick | halt }
  }
}
on 500:text:gainops*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me gainops <on|off> | halt }
  if ($2 == on) { .writeini -n ini\globals.ini Config Cycle On | .msg $nick The bot will now try to gain ops. | halt }
  if ($2 == off) { .writeini -n ini\globals.ini Config Cycle Off | .msg $nick The bot will never try to gain ops. | halt }
  else { .msg $nick $cl Error: Invalid parameters. Available options: ON/OFF. | halt }
}


;@@@ Public channel commands @@@
on 500:Text:*quit*:#: {
  if ($1 == %c $+ quit) { quit $dbver(text) $+ . Get it at: $dbver(site) }
}
on 500:text:*jump*:#: { 
  if ($1 == %c $+ jump) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me jump <server> <port>. | halt }
    if ($2 !== $null) {
      if ($2 == $server) { .msg $nick I'm currently on that server. ( $+ $server $+ ). | halt }
      if ($2 !== $server) {
        if ($3 == $null) { quit Changing servers. | //server $2 | halt }
        if ($3 !== $null) { quit Changing servers. | //server $2 $+ : $+ $3 | halt }
      }
    }
  }
}
on 500:text:*join*:#: {
  if ($1 == %c $+ join) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me join <#channel> [key]. | closemsg $nick | halt }
    if ($2 !== $null) {
      if ($me ison $2) { .msg $nick I'm already on that channel. | closemsg $nick | halt }
      if ($me !ison $2) { .join $2 $3 | .msg $nick Join attempt on $2 completed. | closemsg $nick | halt }
    }
  }
}
on 500:text:*part*:#: {
  if ($1 == %c $+ partall) { .partall }
  if ($1 == %c $+ part) {
    if ($2 == $null) { .part $chan | halt }
    if ($2 !== $null) {
      if ($me !ison $2) { .msg $nick I'm not on that channel. | closemsg $nick | halt }
      if ($me ison $2) { .part $2 | .msg $nick Left channel $2 $+ . | closemsg $nick | halt }
    }
  }
}

on 500:text:*mode*:#: {
  if ($1 == %c $+ mode) {
    if ($2 == $null) { .msg $nick You must specify a mode to set. | halt }
    if ($2 !== $null) {
      if ($me !isop $chan) && ($me !ishop $chan) { .msg $nick I'm not oped in $chan $+ . | halt }
      if ($me isop $chan) || ($me ishop $chan) { //.mode $chan $2- }
    }
  }
  if ($1 == %c $+ automode) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ automode <on|off> <modes> | halt }
    if ($2 == on) {
      if ($3 == $null) {  .msg $nick You must specify modes to set. | halt }
      if ($3 !== $null) { .writeini -n ini\channels.ini $chan SModes $3- | .msg $nick Saved channel modes for $chan are now $3- $+ . | halt }
    }
    if ($2 == Off) { .writeini -n ini\channels.ini $chan SModes Off | .msg $nick Auto modes for $chan are now disabled. | halt }
  }
}
on 500:Text:*nick*:#: {
  if ($1 == %c $+ nick) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ nick <nickname to use>. | halt }
    if ($2 !== $null) { 
      if ($2 === $me) { .msg $nick I already have that nick. | halt }
      else { //nick $2 | .msg $nick Nickname change attempt completed. }
    }
  }
}
on 500:Text:*cmdchr*:#: {
  if ($1 == %c $+ cmdchr) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ cmdchr <command character>. | halt }
    if ($len($2) > 1) { .msg $nick The command character must be only ONE character. | halt }
    if ($2 !== $null) {
      if ($2 == %c) { .msg $nick New command character same as old one. | halt }
      if ($2 !== %c) { .unset %c | set %c $2 | .msg $nick New command character is $2 $+ . }
    }
  }
}
on 500:text:*cycle*:#: {
  if ($1 == %c $+ cycle) { hop $chan }
  else { halt }
}
on 500:Text:*rehash*:#: {
  if ($1 == %c $+ rehash) { 
    .msg $chan Removed $findfile($mircdir\ini\junk, * $+ $chr(35) $+ *.ini,*, remove $1- ) storage files. Rehash complete.
  }
}
on 500:text:*greet*:#: {
  if ($1 == %c $+ greet) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ greet <on|off>. | halt }
    if ($2 !== $null) {
      if ($2 == on) { writeini -n ini\channels.ini $chan Greet On | .msg $nick Greet mode for $chan enabled. | halt }
      if ($2 == off) { writeini -n ini\channels.ini $chan Greet Off | .msg $nick Greet mode for $chan disabled. | halt }
      else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON\OFF. | halt }
    }
  }
  if ($1 == %c $+ greetnotice) {
    if ($2 == $null)  { .msg $nick Command incomplete. Syntax: %c $+ greetnotice <text>. | halt }
    if ($2 !== $null) { 
      if ($readini(ini\channels.ini, $chan, Greet) == Off) { .msg $nick The greet mode is disabled. To enable it type %c $+ greet on. | halt }
      if ($readini(ini\channels.ini, $chan, Greet) == On) { write -ds $+ $chan ini\grlines.txt | write ini\grlines.txt $chan $2- | .msg $nick Added greet notice for $chan $+ . | halt }
    }
  }
}
on 500:text:*greet*:?: {
  if ($1 == help) { halt }
  if ($1 == greet) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me greet <#channel> <on|off>. | halt }
    if ($2 !== $null) {
      if ($3 == on) { writeini -n ini\channels.ini $2 Greet On | .msg $nick Greet mode for $2 enabled. | halt }
      if ($3 == off) { writeini -n ini\channels.ini $2 Greet Off | .msg $nick Greet mode for $2 disabled. | halt }
      else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
    }
  }
  if ($1 == greetnotice) {
    if ($2 == $null)  { .msg $nick Command incomplete. Syntax: /msg $me greetnotice <#channel> <text>. | halt }
    if (($2 !== $null) && ($3 !== $null)) { 
      if ($readini(ini\channels.ini, $chan, Greet) == Off) { .msg $nick The greet mode is disabled. To enable it type /msg $me greet <#channel> on. | halt }
      if ($readini(ini\channels.ini, $chan, Greet) == On) { write -ds $+ $2 ini\grlines.txt $2 $3- | write ini\grlines.txt $chan $2- | .msg $nick Added greet notice for $2 $+ . | halt }
    }
  }
}
;@@@ Auto op @@@
on 500:text:autoop*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me autoop <on|off>. | halt }
  if ($2 !== $null) { 
    if ($2 == on) { .enable #aop | .msg $nick The auto op feature is now enabled. | halt }
    if ($2 == off) { .disable #aop | .msg $nick The auto op feature is now disabled. | halt }
    else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
  }
}
on 500:text:*autoop*:#: {
  if ($1 == %c $+ autoop) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ autoop <on|off>. | halt }
    if ($2 !== $null) { 
      if ($2 == on) { .enable #aop | .msg $nick The auto op feature is now enabled. | halt }
      if ($2 == off) { .disable #aop | .msg $nick The auto op feature is now disabled. | halt }
      else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
    }
  }
}
#aop off
on @100:join:#: { mode $chan +o $nick }
#aop end

;@@@ Anti Idle @@@
on 500:text:aidle*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me aidle <on|off> | halt }
  if ($2 !== $null) {
    if ($2 == on) { .set %aidle on | .msg $nick The anti idle mode is now enabled. | halt }
    if ($2 == off) { .set %aidle off | .msg $nick The anti idle mode is now disabled. | halt }
    else { .msg $nick $cl Error: Invalid parameters. Available options: ON/OFF. | halt }
  }
}
on 500:text:*aidle*:#: {
  if ($1 == %c $+ aidle) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me aidle <on|off> | halt }
    if ($2 !== $null) {
      if ($2 == on) { .set %aidle on | .msg $nick The anti idle mode is now enabled. | halt }
      if ($2 == off) { .set %aidle off | .msg $nick The anti idle mode is now disabled. | halt }
      else { .msg $nick $cl Error: Invalid parameters. Available options: ON/OFF. | halt }
    }
  }
}
on 500:text:*gainops*:#: {
  if ($1 == %c $+ gainops) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ gainops <on|off> | halt }
    if ($2 == on) { .writeini -n ini\globals.ini Config Cycle On | .msg $nick The bot will now try to gain ops. | halt }
    if ($2 == off) { .writeini -n ini\globals.ini Config Cycle Off | .msg $nick The bot will never try to gain ops. | halt }
    else { .msg $nick $cl Error: Invalid parameters. Available options: ON/OFF. | halt }
  }
}
on 500:text:*listops:#: {
  if ($1 == %c $+ listops) {
    if ($exists(ini\oplines.txt) == $false) { .msg $nick Operators database does not exist. | halt }
    set %op.count 0
    .msg $nick $cl Listing bot operators:
    :showop
    inc %op.count
    if ($read(ini\oplines.txt,%op.count) == $null) { halt }
    .msg $nick $cl  $read(ini\oplines.txt, %op.count)  is a bot $readini(ini\oper.ini,$read(ini\oplines.txt,%op.count),Level) $+ .
    goto showop
  }
}
on 500:text:*shutdown*:#: {
  if $1 == %c $+ shutdown {
    msg $chan why? On the other hand...
    amsg Bye!
    quit $dbver(text) $+ . Get it at: $dbver(site)
    exit
  }
}
