;@@@
;@@@ DreamBot IRC Bot 5.4
;@@@ File description: misc features and quick-module (qmod)
;@@@ Design & coding: DreamBot development team
;@@@ (C) Copyright 2004-2006 DreamBot development team. All rights reserved. 
;@@@

on 100:TEXT:*uptime:#: { if ($1 == $+(%c,uptime)) { .msg $chan My machine has been up $uptime(system,1) $+ . I have been up $uptime(mirc,1) and connected to server for $uptime(server,1) $+ . | halt } }
alias _main { 
  .unset %banned [ $+ [ $1 ] ]
  if ($me !isop $1) && ($me !ishop $1) { halt }
  if ($readini(ini\channels.ini, $1, STopic) == On) {
    if (($read(ini\tlines.txt, s, $1) !== $null) && ($chan($1).topic !=== $read(ini\tlines.txt, s, $1))) { topic $1 $read(ini\tlines.txt, s, $1) }
  }
  if (($readini(ini\globals.ini, HelpMode, AModerated) == On) && ($Readini(ini\channels.ini, $1, HelpMode) == On))  { 
    if (m !isin $chan($1).mode) { mode $1 +m }
  }
  if ($readini(ini\channels.ini, $1, SModes) == Off) { halt }
  if ($readini(ini\channels.ini, $1, SModes) == $null) { halt }
  if (($readini(ini\channels.ini, $1, SModes) !== Off) || ($readini(ini\channels.ini, $1, SModes) !== $null)) { mode $1 $readini(ini\channels.ini, $1, SModes) }
  _live.kb $1
}
on 1:exit: {
  unset %q*
  unset %fb*
  unset %lock*
  unset %evtrig*
  unset %floodnick*
  unset %waitlist.*
  unset %next.*
}
on 1:disconnect: {
  unset %q*
  unset %fb*
  unset %lock*
  unset %evtrig*
  unset %floodnick*
  unset %ban.*
}
on 100:text:*act*:#: {
  if ($1 == %c $+ act) {
    if ($readini(ini\globals.ini, Features, Say) == Off) {
      .msg $nick The Say mode is not enabled. To enable use %c $+ set_say <on|off>. Only the bot owner can enable this setting.
      halt
    }
    if ($readini(ini\globals.ini, Features, Say) == On) { 
      if ($2 == $null) {
        .msg $nick Command incomplete. Syntax: %c $+ act <text to say>.
        halt
      }
      if ($2 !== $null) {
        .describe $chan $2-
      }
    }
  }
}
on 100:text:*say*:#: {
  if ($1 == %c $+ set_say) {
    if ($level($mask($address($nick,2),2)) < 500) { .msg $nick Only the bot owner can enable the Say mode. | halt }
    if ($level($mask($address($nick,2),2)) == 500) { 
      if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ set_say <on|off>. | halt }
      if ($2 !== $null) {
        if ($2 == on) { writeini -n ini\globals.ini Features Say On | .msg $nick The Say mode is now enabled. | halt }
        if ($2 == off) { writeini -n ini\globals.ini Features Say Off | .msg $nick The Say mode is now disabled. | halt }
        else { .msg $nick >>> Error: Invalid parameters. Available parameters: ON/OFF. | halt }
      }
    }
  }
  if ($1 == %c $+ say) {
    if ($readini(ini\globals.ini, Features, Say) == Off) { .msg $nick The Say mode is not enabled. To enable use %c $+ set_say <on|off>. Only the bot owner can enable this setting. | halt }
    if ($readini(ini\globals.ini, Features, Say) == On) { 
      if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ say <text to say>. | halt }
      if ($2 !== $null) { .msg $chan $2- }
    }
  }
}
on 500:text:set_say*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me set_say <on|off>. | halt }
  if ($2 !== $null) {
    if ($2 == on) { writeini -n ini\globals.ini Features Say On | .msg $nick The Say mode is now enabled. | halt }
    if ($2 == off) { writeini -n ini\globals.ini Features Say Off | .msg $nick The Say mode is now disabled. | halt }
    else { .msg $nick >>> Error: Invalid parameters. Available parameters: ON/OFF. | halt }
  }
}
on 100:text:say*:?: {
  if ($readini(ini\globals.ini, Features, Say) == Off) { .msg $nick The Say mode is not enabled. To enable use /msg $me set_say <on|off>. Only the bot owner can enable this setting. | halt }
  if ($readini(ini\globals.ini, Features, Say) == On) { 
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me say <#channel> <text to say>. | halt }
    if (($2 !== $null) && ($3 == $null)) { .msg $nick You didn't specified any text to say. }
    if (($2 !== $null) && ($3 !== $null) && ($left($2,1) == $chr(35))) { .msg $2 $3- }
  }
}
ctcp *:VERSION:?: {
  .ctcpreply $nick VERSION $dbver(text) $+ . Get it at: $dbver(site) - The best Windows bot! 
}

on @25:text:*status*:#: {
  if ($1 == %c $+ status) {
    if ($2 == $null) { .msg $nick Please specifiy the display mode. Syntax: %c $+ status <public|private>. | halt }
    if ($2 == private) {
      .timer 1 1 .msg $nick Status information for $chan $+ :
      if ($chan($chan).topic !== $null) { .timer 1 3 .msg $nick Topic is $chan($chan).topic }
      .timer 1 5 .msg $nick Current channel modes: $chan($chan).mode $+ .
      .timer 1 7 .msg $nick There are currently $nick($chan,0) persons on the channel, $nick($chan,0,o) op(s), $nick($chan,0,v) voice(s) and $nick($chan,0,r) regular(s).
      .timer 1 9 .msg $nick Total bans: $ibl($chan,0) $+ .
    }
    if ($2 == public) {
      .timer 1 1 .msg $chan Status information for $chan $+ :
      if ($chan($chan).topic !== $null) { .timer 1 3 .msg $chan Topic is $chan($chan).topic }
      .timer 1 5 .msg $chan Current channel modes: $chan($chan).mode $+ .
      .timer 1 7 .msg $chan There are currently $nick($chan,0) persons on the channel, $nick($chan,0,o) op(s), $nick($chan,0,v) voice(s) and $nick($chan,0,r) regular(s).
      .timer 1 9 .msg $chan Total bans: $ibl($chan,0) $+ .
    }
  }
}
on 400:text:*autovoice*:#: {
  if ($1 == %c $+ autovoice) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ autovoice <on|off>. | halt }
    if ($2 !== $null) {
      if ($2 == on) { writeini -n ini\channels.ini $chan AutoVoice On | .msg $nick AutoVoice for $chan is now ON. Everyone that joins this channel will be voiced. | .msg $nick >>> WARNING: This makes channel lock more inefficient. | halt }
      if ($2 == off) { writeini -n ini\channels.ini $chan AutoVoice Off | .msg $nick AutoVoice for $chan is now OFF. Everyone that joins this channel will not be voiced anymore. | halt }
      else { .msg $nick >>> Error: Invalid parameters. Available parameters: ON/OFF. | halt }
    }
  }
}
on 400:text:autovoice*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax: /msg $me autovoice <#channel> <on|off>. | halt }
  if ($2 !== $null) {
    if ($3 == on) { writeini -n ini\channels.ini $2 AutoVoice On | .msg $nick AutoVoice for $2 is now ON. Everyone that joins this channel will be voiced. | .msg $nick >>> WARNING: This makes channel lock more inefficient. | halt }
    if ($3 == off) { writeini -n ini\channels.ini $2 AutoVoice Off | .msg $nick AutoVoice for $2 is now OFF. Everyone that joins this channel will not be voiced anymore. | halt }
    else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
  }
}
on 400:text:*bitchmode*:#: {
  if ($1 == %c $+ bitchmode) {
    if ($2 == $null) { .msg $nick Command incomlpete. Syntax: %c $+ bitchmode <on|off>. | halt }
    if ($2 !== $null) { 
      if ($2 == on) { writeini -n ini\channels.ini $chan Bitchmode On | .msg $nick The bitch mode for $chan is now enabled. Everyone that is oped by other person than the bot will be deoped. | halt }
      if ($2 == off) { writeini -n ini\channels.ini $chan Bitchmode Off | .msg $nick The bitch mode for $chan is now disabled. Everyone that is oped by other person than the bot will NOT be deoped anymore. | halt }
      else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
    }
  }
}
on 400:text:bitchmode*:?: {
  if ($2 == $null) { .msg $nick Command incomlpete. Syntax: /msg $me bitchmode <#channel> <on|off>. | halt }
  if ($2 !== $null) { 
    if ($3 == on) { writeini -n ini\channels.ini $2 Bitchmode On | .msg $nick The bitch mode for $2 is now enabled. Everyone that is oped by other person than the bot will be deoped. | halt }
    if ($3 == off) { writeini -n ini\channels.ini $2 Bitchmode Off | .msg $nick The bitch mode for $2 is now disabled. Everyone that is oped by other person than the bot will NOT be deoped anymore. | halt }
    else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
  }
}
on @1:op:#: {
  if ($readini(ini\channels.ini, $chan, Bitchmode) == On) {
    if ($nick == $me) { halt }
    if ($opnick == $me) { halt }
    if (($level($mask($address($nick,2),2)) >= 400) || ($level($mask($address($opnick,2),2)) >= 400)) { halt }
    else { mode $chan -o $opnick | .msg $nick The bitchmode for $chan is enabled. }
  }
}
on *:join:#: {
  if ($nick == $me) { 
    .timer 1 3 _main $chan
    .timerQub $+ $chan 0 5 qub $chan 
    .timerQb $+ $chan 0 5 qb $chan
    .timerQKlist $+ $chan 0 5 qk $chan
    .timerQdVoice $+ $chan 0 5 qdvoice $chan
    .timerQVoice $+ $chan 0 7 qvoice $chan
    .timerQm $+ $chan 0 30 _main $chan
    _float $chan
  }
  if ($me !isop $chan) && ($me !ishop $chan) { halt }
  if (($readini(ini\channels.ini, $chan, Greet) == On) && ($read(ini\grlines.txt, s, $chan) !== $null)) { .notice $nick $read(ini\grlines.txt, s, $chan) }
  if ($readini(ini\channels.ini, $chan, AutoVoice) == on) { 
    qvadd $chan $nick
    halt 
  }
  if ($readini(ini\channels.ini, $chan, AutoVoice) == off) { halt }
}
alias qvadd {
  ;Syntax: /qvadd <#channel> <nick>
  if ($istok(%qvoice [ $+ [ $1 ] ],$2,32) == $true) { halt }
  if (%qvoice [ $+ [ $1 ] ] == $null) { set %qvoice [ $+ [ $1 ] ] $2 | halt }
  if ((%qvoice [ $+ [ $1 ] ] !== $null) && ($numtok(%qvoice [ $+ [ $1 ] ],32) >= 6)) { qvoice $1 | set %qvoice [ $+ [ $1 ] ] $2  | halt }
  else { set %qvoice [ $+ [ $1 ] ] %qvoice [ $+ [ $1 ] ] $2 | halt } 
}
alias qdvadd {
  ;Syntax: /qdvadd <#channel> <nick>
  if ($istok(%qdvoice [ $+ [ $1 ] ],$2,32) == $true) { halt }
  if (%qdvoice [ $+ [ $1 ] ] == $null) { set %qdvoice [ $+ [ $1 ] ] $2 | halt }
  if ((%qdvoice [ $+ [ $1 ] ] !== $null) && ($numtok(%qdvoice [ $+ [ $1 ] ],32) >= 6)) { qdvoice $1 | set %qdvoice [ $+ [ $1 ] ] $2 | halt }
  else { set %qdvoice [ $+ [ $1 ] ] %qdvoice [ $+ [ $1 ] ] $2 } 
}
alias qbadd {
  ;Syntax: /qbadd <#channel> <host> <nick>
  if ($istok(%banned [ $+ [ $1 ] ],$2,32) == $true) { qkadd $1 $3 | halt }
  if ($istok(%qb [ $+ [ $1 ] ],$2,32) == $true) { halt }
  if (%qb [ $+ [ $1 ] ] == $null) { set %qb [ $+ [ $1 ] ] $2 | set %banned [ $+ [ $1 ] ] %banned [ $+ [ $1 ] ] $2 | qkadd $1 $3 | halt }
  if ((%qb [ $+ [ $1 ] ] !== $null) && ($numtok(%qb [ $+ [ $1 ] ],32) >= 6)) { qb $1 | set %qb [ $+ [ $1 ] ] $2 | set %banned [ $+ [ $1 ] ] %banned [ $+ [ $1 ] ] $2 | qkadd $1 $3 | halt }
  else { set %qb [ $+ [ $1 ] ] %qb [ $+ [ $1 ] ] $2 | set %banned [ $+ [ $1 ] ] %banned [ $+ [ $1 ] ] $2 | qkadd $1 $3  }
}
alias qbadd2 {
  ;Syntax: /qbadd <#channel> <host> <nick>
  if ($istok(%banned [ $+ [ $1 ] ],$2,32) == $true) { qkadd $1 $3 | return }
  if ($istok(%qb [ $+ [ $1 ] ],$2,32) == $true) { return }
  if (%qb [ $+ [ $1 ] ] == $null) { set %qb [ $+ [ $1 ] ] $2 | set %banned [ $+ [ $1 ] ] %banned [ $+ [ $1 ] ] $2 | qkadd $1 $3 | return }
  if ((%qb [ $+ [ $1 ] ] !== $null) && ($numtok(%qb [ $+ [ $1 ] ],32) >= 6)) { qb $1 | set %qb [ $+ [ $1 ] ] $2 | set %banned [ $+ [ $1 ] ] %banned [ $+ [ $1 ] ] $2 | qkadd $1 $3 | return }
  else { set %qb [ $+ [ $1 ] ] %qb [ $+ [ $1 ] ] $2 | set %banned [ $+ [ $1 ] ] %banned [ $+ [ $1 ] ] $2 | qkadd $1 $3  }
}
alias qbadd3 {
  ;Syntax: /qbadd2 <#channel> <host>
  if $level($2) > 1 || $2 iswm $address($me,5) { halt }
  if ($istok(%qb [ $+ [ $1 ] ],$2,32) == $true) { return }
  if (%qb [ $+ [ $1 ] ] == $null) { set %qb [ $+ [ $1 ] ] $2 | halt }
  if ((%qb [ $+ [ $1 ] ] !== $null) && ($numtok(%qb [ $+ [ $1 ] ],32) >= 6)) { qb $1 | set %qb [ $+ [ $1 ] ] $2 | halt }
  else { set %qb [ $+ [ $1 ] ] %qb [ $+ [ $1 ] ] $2 }
}
alias qkadd {
  if ($istok(%qkick [ $+ [ $1 ] ],$2,32) == $true) { return }
  set %qkick [ $+ [ $1 ] ] %qkick [ $+ [ $1 ] ] $2
}

