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

;@@@ get hosts of all users on the channel @@@

;@@@ end joinwho @@@

;@@@ owner removal tool @@@
alias _remowner { dialog -ma remowner remowner }
dialog remowner {
  title "Remove bot owner"
  size -1 -1 300 230
  icon "img/set.ico", 0
  text "    With this tool you can remove the bot's owner, without reinstalling the bot. You have to enter your owner password in order to do this removal and you also have to enter a new owner registration code.", 1, 5 5 290 60
  text "Bot owner:", 2, 5 60 290 15
  text "Username:", 3, 15 75 50 15
  text "Password:", 4, 155 75 50 15
  edit "", 5, 70 72 70 20
  edit "", 6, 210 72 70 20, password 
  text "New registration code:", 7, 15 110 130 15
  edit "", 8, 150 107 70 20, limit 4
  text "    The registration code must be a 4-digit number. Enter a number between 1000 and 9999. That will be your new owner registration code. Read the ReadMe document to find out how to set yourself as owner.", 9, 5 135 290 80
  button "Remove owner", 10, 30 195 90 25
  button "Cancel", 11, 180 195 90 25, cancel
}
on *:dialog:remowner:init:0: {
  if (%owner == $null) { dialog -c remowner | _error You can't use this tool as the bot doesn't have any owner. First set yourself as owner (read the ReadMe file for more info). | halt }
  did -ram remowner 5 %owner
}
on *:dialog:remowner:sclick:10: {
  if ($did(remowner,6).text == $null) { _error Please specify the password for the owner. | halt }
  if ($did(remowner,6).text !== $readini(ini\oper.ini, $did(remowner,5).text, Password)) { _error You specified an invalid password. | halt }
  if ($did(remowner,8).text == $null) { _error You must specify a new registration code. | halt }
  if (($did(remowner,8).text < 1000) || ($did(remowner,8).text > 9999)) { _error You specified an invalid registration code. Please enter a number between 1000 and 9999. | halt }
  .ruser 500 $readini(ini\oper.ini, $did(remowner,5).text, Hostmask)
  .remini ini\oper.ini $did(remowner,5).text
  .write -ds $+ $did(remowner,5).text ini\oplines.txt
  unset %owner
  set %regcode $did(Remowner,8).text
  .enable #owner
  dialog -c remowner
  _info The bot owner was removed.
}

;@@@ Load bar
dialog db_progressb {
  title "DreamBot"
  size -1 -1 268 27
  option pixels
  text "System is configuring setup files..", 1, 25 5 220 15, center disable
  text "", 2, 9 26 250 18
  button Ok, 3, 0 0 0 0, ok
}
on *:dialog:db_progressb:init:*:{
  mdx_load SetMircVersion $version
  mdx_load MarkDialog $dname
  mdx_load SetControlMDX $dname 2 ProgressBar smooth > $cgen
  mdx_load SetFont $dname 1 +a 12 700 Tahoma
  mdx_load SetDialog $dname style 0 tool dlgmodal
}

alias db_pb $iif(!$dialog(db_progressb),dialog -om db_progressb db_progressb) | $iif($dialog(db_progressb),did -ra db_progressb 2 $1 0 100)
alias db_progressb $iif(!$dialog(db_progressb),dialog -om db_progressb db_progressb) | did -ra db_progressb 1 $1-

alias cgen { return system\ctl_gen.mdx }
alias mdx_load { return $dll(system\mdx.dll,$1,$2-) }
alias _edlginit { 
  mdx_load MarkDialog $dname
  mdx_load SetMircVersion $version
}
dialog db_bload {
  title "Initializing system's Core sequences..."
  size -1 -1 268 27
  option pixels
  text "System is configuring setup files..", 1, 25 5 210 15, center disable
  text "", 2, 9 26 250 18
  button Ok, 3, 0 0 0 0, ok
}
on *:dialog:db_bload:init:*:{
  _edlginit
  mdx_load SetControlMDX $dname 2 ProgressBar smooth > $cgen
  mdx_load SetFont $dname 1 +a 12 400 Tahoma
  mdx_load SetDialog $dname style 0 tool dlgmodal
  did -a $dname 2 BarColor $rgb(58,110,165)
}
alias db_barload $iif(!$dialog(db_bload),dialog -om db_bload db_bload) | $iif($dialog(db_bload),did -ra db_bload 2 $1 0 100)
alias db_bload $iif(!$dialog(db_bload),dialog -om db_bload db_bload) | did -ra db_bload 1 $1-



