alias swjbot $iif($sock(jbot).status == active,sockwrite -nt jbot $1-)

on *:sockclose:jbot:$+(.timer,jbot) 1 2 sockopen jbot $_sunucuip $_port
on *:sockopen:jbot:{
  if ($sockerr) { sockclose jbot | $+(.timer,jbot) 1 2 sockopen jbot $_sunucuip $_port | returnex }
  swjbot NICK $+($_jbot,$r(10,9999)) 
  swjbot USER $_ident "" " $+ $iif($host,$host,$ip) $_username
  sockmark $sockname $_jbot
}
on *:sockread:jbot:{
  if ($sockerr) { sockclose jbot | $+(.timer,jbot) 1 2 sockopen jbot $_sunucuip $_port | returnex }
  var %;jbot | sockread %;jbot | tokenize 32 %;jbot
  if ($1 = ping) swjbot pong $remove($2,:) 
  elseif $regex($2,/(001|433)/) { swjbot oper $_oper | swjbot ns ghost $_jbot $_pass | swjbot ns release $_jbot $_pass | swjbot join #0,0 | $+(.timer,$rand(100,999)) 1 3 swjbot nick $_jbot }
  elseif $1 == error && $2 == :closing { sockclose jbot | $+(.timer,jbot) 1 2 sockopen jbot $_sunucuip $_port }  
  elseif $regex($2,/(473|475|471|474)/) { swjbot sajoin $_jbot $4 }
  elseif $regex($2,/(481|411)/) { swjbot oper $_oper | swjbot nick $_jbot | swjbot nickserv identify $_pass }
  elseif ($2 == NICK) { 
    if $_nick($1) == $_jbot { swjbot ns ghost $_jbot $_pass | swjbot ns release $_jbot $_pass | $+(.timer,$rand(100,999)) 1 3 swjbot nick $_jbot }
    elseif $right($3,-1) == $_jbot {
      swjbot nickserv identify $_pass      
      swjbot oper $_oper
      $iif($_supass,swjbot os su $_supass)
      swjbot join 0,0
      swjbot mode $right($3,-1) +qHp-h
      swjbot chghost $right($3,-1) $_host
      $+(.timer,_jbotgir) 1 5 swjbot sajoin $right($3,-1) $+($_kontrol,$chr(44),$_bots)
    }
  }
  elseif $regex($2,/366/) && !$istok($_kontrol $_bots,$4,32) { swjbot part $4 }  
  elseif $regex($2,/^PART$/i) {
    if $regex($_nick($1),/^ $+ $_jbot $+ $/Si) && $istok($_kontrol $_bots,$3,32) { swjbot sajoin $_nick($1) $3 }
  }
  elseif $regex($2,/^KICK$/i) {
    if $regex($4,/^ $+ $_jbot $+ $/Si) && $istok($_kontrol $_bots,$3,32) { swjbot sajoin $4 $3 }
  }
  elseif $regex($2,/^JOIN$/i) {
    if $regex($_nick($1),/ $+ $+(^,$_jbot,$) $+ /Si) {
      if $istok($_kontrol $_bots,$right($3,-1),32) {
        swjbot mode $right($3,-1) -qao+h $str($+($_nick($1),$chr(32)),5)
        swjbot mode $_nick($1) +qHp-h
        swjbot chghost $_nick($1) $_host
      }
    }
  }
  elseif $regex($2,/^MODE$/Si) && $regex($3,/^#/) {
    if $regex($4,^\+(\S+)?(b)(\S+)?) && $5 {
      swjbot mode $3 -b *!*@*
      if $regex($5-,/ $+ $_jbot $+ /i) { swjbot mode $3 -b $_jbot }
    }
    elseif $regex($4,^\-(\S+)?(h)(\S+)?) || $regex($4,^\+(\S+)?(a|q|o)(\S+)?) && $regex($5-,/ $+ $_jbot $+ /i) { swjbot mode $3 -qao+h $str($+($_jbot,$chr(32)),5) }
  }
  elseif $regex($2,/^NOTICE$/Si) && $regex($4-,/Client connecting on port/Si) {
    var %:nickj $token($token($4-,1,40),-1,32), %:identj $token($token($4-,1,64),2,40), %:ipj $token($token($4-,2,64),1,41), %:portj $token($token($4-,1,58),-1,32)
    if $istok($_sunucuip %:myip,%:ipj,32) && ($_nickler(%:nickj) == 0) { $+(.timer,%:nickj,¿join) 1 4 _dagit %:nickj | return }
    if $hget(MuafPort,%:portj) || $hget(MuafNick,%:nickj) || $hget(MuafIP,%:ipj) { $+(.timer,%:nickj,¿join) 1 4 _dagit %:nickj | return }
    ;swjbot shun %:nickj +80 4IRC Giriş Sistemi
    ;swjbot sajoin %:nickj $_kontrol
    if (%:proxy == on) {
      if $hget(Proxy,%:ip) || $regex(%:ip,/CableLink/Si) || $hget(Proxy1,%:ip) {
        swjbot gline $+(*@,%:ip) +5h Proxy Yasak.. [HASH] 
        return 
      }
    }

    if (%:yasakip == on) {
      if $hget(YasakIP,%:ip) || $regex(%:ip,/CableLink/Si) || $hget(YasakIP,%:ip) {
        swjbot gzline $+(*@,%:ip) +5h Sabıkalı IP bloğu kullandığınız için giriş yapamazsınız. (irc@kahkaha.gen.tr adresine IP ve Nick bilgisi gönderebilirsiniz.) [HASH] 
        return 
      }
    }

  }
}

alias _dagit { 
  ;swjbot shun $+(-*@,$2) | swjbot shun $+(-,$1)
  ;swjbot os raw svspart $1 $_kontrol 
  ;swjbot os raw svsjoin $1 $_gkanal
}