on 500:text:*bp*:#: {
  if ($1 == %c $+ bp) {
    if ($2 == $null) { .msg $nick Command incomplete. Syntax: %c $+ bp <on|off>. | halt }
    if ($2 !== $null) {
      if ($2 == on) { .enable #ban | .msg $nick The Ban protection is now on. | halt }
      if ($2 == off) { .disable #ban | .msg $nick The Ban protection is now off. | halt }
      else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
    }
  }
}
on 500:text:bp*:?: {
  if ($2 == $null) { .msg $nick Command incomplete. Syntax:/msg $me bp <on|off>. | halt }
  if ($2 !== $null) {
    if ($2 == on) { .enable #ban | .msg $nick The Ban protection is now on. | halt }
    if ($2 == off) { .disable #ban | .msg $nick The Ban protection is now off. | halt }
    else { .msg $nick $cl Error: Invalid parameters. Available parameters: ON/OFF. | halt }
  }
}
on 1:part:#: {
  if ($nick == $me) {
    _dfloat $chan
    .timer* $+ $chan off
  }
}
on 1:kick:#: {
  if ($knick == $me) {
    .timer* $+ $chan off
  }
}

alias qub {
  if ($me !isop $1) && ($me !ishop $1) { return }
  if (%qub [ $+ [ $1 ] ] !== $null) { mode $1 - $+ $str(b,$numtok(%qub [ $+ [ $1 ] ],32)) %qub [ $+ [ $1 ] ]  }
  unset %qub [ $+ [ $1 ] ]
}
alias qb {
  if ($me !isop $1) && ($me !ishop $1) { return }
  if (%qb [ $+ [ $1 ] ] !== $null) { mode $1 + $+ $str(b,$numtok(%qb [ $+ [ $1 ] ],32)) %qb [ $+ [ $1 ] ]  }
  unset %qb [ $+ [ $1 ] ]
}
alias qdvoice {
  if ($me !isop $1) && ($me !ishop $1) { return }
  if (%qdvoice [ $+ [ $1 ] ] !== $null) { mode $1 - $+ $str(v,$numtok(%qdvoice [ $+ [ $1 ] ],32)) %qdvoice [ $+ [ $1 ] ]  }
  unset %qdvoice [ $+ [ $1 ] ]
}
alias qvoice {
  if ($me !isop $1) && ($me !ishop $1) { return }
  if (%qvoice [ $+ [ $1 ] ] !== $null) { mode $1 + $+ $str(v,$numtok(%qvoice [ $+ [ $1 ] ],32)) %qvoice [ $+ [ $1 ] ]  }
  unset %qvoice [ $+ [ $1 ] ]
}
alias qk {
  if ($me !isop $1) && ($me !ishop $1) { return }
  set %qkcount [ $+ [ $1 ] ] 0
  :loop
  inc %qkcount [ $+ [ $1 ] ] 1
  if ($gettok(%qkick [ $+ [ $1 ] ],%qkcount [ $+ [ $1 ] ],32) == $null) { return }
  if ($gettok(%qkick [ $+ [ $1 ] ],%qkcount [ $+ [ $1 ] ],32) !ison $1) { //set %qkick [ $+ [ $1 ] ] $remtok(%qkick [ $+ [ $1 ] ], $gettok(%qkick [ $+ [ $1 ] ], %qkcount [ $+ [ $1 ] ], 32),32) | goto loop }
  if ($gettok(%qkick [ $+ [ $1 ] ],%qkcount [ $+ [ $1 ] ],32) ison $1) {
    kick $1 $gettok(%qkick [ $+ [ $1 ] ],%qkcount [ $+ [ $1 ] ],32) $iif(%kb.reason != $null,$replace(%kb.reason,&url&,$readini(ini\channels.ini,$1,URL)),Out)
    //set %qkick [ $+ [ $1 ] ] $remtok(%qkick [ $+ [ $1 ] ], $gettok(%qkick [ $+ [ $1 ] ], %qkcount [ $+ [ $1 ] ], 32),32)
    goto loop
  }
}
#ban on
on @!*:ban:#: {
  if (($banmask iswm $address($me,5)) && ($level($mask($address($nick,2),2)) == 500)) { 
    if (%qub [ $+ [ $chan ] ] == $null) { set %qub [ $+ [ $chan ] ] $banmask | halt }
    if ((%qub [ $+ [ $chan ] ] !== $null) && ($numtok(%qub [ $+ [ $chan ] ], 32) >= 6)) { qub $chan | set %qub [ $+ [ $chan ] ] $banmask | halt }
    else { set %qub [ $+ [ $chan ] ] %qub [ $+ [ $chan ] ] $banmask | halt } 
  }
  if (($banmask iswm $address($me,5)) && ($level($mask($address($nick,2),2)) !== 500)) {
    mode $chan -o $nick 
    if (%qub [ $+ [ $chan ] ] == $null) { set %qub [ $+ [ $chan ] ] $banmask | halt }
    if ((%qub [ $+ [ $chan ] ] !== $null) && ($numtok(%qub [ $+ [ $chan ] ], 32) >= 6)) { qub $chan | set %qub [ $+ [ $chan ] ] $banmask | halt }
    else { set %qub [ $+ [ $chan ] ] %qub [ $+ [ $chan ] ] $banmask | halt } 
  }
  if (($level($banmask) > 1) && ($level($address($nick,2)) !== 500)) { 
    mode $chan -o $nick 
    if (%qub [ $+ [ $chan ] ] == $null) { set %qub [ $+ [ $chan ] ] $banmask | halt }
    if ((%qub [ $+ [ $chan ] ] !== $null) && ($numtok(%qub [ $+ [ $chan ] ], 32) >= 6)) { qub $chan | set %qub [ $+ [ $chan ] ] $banmask | halt }
    else { set %qub [ $+ [ $chan ] ] %qub [ $+ [ $chan ] ] $banmask | halt } 
  }
  ;if (($level($address($nick,2)) > 1) && ($level($banmask) !< $level($address($nick,2)))) { halt }
  var %ban.total = $ialchan($banmask,$chan,0)
  if (%ban.total > 600) { halt }
  var %ban.current = 0
  while (%ban.total > %ban.current) {
    inc %ban.current
    var %ban.nick = $ialchan($banmask,$chan,%ban.current).nick
    if (%ban.nick == $me)  { continue }
    if ($banmask iswm $address($me,5)) { halt }
    if ($banmask iswm $address(%ban.nick,5)) {
      if (%ban.nick isop $chan)  { halt } 
      else { 
        ;/qkadd <#channel> <nick> - queues output so the bot doesn't flood itself off the server while kicking
        ;also, it won't touch channel ops
        qkadd $chan %ban.nick 
      }
    }
  }
}
#ban end
alias _enforce {
  ;Syntax: /_enforce <#channel> <hostmask>
  set %ban.total [ $+ [ $1 ] ] [ $+ [ $2 ] ]  $ialchan($2,$1,0)
  if (%ban.total [ $+ [ $1 ] ] [ $+ [ $2 ] ] > 600) { halt }
  set %ban.current [ $+ [ $1 ] ] [ $+ [ $2 ] ]  0
  if %ban.total [ $+ [ $1 ] ] [ $+ [ $2 ] ] == 0 { halt }
  qbadd2 $1 $2
  while (%ban.total [ $+ [ $1 ] ] [ $+ [ $2 ] ] > %ban.current [ $+ [ $1 ] ] [ $+ [ $2 ] ]) {
    inc %ban.current [ $+ [ $1 ] ] [ $+ [ $2 ] ]
    set %ban.nick [ $+ [ $1 ] ] [ $+ [ $2 ] ]  $ialchan($2,$1,%ban.current [ $+ [ $1 ] ] [ $+ [ $2 ] ]).nick
    if (%ban.nick [ $+ [ $1 ] ] [ $+ [ $2 ] ] == $me)  { continue }
    if ($2 iswm $address($me,5)) { halt }
    if ($2 iswm $address(%ban.nick [ $+ [ $1 ] ] [ $+ [ $2 ] ],5)) {
      if (%ban.nick [ $+ [ $1 ] ] [ $+ [ $2 ] ] isop $1)  { halt } 
      else { 
        ;/qkadd <#channel> <nick> - queues output so the bot doesn't flood itself off the server while kicking
        ;also, it won't touch channel ops
        qkadd $1 %ban.nick [ $+ [ $1 ] ] [ $+ [ $2 ] ]
      }
    }
  }
}