;@@@ Self maintainence @@@
alias sf {
  if (%aidle == on) { .msg $me Anti-Idle }
  ;_amenu
}

on 1:connect: {
  .timerSM 0 300 sf
}
;@@@ mass unban module @@@

on *:unban:#: { 
  if (%fb [ $+ [ $chan ] ] == no) { halt }
  if (%fb [ $+ [ $chan ] ] !== no) { set %fb [ $+ [ $chan ] ] no }
}
raw 367:*: { 
  if (%ub [ $+ [ $2 ] ] !== $null) {
    if (%ub [ $+ [ $2 ] ] iswm $3) {
      if ((%qub [ $+ [ $2 ] ] !== $null) && ($numtok(%qub [ $+ [ $2 ] ], 32) >= 6)) { qub $2 | set %qub [ $+ [ $2 ] ] $3 | halt }
      else { set %qub [ $+ [ $2 ] ] %qub [ $+ [ $2 ] ] $3 | halt } 
    }
  }
}
raw 368:*: { 
  if (%ub [ $+ [ $2 ] ] !== $null) { unset %ub [ $+ [ $2 ] ] | halt }
}
raw 478:*: {
  if (($me ison $2) && ($me isop $2) && (%fb [ $+ [ $2 ] ] !== yes)) { 
    mode $2 +mir 
    msg $2 Channel banlist is full. Type %c $+ unban * to clear it. 
    set %fb [ $+ [ $2 ] ] yes 
    halt 
  }
  if (($me ison $2) && ($me isop $2) && (%fb [ $+ [ $2 ] ] == yes)) { 
    ;mode $2 +mir 
    halt 
  }
}
on 100:text:*unban*:#: {
  if ($1 == %c $+ unban) {
    if ($me !isop $chan) && ($me !ishop $chan) { .msg $nick I'm not oped in $chan $+ . | halt }
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ unban <hostmask>. | halt }
    if ($2 !== $null) {
      //set %ub [ $+ [ $chan ] ]  $2
      mode $chan +b
    }
  }
}
on 100:text:unban*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me unban <#channel> <hostmask>. | halt }
  if (($2 !== $null) && ($3 !== $null)) {
    if ($me !isop $2) && ($me !ishop $chan) { .msg $nick I'm not oped in $2 $+ . | halt }
    //set %ub [ $+ [ $2 ] ]  $3
    mode $2 +b
  }
}
;@@@ msg and ini routines @@@
on 1:text:*:?: { closemsg $nick }
on 1:ban:#: { writeini -n ini\channels.ini $chan LastBan $banmask }
;@@@ gain ops @@@

on !*:part:#: {
  if (($readini(ini\globals.ini, Config, Cycle) == Off) || ($readini(ini\globals.ini, Config, Cycle) == $null)) { halt }
  %rjc.chan = #
  if ($nick(%rjc.chan,0,o,ahvr) == 0) && ($nick(%rjc.chan,0) == 2) && ($me !isop #) { 
    raw -q part %rjc.chan 
    raw -q join %rjc.chan 
    unset %rjc.* 
  }
}
;@@@ rainbow text @@@
alias rain {
  if ($1 != $null) {
    var %LL = 04,07,08,09,12,11,13
    var %ctl = 1
    var %ct = 1
    while (%ct <= $len($1-)) {
      var %new = %new $+  $+ $gettok(%LL,%ctl,44) $+ $iif($mid($1-,%ct,1) != $chr(32), $+ $mid($1-,%ct,1), $chr(32) $+ $mid($1-,%ct,1)) 
      inc %ctl 1
      if (%ctl > 7) { var %ctl = 1 }
      inc %ct 1
    }
    return %new $+ 
  }
}
;@@@ mask kick @@@
on @500:text:*mk*:#:{
  if ($1 == %c $+ mk) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ mk <hostmask> | halt }
    if ($2 !== $null) {
      if ($2 iswm $address($me,5)) { .msg $nick $cl Error: I match that hostmask. | halt }
      if ($2 iswm $address($nick,5)) { .msg $nick $cl Error: You match that hostmask. | halt }
      else {
        set %x 0
        mode $chan +b $2
        //set %bmask $2
        :begin
        inc %x 1
        //set %nick $nick($chan,%x)
        if (%nick == $null) { goto end2 }
        //set %address $address(%nick,5)
        //set %address2 $address(%nick,2)
        if (%nick == $me) { goto begin }
        if (%bmask !iswm %address) { goto begin }
        if ((%bmask iswm %address) && ($level(%address2) > 1)) { .msg $nick %nick was excluded as he is a bot operator. | goto begin }
        if (%bmask iswm %address) { //kick $chan %nick You are banned. | goto begin }
        :end2 
        unset %nick
        unset %x
        unset %address
        unset %address2
        unset %bmask
        :end
        halt
      }
    }
  }
}
;@@@ bot calculator @@@
on *:text:*calc*:#: {
  if ($1 == %c $+ calc) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ calc <math operations>. | halt }
    if ($calc($2-) !== $null) { msg $chan $nick $+ , result is: $calc($2-). }
  }
}
alias _sp { return 0102121415 }
;@@@ check for owner @@@
alias _owner { 
  if (%regcode == $null) { set %regcode $rand(1000,9999) }
  if (%c == $null) { set %c ! }
  if (%owner == $null) { .enable #owner }
  window -kb0a @ReadMe
  aline -p @ReadMe $cl DreamBot IRC Bot ReadMe
  aline -p @ReadMe $cl $_sp
  aline -p @ReadMe For using DreamBot, you must first set yourself as owner.
  aline -p @ReadMe Please follow these steps:
  aline -p @ReadMe 1. Open another IRC client (such as mIRC) and connect it to a server and join a channel.
  aline -p @ReadMe 2. Connect the bot's mIRC to the same server you connected and make it join the same channel as you (/join #channel_name_here).
  aline -p @ReadMe 3. In your IRC client (not in the bot's mIRC) type the following command:
  aline -p @ReadMe %c $+ owner %regcode
  aline -p @ReadMe 4. The bot will then ask you to set a password. Setting a password allows you to login the bot when it does not recognize your host/IP. When it does, you don't need to login. The login command has the following format: /msg botnick login <username> <password>. Please note that your username is the nick you had when you set yourself as owner.
  aline -p @ReadMe 5. Then type %c $+ commands in the channel window to see a list of available commands.
  aline -p @ReadMe 6. Now please configure your bot the way you like using 'Configuration...' in the DreamBot 5.4 menu or press F2.
  aline -p @ReadMe 7. That's about all, enjoy DreamBot! For more information, please read the documentation that came with the bot (press F1).
}
;@@@ try to connect @@@
alias _connect { 
  if (%fvr-s == 1) || (%fvr-n == 1) || (%fvr-t == 1) { exit }
  if (($readini(ini\globals.ini,Config,Auto) == $null) || ($readini(ini\globals.ini,Config,Auto) == Off) && ($1 == $null)) { halt }
  if (($readini(ini\globals.ini,Config,Auto) == On) || ($1 == force)) {
    if ($readini(ini\globals.ini,Config,Server) == $null) { echo -s $cl 5No server set for auto connect. | halt }
    echo -s $cl 5Trying to connect to  $+ $readini(ini\globals.ini,Config,Server) $+ ...
    set %s_server $readini(ini\globals.ini,Config,Server)
    if ($readini(ini\globals.ini,Config,SrvPort) == $null) { echo -s $cl 5No port set. Using 6667... | set %s_port 6667 }
    if ($readini(ini\globals.ini,Config,SrvPort) !== $null) { echo -s $cl 5Using port  $+ $readini(ini\globals.ini,Config,SrvPort) $+ ... | set %s_port $readini(ini\globals.ini,Config,SrvPort) }
    if ($readini(ini\globals.ini,Config,NickName) == $null) { set %dbnick db- $+ $rand(1000,9999) | echo -s $cl 5No nick specified. Using  $+ %dbnick $+ ... | set %s_nick %dbnick }
    if ($readini(ini\globals.ini,Config,NickName) !== $null) { echo -s $cl 5Using nick  $+ $readini(ini\globals.ini,Config,NickName) $+ ... | set %s_nick $readini(ini\globals.ini,Config,NickName) }
    if ($readini(ini\globals.ini,Config,Channels) == $null) { echo -s $cl 5No channels specified to join on connect. }
    if ($readini(ini\globals.ini,Config,Channels) !== $null) { echo -s $cl 5Channels to join on connnect: $readini(ini\globals.ini,Config,Channels) $+ ... | set %s_chan $readini(ini\globals.ini,Config,Channels) }
    server %s_server $+ : $+ %s_port -i %s_nick -j %s_chan
    _auth
  }
}
alias r.net { return $readini(ini\networks.ini,$1,$2) }
alias _auth {
  if ($readini(ini\networks.ini,$1,Method) == $null) { halt }
  if ($readini(ini\networks.ini,$1,Method) == NickServ) {
    if ($readini(ini\networks.ini,$1,NickName) == $2) {
      if ($readini(ini\networks.ini,$1,NSMethod) == 1) {
        if ($readini(ini\networks.ini,$1,NPass) == $null) { halt }
        nickserv identify $readini(ini\networks.ini,$1,NPass)
        halt
      }
      if ($readini(ini\networks.ini,$1,NSMethod) == 2) {
        if ($readini(ini\networks.ini,$1,NPass) == $null) { halt }
        msg nickserv identify $readini(ini\networks.ini,$1,NPass)
        halt
      }
      if ($readini(ini\networks.ini,$1,NSMethod) == 3) {
        if ($readini(ini\networks.ini,$1,NPass) == $null) { halt }
        if ($r.net($1,NS3) == $null) { halt }
        . $+ $r.net($1,NS3) $readini(ini\networks.ini,$1,NPass)
        halt
      }
    }
  }
  if ($r.net($1,Method) == GNU) {
    if ($r.net($1,UserName) == $null) { halt }
    if ($r.net($1,Upass) == $null) { halt }
    if ($r.net($1,GNUmethod) == $null) { halt }
    . $+ $r.net($1,GNUmethod) login $r.net($1,UserName) $r.net($1,Upass)
  }
  if ($r.net($1,Method) == 0) { halt }
}
on 1:join:#: { 
  if ($nick == $me) {
    if ($r.net($network,Method) == NickServ) {
      if ($r.net($network,GainOps) == On) { chanserv op $chan $me }
    }
    if ($r.net($network,Method) == GNU) {
      if ($r.net($network,GainOps) == On) {  $r.net($network,GNUmethod) op $chan }
    }
  }
}
on *:deop:#: { 
  if ($opnick == $me) {
    if ($r.net($network,Method) == NickServ) {
      if ($r.net($network,ReOp) == On) { chanserv op $chan $me }
    }
    if ($r.net($network,Method) == GNU) {
      if ($r.net($network,ReOp) == On) {  $r.net($network,GNUmethod) op $chan }
    }
  }
}
alias _faq { 
  window -kb0a @FAQ
  aline -p @FAQ $cl DreamBot IRC FAQ
  aline -p @FAQ $cl Copyright 2004-2006 by DreamBot development team.
  aline -p @FAQ $_sp
  aline -p @FAQ 1. What is DreamBot?
  aline -p @FAQ DreamBot IRC Bot is a mIRC based Windows bot that can take care of your channels.
  aline -p @FAQ $_sp
  aline -p @FAQ 2. How do I set myself as owner?
  aline -p @FAQ To find out how to set yourself as owner, please read the ReadMe file, under the DreamBot 5.4 -> DreamBot Files menu.
  aline -p @FAQ $_sp
  aline -p @FAQ 3. When I use colors in a channel, the bot warns me and then bans me. What's wrong?
  aline -p @FAQ The bot might not recognize you as its owner. You need to login using /msg <botname> login <username> <password>. The username is the nickname you had when you set yourself as owner.
  aline -p @FAQ $_sp
  aline -p @FAQ 4. Can this bot stay on my channel while I'm not on the Internet?
  aline -p @FAQ It can't. To do this, you must be connected to the Internet 24/7.
  aline -p @FAQ $_sp
  aline -p @FAQ 5. The bot keeps getting disconneted when it remains idle, how can I stop that?
  aline -p @FAQ You must enable the anti idle feature, using  $+ %c $+ aidle on
  aline -p @FAQ $_sp
  aline -p @FAQ 6. The bot won't kick ban users that I tell it to. What's wrong?
  aline -p @FAQ Maybe it isn't oped in the channel. Make sure the bot is always oped.
  aline -p @FAQ $_sp
  aline -p @FAQ 7. I want to read more about this bot. Where can I find more info?
  aline -p @FAQ There's a help file available for that. Just press F1.
  aline -p @FAQ $_sp
  aline -p @FAQ 8. I found a bug. How can I report it?
  aline -p @FAQ Just post a message on our forums, at http://dreambot.eurion.com
  aline -p @FAQ $_sp
  aline -p @FAQ 9. Were can I check for new versions of the bot?
  aline -p @FAQ You can always do this at out homepage, http://dreambot.eurion.com. Make sure you do at least a check every month.
  aline -p @FAQ $_sp
  aline -p @FAQ 10. Where can I find the author of this bot?
  aline -p @FAQ You can find the author on irc.undernet.org in the channel #AllNightCafe, with the nickname Crosswing. Please note that I'm not always online.
  aline -p @FAQ $_sp
}
