Pages

Saturday, August 27, 2011

egoz.tcl

##########################
set max_length 200
set max_length_ban 5
set max_caps 15
set max_repeat 2
set inviter_ban 180
set badword_ban 5
set badwords {
""
"#?"
"j?nc?k"
"j?nc?x"
"ganc?k"
"ganc?x"
"orgasm"
"d?nc?k"
"d?nc?x"
"d?anc?k"
"d?anc?x"
"damput"
"dampot"
"ancok"
"ancuk"
"anc0k"
"d a n c ? k"
"j a n c ? k"
"fuck"
"kont?l"
"k?ont?l"
"konth?l"
"memek"
"memeq"
"memex"
"pepek"
"temp?k"
"temp?x"
"nenen"
"jembu*t"
"j?embu*t"
"jembo*t"
"j?embo*t"
"jemb0*t"
"j?emb0*t"
"jembo*d"
"j?embo*d"
"gath?l"
"kenthu"
"vagina"
"bawuk"
"bawok"
" itil "
" itel "
"ngacen?"
"nguacen?"
"ngwacen?"
"masturb"
"ngloco"
"pejuh"
"pejoh"
"nonok"
"kentu"
"coli"
" asu "
" kete "
"rakete"
"matamu"
"matane"
"kunam"
"kimpet"
"tempeek"
"anjin?"
"(?)*(?)*(?)*(?)*(?)*(?)"
":*-*:*-*:*-*:*-*:*-"
":*-*:*-*:*-*(?)*(?)*(?)"
""
}




################## g0eZ AddOns ##################

proc ccodes:filter {str} {
  regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str
  return $str
}

bind RAW - PRIVMSG msgcheck
bind RAW - NOTICE msgcheck

proc msgcheck {from key arg} {
 global botnick
 set arg [split $arg]
 set nick [lindex [split $from !] 0]
 set uhost [string range $from [expr [string first "!" $from]+1] e]
 set target [lindex $arg 0]
 if {![string match *#* $target]} { set hand "*" }
 if {[string match *#* $target]} { set hand [nick2hand $nick $target] }
 set text [string range [join [lrange $arg 1 end]] 1 end]
 if {[isbotnick $nick]} {return}
 if {[string match ** $text]} {
  set text [string range [join [lrange $arg 1 end]] 0 end]
 }
 split:pub:msg $nick $uhost $hand $target $text
}
proc split:pub:msg {nick uhost hand target text} {
# if {![string match *#* $target]} {priv:msg $nick $uhost $hand $target $text}
 if {[string match *#* $target]} {pub:msg $nick $uhost $hand $target $text}
}
proc pub:msg {nick uhost hand target text} {
 long:text $nick $uhost $hand $target $text
 caps:lock $nick $uhost $hand $target $text
 no:repeat $nick $uhost $hand $target $text
 no:badword $nick $uhost $hand $target $text
 split:cmd $nick $uhost $hand $target $text
}


proc long:text {nick uhost hand chan arg} {
 global max_length max_length_ban
 if {[matchattr $hand b] || [matchattr $hand f|f $chan] || [matchattr $hand mo|mo $chan]} { return }
 set banmask "*![lindex [split $uhost "@"] 0]@[lindex [split [maskhost $uhost] "@"] 1]"
 if {[string length $arg] >= $max_length} {
  if {[isop $nick $chan]} {
   putquick "KICK $chan $nick :jangan panjang² to $nick kasian yang akai hape itu loh.."
   return
  }
  putquick "KICK $chan $nick :Jangan panjang² donk!! Maks. $max_length karakter, ku banned $max_length_ban menit "
  newchanban $chan $banmask AutoBan LongText $max_length_ban sticky
  return
 }
}


proc caps:lock {nick uhost hand chan arg} {
 global max_caps
 set text [ccodes:filter $arg]
 set upper 0
 foreach i [split $text {}] { if [string match \[A-Z\] $i] { incr upper } }
 if {$upper == 0} { return }
 if {[string length $text] < $max_caps} { return }
 set capchar [string length $text]
 set number $upper/$capchar
 if {[matchattr $hand b] || [matchattr $hand f|f $chan] || [matchattr $hand mo|mo $chan]} { return }
 if {[expr 30 * $upper / $capchar] > $max_caps} {
  putquick "KICK $chan $nick :Ups.. CapsLock nya kecantol tuh.."
 }
}


proc no:repeat {nick uhost hand chan text} {
  global repeat_last repeat_num max_repeat
  set text [ccodes:filter $text]
  if {[matchattr $hand b] || [matchattr $hand f|f $chan] || [matchattr $hand mo|mo $chan]} { return }
  if [info exists repeat_last([set n [string tolower $nick]])] {
    if {[string compare [string tolower $repeat_last($n)] \
        [string tolower $text]] == 0} {
      if {[incr repeat_num($n)] >= ${max_repeat}} {
        putquick "KICK $chan $nick :walah.. jangan di ulang² pliss.."
        unset repeat_last($n)
        unset repeat_num($n)
      }
      return
    }
  }
  set repeat_num($n) 1
  set repeat_last($n) $text
}
bind nick - * repeat_nick
proc repeat_nick {nick uhost hand chan newnick} {
  if [matchattr $hand f] {return 0}
  global repeat_last repeat_num
  catch {set repeat_last([set nn [string tolower $newnick]]) \
         $repeat_last([set on [string tolower $nick]])}
  catch {unset repeat_last($on)}
  catch {set repeat_num($nn) $repeat_num($on)}
  catch {unset repeat_num($on)}
}
proc repeat_timr {} {
  global repeat_last
  catch {unset repeat_last}
  catch {unset repeat_num}
  timer 1 repeat_timr
}
if ![regexp repeat_timr [timers]] {
  timer 1 repeat_timr
}


proc no:badword {nick uhost handle channel args} {
 global badwords badword_ban
 set args [ccodes:filter $args]
 foreach badword [string tolower $badwords] {    
  if {[string match *$badword* [string tolower $args]]} {
   set banmask "*![lindex [split $uhost "@"] 0]@[lindex [split [maskhost $uhost] "@"] 1]"
   set badreason "Kalau Ketik Sopan Dikit Bisa Kan!! banned $badword_ban menit"
   if {[matchattr $handle +f]} {
    putquick "NOTICE $nick :Begh Kalau Ketik Sopan Dikit Bisa Kan!! "
    return
   }
   if {[isop $nick $channel]} {
    putquick "KICK $channel $nick :ini @OP badung banget.. Ku Del ACC kamu ntar..!!"
    return
   }
   putquick "KICK $channel $nick :$badreason"
   newchanban $channel $banmask AutoBan BadWord $badword_ban sticky
  }
 }
}


bind part - * fuck:inviter
proc fuck:inviter {nick uhost hand chan reason} {
 global banmask inviter_ban
 set reason [ccodes:filter $reason]
 set banmask "*![lindex [split $uhost "@"] 0]@[lindex [split [maskhost $uhost] "@"] 1]"
 if {[string match *echo*invit* [string tolower $reason]]} {
  putquick "MODE $chan -b+b 4Fuck3!4echoX3@4inviter $banmask"
  newchanban $chan $banmask AutoBan echoXinviter $inviter_ban sticky
  putquick "KICK $chan :$nick Inviter Salah masuk euy.... "
 }
 if {[string match ** [string tolower $reason]]} {
  putquick "MODE $chan -b+b Banjir...... $banmask"
  newchanban $chan $banmask AutoBan tsunamer $inviter_ban sticky
  putquick "KICK $chan :$nick Tsunami kok disini!!"
 }
 if {[string match *#* [string tolower $reason]]} {
  putquick "MODE $chan -b+b Inviter Dilarang keras masuk sini $banmask"
  newchanban $chan $banmask AutoBan inviterjancok $inviter_ban sticky
  putquick "KICK $chan :$nick NakaL"
 }
}


set badnickban 30
set badnickkickreason "Gue gak suka Nick/Ident/Host Loe.. Banned $badnickban menit"

bind join - * join:badnick
bind nick - * change:badnick

proc join:badnick {nick uhost hand chan} {
 global botnick badwords badnickkickreason badnickban
 if {$nick == $botnick} {return}
 set ident [lindex [split $uhost "@"] 0]
 set host [lindex [split $uhost @] 1]
 foreach badnick [string tolower $badwords] {
  if {[matchattr $hand f]} { return }
  if {[string match *$badnick* [string tolower $nick]]} {
   putquick "KICK $chan $nick :$badnickkickreason"
   newchanban $chan *$badnick*!*@* AutoBan BadNick $badnickban sticky
   return 0
  }
  if {[string match *$badnick* [string tolower $ident]]} {
   putquick "KICK $chan $nick :$badnickkickreason"
   newchanban $chan *!*$badnick*@* AutoBan BadIdent $badnickban sticky
   return 0
  }
  if {[string match *$badnick* [string tolower $host]]} {
   putquick "KICK $chan $nick :$badnickkickreason"
   newchanban $chan *!*@*$badnick* AutoBan BadHost $badnickban sticky
   return 0
  }
 }
}
proc change:badnick {nick uhost hand chan newnick} {
 global botnick badwords badnickkickreason badnickban
 if {$nick == $botnick} {return}
 foreach badnick [string tolower $badwords] {
  if {[matchattr $hand f]} { return }
  if {[string match *$badnick* [string tolower $newnick]]} {
   putquick "KICK $chan $newnick :$badnickkickreason"
   newchanban $chan *$badnick*!*@* AutoBan BadNick $badnickban sticky
   return 0
  }
 }
}

bind time - "* * * * *" Chan:Limit
proc Chan:Limit {min hour day month year} {
    foreach chan [channels] {
    set newlimit [expr [llength [chanlist $chan]] + 10]
    set currentlimit [currentlimit $chan]
    if {$currentlimit < [expr $newlimit - 1] || $currentlimit > [expr $newlimit + 1]} {
        putquick "mode $chan +l $newlimit"
    }
    }   
}
proc currentlimit {chan} {
    set currentmodes [getchanmode $chan]
    if {[string match "*l*" [lindex $currentmodes 0]]} {
    return [lindex $currentmodes end]
    }
    return 0
}
proc split:cmd {nick uhost hand chan text} {
 global botnick
 set text [ccodes:filter $text]
 set cmd [lindex $text 0]
 set cmd [string tolower $cmd]
 set string [lrange $text 1 end]
 if {($cmd == ".help") || ($cmd == "!help")} { putquick "NOTICE $nick :Perintah 15:15| 12.seen 15| 12.ping 15| 12.dns 15| 12.dns6 15| 12.port 15| 12.ip 15| 12.dwhois 15| 12.calc 15| 12.time 15| 12.whois 15| 12«14« 3R4unn6i7ng 8T7cL9 12g010e14Z 11»13» " }
 if {($cmd == ".dns") || ($cmd == "!dns")} { pub:dns $nick $uhost $hand $chan $text }
 if {($cmd == ".dns6") || ($cmd == "!dns6") || ($cmd == "`dns6")} { pub:dns6 $nick $uhost $hand $chan $text }
 if {($cmd == ".dwhois") || ($cmd == "!dwhois")} { pub:dwhois $nick $uhost $hand $chan $text }
 if {($cmd == ".ip") || ($cmd == "!ip")} { pub:ipwhois $nick $uhost $hand $chan $text }
 if {($cmd == ".port") || ($cmd == "!port")} { pub:cekport $nick $uhost $hand $chan $text }
 if {($cmd == ".calc") || ($cmd == "!calc")} { pub:hitung $nick $uhost $hand $chan $text }
 if {($cmd == ".jam") || ($cmd == "!jam") || ($cmd == ".time") || ($cmd == "!time")} { pub:time $nick $uhost $hand $chan $text }
 if {($cmd == ".ping") || ($cmd == "!ping")} { pub:ping $nick $uhost $hand $chan $text }
 if {($cmd == ".uptime") || ($cmd == "!uptime")} { pub:uptime $nick $uhost $hand $chan $text }
 if {($cmd == ".whois") || ($cmd == "!whois")} { pub:whoisnick $nick $uhost $hand $chan $text }
 if {($cmd == ".seen") || ($cmd == "!seen")} { pub:seen $nick $uhost $hand $chan $text }
 if {($cmd == ".seennick") || ($cmd == "!seennick")} { pub:seennick $nick $uhost $hand $chan $text }
 if {($cmd == ".seenstats") || ($cmd == "!seenstats")} { pub:seenstats $nick $uhost $hand $chan $text }
 if {($cmd == ".chanstats") || ($cmd == "!chanstats")} { pub:chanstats $nick $uhost $hand $chan $text }
 if {($cmd == ".lastspoke") || ($cmd == "!lastspoke")} { pub:lastspoke $nick $uhost $hand $chan $text }
 if {($cmd == ".idle") || ($cmd == "!idle")} { pub:cekidle $nick $uhost $hand $chan $text }
 if {($cmd == ".host") || ($cmd == "!host")} { pub:userhost $nick $uhost $hand $chan $text }
}


proc pub:dns {nick uhost hand chan text} {
 set hostip [lindex $text 1]
 if {$hostip == ""} {
  putquick "NOTICE $nick :Aturan Pakai : .dns <host/ip>"
  } else {
  dnslookup $hostip dns:rep $chan $hostip
 }
}
proc dns:rep {ip host status chan hostip} {
 if {!$status} {
  putquick "privmsg $chan :«!» Ga ada hasil untuk $hostip «!»"
 } elseif {[regexp -nocase -- $ip $hostip]} {
  putquick "privmsg $chan :«!» Hasil untuk $ip «-» $host «!»"
 } else {
  putquick "privmsg $chan :«!» Hasil untuk $host «-» $ip «!»"
 }
}


proc pub:dns6 {nick uhost hand chan text} {
 global botnick
 set cmd "nslookup"
 set orig [lindex $text 1]
 if {$orig == ""} {
  putquick "NOTICE $nick :Aturan Pakai : 4.dns6 <host/ipv6>"
  return
 }
 if {[string match "*:*.*" $orig]} {
  putquick "PRIVMSG $chan :«!» $orig is invalid host/ipv6 «!»"
  return
 }
 if {[string match "*.*:*" $orig]} {
  putquick "PRIVMSG $chan :«!» $orig is invalid host/ipv6 «!»"
  return
 }
 catch {exec $cmd -type=any $orig} input
 set result ""
 set fnd 0
 foreach line [split $input "\n"] {
  if {[string match "*ip6.\[int|arpa\]*name*=*" $line] || [string match "*IPv6 address*=*" $line]} {
   set result [string trim [lindex [split $line "="] 1]]
   break
  } elseif {[string match "*has AAAA*" $line]} {
   set result [lindex [split $line] [expr [llength [split $line]] - 1]]
   break
  }
 }
 if {$result == ""} {
  putquick "PRIVMSG $chan :«!» Ga ada Hasil untuk $orig «!»"
  return
 }
 putquick "PRIVMSG $chan :«!» Hasil untuk $orig «-» $result «!»"
 return
}



proc pub:dwhois {nick host handle chan text} {
 set server "isfree.schlundtec.com"
 set port 80
 set l 14
 set i 0
 set path "/cgi-bin/isfree.cgi?nodesign=1&domain=[lindex $text 1]"
 set sockdw [socket $server $port]
 puts $sockdw "GET $path HTTP/1.0"
 puts $sockdw "User.Agent:Mozilla"
 puts $sockdw "Host: $server"
 puts $sockdw ""
 flush $sockdw
 while {$i <= $l} {
  gets $sockdw linedw
  if {[string match "*Domain*frei*" $linedw]} {
   putquick "PRIVMSG $chan :«!» Domain [lindex $text 1] Belom Terdaftar «!»"
   close $sockdw
   return 0
  }
  if {[string match "*Domain*registriert*" $linedw]} {
   gets $sockdw
   putquick "PRIVMSG $chan :«!» Informasi untuk [lindex $text 1] : [html [gets $sockdw]], [html [gets $sockdw]], [html [gets $sockdw]], [html [gets $sockdw]], [html [gets $sockdw]] «!»"
   close $sockdw
   return 0
 }
 incr i
 }
 close $sockdw
}
proc html { text } {
 regsub -all "</TD>" $text "" text
 regsub -all "</FONT>" $text "" text
 regsub -all "    " $text "" text
 regsub -all "&uuml;" $text "ü" text
 regsub -all "&ouml;" $text "ö" text
 regsub -all "&auml;" $text "ä" text
 regsub -all "&Uuml;" $text "Ü" text
 regsub -all "&Ouml;" $text "Ö" text
 regsub -all "&Auml;" $text "Ä" text
 regsub -all "&szlig;" $text "ß" text
 regsub -all "&quot;" $text "\"" text
 regsub -all "<tb>" $text "" text
 regsub -all "<font" $text "" text
 regsub -all "size=\"2\"" $text "" text
 regsub -all "face=\"Verdana,Arial,Helvetica,Geneva\">" $text "" text
 regsub -all "<br>" $text "" text
 regsub -all "&nbsp;" $text "" text
 regsub -all "</font>" $text "" text
 regsub -all "<td>" $text "" text
 regsub -all "</td>" $text "" text
 regsub -all "<b>" $text "" text
 regsub -all "</b>" $text "" text
 regsub -all "</pre>" $text "" text
 return $text
}



set whoisinfo(port) 43
set whoisinfo(ripe) "whois.ripe.net"
set whoisinfo(arin) "whois.arin.net"
set whoisinfo(apnic) "whois.apnic.net"
set whoisinfo(lacnic) "whois.lacnic.net"
set whoisinfo(afrinic) "whois.afrinic.net"
proc whoisinfo_setarray {} {
 global query
 set query(netname) "(none)"
 set query(country) "(none)"
 set query(orgname) "(none)"
 set query(orgid) "(none)"
 set query(range) "(none)"
}
proc whoisinfo_display { chan } {
 global query
 putquick "PRIVMSG $chan :«!» Jarak : $query(range) - NamaNet : $query(netname) - Organisasi : $query(orgname) - Wilayah: $query(country) «!»"
}
proc pub:ipwhois {nick uhost handle chan search} {
 set search [lindex $search 1]
 if {$search == ""} {
  putquick "NOTICE $nick :12ip-nya berapa g0eZ?"
  return
 }
 global whoisinfo
 global query
 whoisinfo_setarray
 if {[whoisinfo_whois $whoisinfo(arin) $search]==1} {
  if {[string compare [string toupper $query(orgid)] "RIPE"]==0} {
   if {[whoisinfo_whois $whoisinfo(ripe) $search]==1} {
    whoisinfo_display $chan
   }
  } elseif {[string compare [string toupper $query(orgid)] "APNIC"]==0} {
   if {[whoisinfo_whois $whoisinfo(apnic) $search]==1} {
    whoisinfo_display $chan
   }
  } elseif {[string compare [string toupper $query(orgid)] "LACNIC"]==0} {
   if {[whoisinfo_whois $whoisinfo(lacnic) $search]==1} {
    whoisinfo_display $chan
   }
  } elseif {[string compare [string toupper $query(orgid)] "AFRINIC"]==0} {
   if {[whoisinfo_whois $whoisinfo(afrinic) $search]==1} {
    whoisinfo_display $chan
   }
 } else {
   whoisinfo_display $chan
  }
 } else {
  if { [info exist query(firstline)] } {
   putquick "PRIVMSG $chan :$query(firstline)"
  } else {
   putquick "PRIVMSG $chan :Gagal"
  }
 }
}

proc whoisinfo_whois {server search} {
 global whoisinfo
 global query
 set desccount 0
 set firstline 0
 set reply 0
# putlog "Whois: $server:$whoisinfo(port) -> $search"
 if {[catch {set sock [socket -async $server $whoisinfo(port)]} sockerr]} {
  putquick "PRIVMSG $chan :Gagal: $sockerr. Koneksi Gue Lagi Lemotz."
  close $sock
  return 0
 }
 puts $sock $search
 flush $sock
 while {[gets $sock whoisline]>=0} {
# putlog "Whois: $whoisline"
  if {[string index $whoisline 0]!="#" && [string index $whoisline 0]!="%" && $firstline==0} {
   if {[string trim $whoisline]!=""} {
    set query(firstline) [string trim $whoisline]
    set firstline 1
   }
  }
  if {[regexp -nocase {netname:(.*)} $whoisline all item]} {
   set query(netname) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {owner-c:(.*)} $whoisline all item]} {
   set query(netname) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {country:(.*)} $whoisline all item]} {
   set query(country) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {descr:(.*)} $whoisline all item] && $desccount==0} {
   set query(orgname) [string trim $item]
   set desccount 1
   set reply 1
  } elseif {[regexp -nocase {orgname:(.*)} $whoisline all item]} {
   set query(orgname) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {owner:(.*)} $whoisline all item]} {
   set query(orgname) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {orgid:(.*)} $whoisline all item]} {
   set query(orgid) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {inetnum:(.*)} $whoisline all item]} {
   set query(range) [string trim $item]
   set reply 1
  } elseif {[regexp -nocase {netrange:(.*)} $whoisline all item]} {
   set query(range) [string trim $item]
   set reply 1
  }
 }
 close $sock
 return $reply
}



set portchk_setting(read) 1
proc pub:cekport {nick uhost hand chan text} {
 global portchk_setting
 set host [lindex [split $text] 1]
 set port [lindex [split $text] 2]
 if {$port == ""} {
  putquick "NOTICE $nick :Aturan Pakai :4 $portchk_setting(cmd_pub) 7<host> <port> "
  return
 }
 if {[catch {set sock [socket -async $host $port]} error]} {
  putquick "PRIVMSG $chan :«!» Koneksi $host «-» $port Gak bisa bos «!»"
 } else {
  set timerid [utimer 15 [list portchk_timeout_pub $chan $sock $host $port]]
  fileevent $sock writable [list portchk_connected_pub $chan $sock $host $port $timerid]
 }
}
proc portchk_connected {idx sock host port timerid} {
 killutimer $timerid
 set error [fconfigure $sock -error]
 if {$error != ""} {
  close $sock
  putdcc $idx "«!» Koneksi $host «-» $port «-» Gagal \([string totitle $error]\) «!»"
 } else {
  fileevent $sock writable {}
  fileevent $sock readable [list portchk_read $idx $sock $host $port]
  putdcc $idx "«!» Koneksi $host «-» $port «-» Diterima «!»"
 }
}
proc portchk_timeout {idx sock host port} {
 close $sock
 putdcc $idx "«!» Koneksi $host «-» $port «-» Lagi Timed Out «!»"
}
proc portchk_read {idx sock host port} {
 global portchk_setting
 if {$portchk_setting(read)} {
  if {[gets $sock read] == -1} {
   putdcc $idx "«!» Koneksi $host «-» $port «-» Gagal Sudah Ditutup «!»"
   close $sock
  } else {
   putdcc $idx "$host \($port\) > $read"
  }
 } else {
  close $sock
 }
}
proc portchk_connected_pub {chan sock host port timerid} {
 killutimer $timerid
 set error [fconfigure $sock -error]
 if {$error != ""} {
  close $sock
  putquick "PRIVMSG $chan :«!» Koneksi $host «-» $port «-» Gagal \([string totitle $error]\) «!»"
 } else {
  fileevent $sock writable {}
  fileevent $sock readable [list portchk_read_pub $chan $sock $host $port]
  putquick "PRIVMSG $chan :«!» Koneksi $host «-» $port «-» Diterima «!»"
 }
}
proc portchk_timeout_pub {chan sock host port} {
 close $sock
 putquick "PRIVMSG $chan :«!» Koneksi $host «-» $port «-» Lagi Timed Out «!»"
}
proc portchk_read_pub {sock} {
 global portchk_setting
 if {!$portchk_setting(read)} {
  close $sock
 } elseif {[gets $sock read] == -1} {
  putquick "PRIVMSG $chan :«!» Koneksi $host «-» $port «-» Gagal Sudah Ditutup «!»"
  close $sock
 }
}



proc pub:hitung {nick uhost hand chan text} {
 set text [lindex $text 1]
 if {$text == ""} {
  putquick "NOTICE $nick :04Mau ngitung apaan sich..?"
  return 0
 }
 regsub -all "x" $text "*" math
 regsub -all "pi" $math "3.1415926535897932" math
 if {![regexp -all {\[} $text] || ![regexp -all {\]} $text]} {
  putquick "NOTICE $nick :«!» $text «-» [expr $math] «!»"
 } else {
  putquick "NOTICE $nick :«!» Karakter Salah! «!»"
 }
}



bind RAW - 391 timereply
proc pub:time { nick uhost hand chan text } {
 global botnick
 set text [lindex $text 1]
 putquick "TIME $text"
 set ::timechan $chan
}
proc timereply { from keyword arguments } {
 set channel $::timechan
 time:output $channel $arguments
}
proc time:output { channel arguments } {
global botnick
 set day [lindex [split $arguments] 2]
 if {$day == ":Monday"} { set hari "Senin" }
 if {$day == ":Tuesday"} { set hari "Selasa" }
 if {$day == ":Wednesday"} { set hari "Rabu" }
 if {$day == ":Thursday"} { set hari "Kamis" }
 if {$day == ":Friday"} { set hari "Jum'at" }
 if {$day == ":Saturday"} { set hari "Sabtu" }
 if {$day == ":Sunday"} { set hari "Minggu" }
 set tanggal [lindex [split $arguments] 4]
 set month [lindex [split $arguments] 3]
 if {$month == "January"} { set bulan "Januari" }
 if {$month == "February"} { set bulan "Februari" }
 if {$month == "March"} { set bulan "Maret" }
 if {$month == "April"} { set bulan "April" }
 if {$month == "May"} { set bulan "Mei" }
 if {$month == "June"} { set bulan "Juni" }
 if {$month == "July"} { set bulan "Juli" }
 if {$month == "August"} { set bulan "Agustus" }
 if {$month == "September"} { set bulan "September" }
 if {$month == "October"} { set bulan "Oktober" }
 if {$month == "November"} { set bulan "November" }
 if {$month == "December"} { set bulan "Desember" }
 set tahun [lindex [split $arguments] 5]
 set jam [lindex [split $arguments] 7]
 putquick "PRIVMSG $channel :«!» Sekarang : $hari - $tanggal $bulan $tahun - $jam"
}



bind ctcr - PING pingreply
proc pub:ping {nick uhost hand chan text} {
 pingnick $nick
 return 0
}
proc pingnick {nick} {
 putquick "PRIVMSG $nick :\001PING [expr {abs([clock clicks -milliseconds])}]\001"
}
proc pingreply {nick uhost hand dest key args} {
 set pingnum [lindex $args 0]
 set pingserver [lindex [split $::server :] 0]
 if {[regexp -- {^-?[0-9]+$} $pingnum]} {
  putquick "PRIVMSG $channel :«!» $nick Kamu Lag [expr {abs([expr [expr {abs([clock clicks -milliseconds])} - $pingnum] / 1000.000])}] detik, jika diukur dari $pingserver «!»"
 }
}




proc pub:uptime {nick uhost hand chan arg} {
  putquick "PRIVMSG $chan :[zombieUp]"
}
proc zombieUp {} {
  set ::time(uptime) [expr [clock seconds]-$::uptime]
  set ::time(minggu) [expr $::time(uptime)/604800]
  set ::time(uptime) [expr $::time(uptime)-$::time(minggu)*604800]
  set ::time(hari) [expr $::time(uptime)/86400]
  set ::time(uptime) [expr $::time(uptime)-$::time(hari)*86400]
  set ::time(jam) [expr $::time(uptime)/3600]
  set ::time(uptime) [expr $::time(uptime)-$::time(jam)*3600]
  set ::time(menit) [expr $::time(uptime)/60]
  set ::time(uptime) [expr $::time(uptime)-$::time(menit)*60]
  set ::time(detik) $::time(uptime)
  set ::time(return) "«!» $::time(minggu) minggu $::time(hari) hari $::time(jam) jam $::time(menit) menit $::time(detik) detik «!»"
  return $::time(return)
}




proc pub:whoisnick { nickname hostname handle channel arguments } {
 global whois
 set target [lindex $arguments 1]
 if {$target == ""} {
 putquick "PRIVMSG $channel :Perintah : .whois <nick>"
 return 0
 }
 if {$target == "*"} {
 putquick "KICK $channel $nickname :wedew gak usah badung ah ketik aja 4//timercok 0 0 whois * "
 return 0
 }
 if { ![isop $nickname $channel] } {
  putquick "NOTICE $nickname :.whois hanya untuk @OP aja!"
  return 0
 }
 if {[string length $target] >= "31"} {
 putquick "PRIVMSG $channel :Panjang amat nick nya"; return
 }
 putquick "WHOIS $target $target"
 set ::whoischannel $channel
 bind RAW - 402 whois:nosuch
 bind RAW - 311 whois:info
 bind RAW - 319 whois:channels
 bind RAW - 301 whois:away
 bind RAW - 313 whois:ircop
 bind RAW - 330 whois:auth
 bind RAW - 317 whois:idle
 bind RAW - 275 whois:ssl
 bind RAW - 338 whois:actual
 bind RAW - 312 whois:server
 bind RAW - 716 whois:gmode
 bind RAW - 318 end:of:whois
}

proc whois:putmsg { channel arguments } { putquick "PRIVMSG $channel :$arguments" }

proc whois:info { from keyword arguments } {
set channel $::whoischannel
set ::nickname [lindex [split $arguments] 1]
set ident [lindex [split $arguments] 2]
set host [lindex [split $arguments] 3]
set realname [string range [join [lrange $arguments 5 end]] 1 end]
whois:putmsg $channel "$::nickname is $ident@$host * $realname"
}

proc whois:ircop { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
whois:putmsg $channel "$target is an IRC Operator"
}

proc whois:away { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
set awaymessage [string range [join [lrange $arguments 2 end]] 1 end]
whois:putmsg $channel "$target is away: $awaymessage"
}

proc whois:channels { from keyword arguments } {
set channel $::whoischannel
set channels [string range [join [lrange $arguments 2 end]] 1 end]
set target $::nickname
whois:putmsg $channel "$target on $channels"
}

proc whois:auth { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
set authname [lindex [split $arguments] 2]
whois:putmsg $channel "$target is authed as $authname"
}

proc whois:idle { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
set idletime [lindex [split $arguments] 2]
set signon [lindex [split $arguments] 3]
whois:putmsg $channel "$target has been idle for [duration $idletime]. signon time [ctime $signon]"
}

proc whois:ssl { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
whois:putmsg $channel "$target is connected via Secure Connection (SSL)"
}

proc whois:gmode { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
whois:putmsg $channel "$target is in +g mode (server side ignore)"
}

proc whois:actual { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
set actualhost [lindex [split $arguments] 2]
whois:putmsg $channel "$target actually using host $actualhost"
}

proc whois:server { from keyword arguments } {
set channel $::whoischannel
set target $::nickname
set servers [lindex [split $arguments] 2]
set serverdesc [string range [join [lrange $arguments 3 end]] 1 end]
whois:putmsg $channel "$target using $servers $serverdesc"
}

proc whois:nosuch { from keyword arguments } {
set channel $::whoischannel
whois:putmsg $channel "Ra ono wong'e suw.."
close:whois:bind jancok matane picek
}

proc end:of:whois { from keyword arguments } {
 set channel $::whoischannel
 set target $::nickname
 whois:putmsg $channel "$target End of /WHOIS list."
 close:whois:bind jancok matane picek
}
proc close:whois:bind { from key args } {
 unbind RAW - 402 whois:nosuch
 unbind RAW - 311 whois:info
 unbind RAW - 319 whois:channels
 unbind RAW - 301 whois:away
 unbind RAW - 313 whois:ircop
 unbind RAW - 330 whois:auth
 unbind RAW - 317 whois:idle
 unbind RAW - 275 whois:ssl
 unbind RAW - 338 whois:actual
 unbind RAW - 312 whois:server
 unbind RAW - 716 whois:gmode
 unbind RAW - 318 end:of:whois
}


proc pub:userhost {nick uhost hand chan text} {
 set ::hostchan $chan
 set target [lindex $text 1]
 if {$target == "*"} { putquick "kick $chan $nick :Gak usah Badung ah!!" ; return }
 bind RAW - 311 user:host
 putquick "whois $target"
}
proc user:host {from key args} {
 set chan $::hostchan
 set nick [lindex [split $args] 1]
 set ident [lindex [split $args] 2]
 set host [lindex [split $args] 3]
 putquick "PRIVMSG $chan :«!» $nick «-» \($ident@$host\) «!»"
 unbind RAW - 311 user:host
}


proc pub:cekidle {nick uhost hand chan text} {
 set ::idlechan $chan
 set text [lindex $text 1]
 bind RAW - 317 idle:cek
 putquick "whois $text :$text"
}
proc idle:cek { from key args } {
 set nick [lindex [split $args] 1]
 set chan $::idlechan
 set idletime [lindex [split $args] 2]
 set signon [lindex [split $args] 3]
 putquick "PRIVMSG $chan :$nick \(Idle: [duration $idletime] «-» SignOn: [ctime $signon]\)"
 unbind RAW - 317 idle:cek
}








putlog "+++ Initializing zombie Seen TCL"
set bs(limit) 50000
set bs(nicksize) 30
set bs(no_pub) ""
set bs(quiet_chan) "#ciut"
set bs(no_log) "#"
set bs(log_only) ""
set bs(cmdchar) "."
set bs(flood) 5:5
set bs(ignore) 1
set bs(ignore_time) 1
set bs(smartsearch) 1
set bs(logqueries) 1
set bs(path) ""

proc pub:seen {nick uhost hand chan text} {
 set siapa [lindex $text 1]
 if {$siapa == "*"} { putquick "NOTICE $nick :14ndak usah mainin bot!! " ; return }
 bs_pubreq $nick $uhost $hand $chan $siapa 0
}
proc pub:seennick {nick uhost hand chan text} {
 set siapa [lindex $text 1]
 if {$siapa == "*"} { putquick "NOTICE $nick :14ndak usah mainin bot!!" ; return }
 bs_pubreq $nick $uhost $hand $chan $siapa 1
}
proc pub:seenstats {nick uhost hand chan args} {
 global bs
 if {[matchattr $hand +m]} {
  if {[bs_flood $nick $uhost] || [lsearch -exact $bs(no_pub) [string tolower $chan]] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only)  [string tolower $chan]] == -1)} {return 0}
  if {[lsearch -exact $bs(quiet_chan) [string tolower $chan]] >= 0} {set target "notice $nick"} {set target "privmsg $chan"} ; puthelp "$target :[bs_stats]" ;  return 1
 }
}
proc pub:chanstats {nick uhost hand chan arg} {
 global bs
 if {[matchattr $hand +m]} {
  set chan [string tolower $chan]
  if {[bs_flood $nick $uhost] || [lsearch -exact $bs(no_pub) $chan] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower $chan]] ==  -1)} {return 0}
  if {[lsearch -exact $bs(quiet_chan) $chan] >= 0} {set target "notice $nick"} {set target "privmsg $chan"}
  if {[lindex $arg 1] != ""} {set chan [lindex $arg 1]} ; puthelp "$target :[bs_chanstats $chan]" ; return $bs(logqueries)
 }
}
proc pub:lastspoke {nick uhost hand chan args} {
  global bs botnick bs_botidle
  set chan [string tolower $chan] ; if {[bs_flood $nick $uhost] || [lsearch -exact $bs(no_pub) $chan] >= 0 || ($bs(log_only) != "" && [lsearch -exact  $bs(log_only) $chan] == -1)} {return 0}
  if {[lsearch -exact $bs(quiet_chan) $chan] >= 0} {set target "notice $nick"} {set target "privmsg $chan"}
  set data [lindex [bs_filt [join $args]] 1]
  set ldata [string tolower $data]
  if {[string match *\** $data]} {
    set chanlist [string tolower [chanlist $chan]]
    if {[lsearch -glob $chanlist $ldata] > -1} {set data [lindex [chanlist $chan] [lsearch -glob $chanlist $ldata]]}
  }
  if {[onchan $data $chan]} {
    if {$ldata == [string tolower $botnick]} {puthelp "$target :Hai.. $nick" ; return 1}
    set time [getchanidle $data $chan] ; set bottime [expr ([unixtime] - $bs_botidle($chan))/60]
    if {$time < $bottime} {
      if {$time > 0} {set diftime [bs_when [expr [unixtime] - $time*60 -15]]} {set diftime "kurang lebih semenit"}
      puthelp "$target :$data terakhir berbicara di $chan $diftime yang lalu."
    } {
      set diftime [bs_when $bs_botidle($chan)]
      puthelp "$target :$data tidak berbicara apapun sejak aku join $chan $diftime yang lalu."
    }
  }
  return 1
}

proc bs_filt {data} {
  regsub -all -- \\\\ $data \\\\\\\\ data ; regsub -all -- \\\[ $data \\\\\[ data ; regsub -all -- \\\] $data \\\\\] data
  regsub -all -- \\\} $data \\\\\} data ; regsub -all -- \\\{ $data \\\\\{ data ; regsub -all -- \\\" $data \\\\\" data ; return $data
}
proc bs_flood_init {} {
  global bs bs_flood_array ; if {![string match *:* $bs(flood)]} {putlog "$bs(version): var bs(flood) not set correctly." ; return}
  set bs(flood_num) [lindex [split $bs(flood) :] 0] ; set bs(flood_time) [lindex [split $bs(flood) :] 1] ; set i [expr $bs(flood_num) - 1]
  while {$i >= 0} {set bs_flood_array($i) 0 ; incr i -1 ; }
} ; bs_flood_init
proc bs_flood {nick uhost} {
  global bs bs_flood_array ; if {$bs(flood_num) == 0} {return 0} ; set i [expr $bs(flood_num) - 1]
  while {$i >= 1} {set bs_flood_array($i) $bs_flood_array([expr $i - 1]) ; incr i -1} ; set bs_flood_array(0) [unixtime]
  if {[expr [unixtime] - $bs_flood_array([expr $bs(flood_num) - 1])] <= $bs(flood_time)} {
    putlog "$bs(version): Flood detected from $nick." ; if {$bs(ignore)} {newignore [join [maskhost *!*[string trimleft $uhost ~]]] $bs(version) flood  $bs(ignore_time)} ; return 1
  } {return 0}
}
if {[lsearch -exact [bind time -|- "* * * * *"] bs_timedsave] > -1} {unbind time -|- "* * * * *" bs_timedsave} ; #backup frequency can be lower
proc bs_read {} {
  global bs_list userfile bs
  if {![string match */* $userfile]} {set name [lindex [split $userfile .] 0]} {
    set temp [split $userfile /] ; set temp [lindex $temp [expr [llength $temp]-1]] ; set name [lindex [split $temp .] 0]
  }
  if {![file exists $bs(path)data.seen]} {
    if {![file exists $bs(path)data.seen.bak]} {
      putlog "--- Old seen database not found!" ; putlog "--- If this is the first time you've run the script, don't worry." ; putlog "--- If there *should* be a  database file from past runs of this script... worry." ; return
    } {exec cp $bs(path)data.seen.bak $bs(path)data.seen ; putlog "--- Old seen database not found! Using backup data."}
  } ; set fd [open $bs(path)data.seen r]
  set bsu_ver "" ; set break 0
  while {![eof $fd]} {
    set inp [gets $fd] ; if {[eof $fd]} {break} ; if {[string trim $inp " "] == ""} {continue}
    if {[string index $inp 0] == "#"} {set bsu_version [string trimleft $inp #] ; continue}
    if {![info exists bsu_version] || $bsu_version == "" || $bsu_version < $bs(updater)} {
      putlog "--- Updating database to new version of bseen..."
#bugfix (b) - loading the wrong updater version
      if {[source scripts/bseen_updater1.4.2.tcl] != "ok"} {set temp 1} {set temp 0}
      if {$temp || [bsu_go] || [bsu_finish]} {
        putlog "--- A serious problem was encountered while updating the bseen database."
        if {$temp} {putlog "--- The updater script could not be found."}
        putlog "--- It is *not* safe to run the bot w/ a bseen database that is not matched to this version of bseen."
        putlog "--- If you can't find the problem, the only option is to remove the data.seen and data.seen.bak files.  Then restart the bot."
        putlog "--- Because this is a potential crash point in the bot, the bot will now halt." ; die "critical error in bseen encountered"
      } ; set break 1 ; break
    }
    set nick [lindex $inp 0] ; set bs_list([string tolower $nick]) $inp
  } ; close $fd
  if {$break} {bs_read} {putlog "--- Selesai ngeload [array size bs_list] data."}
}
proc bs_update {} {
  global bs
  putlog "--- A new version of bseen is dynamically being loaded."
  putlog "--- Verifying the integrity of the database across versions..."
  bs_save ; bs_read
}
set bs(updater) 10402 ; set bs(version) bseen1.4.2c
if {[info exists bs_list]} {
#a rehash was done
  if {[info exists bs(oldver)]} {
    if {$bs(oldver) < $bs(updater)} {bs_update} ;# old ver found
  } {bs_update} ;# pre- 1.4.0
}
set bs(oldver) $bs(updater)
if {![info exists bs_list] || [array size bs_list] == 0} {putlog "--- Loading seen database..." ; bs_read}
bind time - "* * * * *" bs_timedsave
proc bs_timedsave {min b c d e} {bs_save}
proc bs_save {} {
  global bs_list userfile bs ; if {[array size bs_list] == 0} {return}
  if {![string match */* $userfile]} {set name [lindex [split $userfile .] 0]} {
    set temp [split $userfile /] ; set temp [lindex $temp [expr [llength $temp]-1]] ; set name [lindex [split $temp .] 0]
  }
  if {[file exists $bs(path)data.seen]} {catch {exec cp -f $bs(path)data.seen $bs(path)data.seen.bak}}
  set fd [open $bs(path)data.seen w] ; set id [array startsearch bs_list]
  puts $fd "#$bs(updater)"
  while {[array anymore bs_list $id]} {set item [array nextelement bs_list $id] ; puts $fd "$bs_list($item)"} ; array donesearch bs_list $id ; close $fd
}
#bugfix -- support new PART in egg1.5.x+
if {[string trimleft [lindex $version 1] 0] >= 1050000} {
  bind part -|- * bs_part 
} {
  if {[lsearch -exact [bind part -|- *] bs_part] > -1} {unbind part -|- * bs_part}
  bind part -|- * bs_part_oldver
}
proc bs_part_oldver {a b c d} {bs_part $a $b $c $d ""}
#bugfix - new bs_part proc
proc bs_part {nick uhost hand chan reason} {bs_add $nick "[list $uhost] [unixtime] part $chan [split $reason]"}
bind join -|- * bs_join
proc bs_join {nick uhost hand chan} {bs_add $nick "[list $uhost] [unixtime] join $chan"}
bind sign -|- * bs_sign
proc bs_sign {nick uhost hand chan reason} {bs_add $nick "[list $uhost] [unixtime] quit $chan [split $reason]"}
bind kick -|- * bs_kick
proc bs_kick {nick uhost hand chan knick reason} {bs_add $knick "[getchanhost $knick $chan] [unixtime] kick $chan [list $nick] [list $reason]"}
bind nick -|- * bs_nick
proc bs_nick {nick uhost hand chan newnick} {set time [unixtime] ; bs_add $nick "[list $uhost] [expr $time -1] nick $chan [list $newnick]" ; bs_add $newnick  "[list $uhost] $time rnck $chan [list $nick]"}
bind splt -|- * bs_splt
proc bs_splt {nick uhost hand chan} {bs_add $nick "[list $uhost] [unixtime] splt $chan"}
bind rejn -|- * bs_rejn
proc bs_rejn {nick uhost hand chan} {bs_add $nick "[list $uhost] [unixtime] rejn $chan"}
bind chon -|- * bs_chon
proc bs_chon {hand idx} {foreach item [dcclist] {if {[lindex $item 3] != "CHAT"} {continue} ; if {[lindex $item 0] == $idx} {bs_add $hand "[lindex $item 2]  [unixtime] chon" ; break}}}
if {[lsearch -exact [bind chof -|- *] bs_chof] > -1} {unbind chof -|- * bs_chof} ; #this bind isn't needed any more
bind chjn -|- * bs_chjn
proc bs_chjn {bot hand channum flag sock from} {bs_add $hand "[string trimleft $from ~] [unixtime] chjn $bot"}
bind chpt -|- * bs_chpt
proc bs_chpt {bot hand args} {set old [split [bs_search ? [string tolower $hand]]] ; if {$old != "0"} {bs_add $hand "[join [string trim [lindex $old 1] ()]]  [unixtime] chpt $bot"}}
if {[string trimleft [lindex $version 1] 0] > 1030000} {bind away -|- * bs_away}
proc bs_away {bot idx msg} {
  global botnet-nick
  if {$bot == ${botnet-nick}} {set hand [idx2hand $idx]} {return}
  set old [split [bs_search ? [string tolower $hand]]]
  if {$old != "0"} {bs_add $hand "[join [string trim [lindex $old 1] ()]] [unixtime] away $bot [bs_filt [join $msg]]"}
}
bind dcc n|n unseen bs_unseen
proc bs_unseen {hand idx args} {
  global bs_list
  set tot 0 ; set chan [string tolower [lindex $args 0]] ; set id [array startsearch bs_list]
  while {[array anymore bs_list $id]} {
    set item [array nextelement bs_list $id]
    if {$chan == [string tolower [lindex $bs_list($item) 4]]} {incr tot ; lappend remlist $item}
  }
  array donesearch bs_list $id ; if {$tot > 0} {foreach item $remlist {unset bs_list($item)}}
  putlog "--- $hand removed $chan from the bseen database.  $tot entries removed."
  putidx $idx "$chan successfully removed.  $tot entries deleted from the bseen database."
}
bind bot -|- bs_botsearch bs_botsearch
proc bs_botsearch {from cmd args} {
  global botnick ; set args [join $args]
  set command [lindex $args 0] ; set target [lindex $args 1] ; set nick [lindex $args 2] ; set search [bs_filt [join [lrange $args 3 e]]]
  if {[string match *\\\** $search]} {
    set output [bs_seenmask bot $nick $search]
    if {$output != "ga' ada yang cocok." && ![string match "I'm not on *" $output]} {putbot $from "bs_botsearch_reply $command  \{$target\} {$nick, $botnick says:  [bs_filt $output]}"}
  } {
    set output [bs_output bot $nick [bs_filt [lindex $search 0]] 0]
    if {$output != 0 && [lrange [split $output] 1 4] != "I don't remember seeing"} {putbot $from "bs_botsearch_reply $command \{$target\} {$nick, $botnick  says:  [bs_filt $output]}"}
  }
}
if {[info exists bs(bot_delay)]} {unset bs(bot_delay)}
bind bot -|- bs_botsearch_reply bs_botsearch_reply
proc bs_botsearch_reply {from cmd args} {
  global bs ; set args [join $args]
  if {[lindex [lindex $args 2] 5] == "not" || [lindex [lindex $args 2] 4] == "not"} {return}
  if {![info exists bs(bot_delay)]} {
    set bs(bot_delay) on ; utimer 10 {if {[info exists bs(bot_delay)]} {unset bs(bot_delay)}}
    if {![lindex $args 0]} {putdcc [lindex $args 1] "[join [lindex $args 2]]"} {puthelp "[lindex $args 1] :[join [lindex $args 2]]"}
  }
}
bind dcc -|- seen bs_dccreq1
bind dcc -|- seennick bs_dccreq2
proc bs_dccreq1 {hand idx args} {bs_dccreq $hand $idx $args 0}
proc bs_dccreq2 {hand idx args} {bs_dccreq $hand $idx $args 1}
proc bs_dccreq {hand idx args no} {
  set args [bs_filt [join $args]] ; global bs
  if {[string match *\\\** [lindex $args 0]]} {
    set output [bs_seenmask dcc $hand $args]
    if {$output == "ga' ada yang cocok."} {putallbots "bs_botsearch 0 $idx $hand $args"}
    if {[string match "I'm not on *" $output]} {putallbots "bs_botsearch 0 $idx $hand $args"}
    putdcc $idx $output ; return $bs(logqueries)
  }
  set search [bs_filt [lindex $args 0]]
  set output [bs_output dcc $hand $search $no]
  if {$output == 0} {return 0}
  if {[lrange [split $output] 1 4] == "Maaf.. Aku gak pernah liat"} {putallbots "bs_botsearch 0 $idx $hand $args"}
  putdcc $idx "$output" ; return $bs(logqueries)
}
bind msg -|- seen bs_msgreq1
bind msg -|- seennick bs_msgreq2
proc bs_msgreq1 {nick uhost hand args} {bs_msgreq $nick $uhost $hand $args 0}
proc bs_msgreq2 {nick uhost hand args} {bs_msgreq $nick $uhost $hand $args 1}
proc bs_msgreq {nick uhost hand args no} {
  if {[bs_flood $nick $uhost]} {return 0} ; global bs
  set args [bs_filt [join $args]]
  if {[string match *\\\** [lindex $args 0]]} {
    set output [bs_seenmask msg $nick $args]
    if {$output == "ga' ada yang cocok."} {putallbots "bs_botsearch 1 \{notice $nick\} $nick $args"}
    if {[string match "I'm not on *" $output]} {putallbots "bs_botsearch 1 \{notice $nick\} $nick $args"}
    puthelp "notice $nick :$output" ; return $bs(logqueries)
  }
  set search [bs_filt [lindex $args 0]]
  set output [bs_output $search $nick $search $no]
  if {$output == 0} {return 0}
  if {[lrange [split $output] 1 4] == "Maaf.. Aku gak pernah liat"} {putallbots "bs_botsearch 1 \{notice $nick\} $nick $args"}
  puthelp "notice $nick :$output" ; return $bs(logqueries)
}


proc bs_pubreq {nick uhost hand chan args no} {
  if {[bs_flood $nick $uhost]} {return 0}
  global botnick bs ; set i 0
  if {[lsearch -exact $bs(no_pub) [string tolower $chan]] >= 0} {return 0}
  if {$bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower $chan]] == -1} {return 0}
  set args [bs_filt [join $args]]
  if {[lsearch -exact $bs(quiet_chan) [string tolower $chan]] >= 0} {set target "notice $nick"} {set target "privmsg $chan"}
  if {[string match *\\\** [lindex $args 0]]} {
    set output [bs_seenmask $chan $hand $args]
    if {$output == "ga' ada yang cocok."} {putallbots "bs_botsearch 1 \{$target\} $nick $args"}
    if {[string match "I'm not on *" $output]} {putallbots "bs_botsearch 1 \{$target\} $nick $args"}
    puthelp "$target :$output" ; return $bs(logqueries)
  }
  set data [bs_filt [string trimright [lindex $args 0] ?!.,]]
  if {[string tolower $nick] == [string tolower $data] } {puthelp "$target :$nick, cari cermin dulu gi.." ; return $bs(logqueries)}
  if {[string tolower $data] == [string tolower $botnick] } {puthelp "$target :$nick, aku disini. kangen yaa?" ; return $bs(logqueries)}
  if {[onchan $data $chan]} {puthelp "$target :$nick, $data ada disini tuh." ; return  $bs(logqueries)}
  set output [bs_output $chan $nick $data $no] ; if {$output == 0} {return 0}
  if {[lrange [split $output] 1 4] == "Maaf.. Aku gak pernah liat"} {putallbots "bs_botsearch 1 \{$target\} $nick $args"}
  puthelp "$target :$output" ; return $bs(logqueries)
}
proc bs_output {chan nick data no} {
  global botnick bs version bs_list
  set data [string tolower [string trimright [lindex $data 0] ?!.,]]
  if {$data == ""} {return 0}
  if {[string tolower $nick] == $data} {return [concat $nick, lupa ingatan ya?]}
  if {$data == [string tolower $botnick]} {return [concat $nick, aku disini, siap melayanimu.]}
  if {[string length $data] > $bs(nicksize)} {return 0}
  if {$bs(smartsearch) != 1} {set no 1}
  if {$no == 0} {
    set matches "" ; set hand "" ; set addy ""
    if {[lsearch -exact [array names bs_list] $data] != "-1"} {
      set addy [lindex $bs_list([string tolower $data]) 1] ; set hand [finduser $addy]
      foreach item [bs_seenmask dcc ? [maskhost $addy]] {if {[lsearch -exact $matches $item] == -1} {set matches "$matches $item"}}
    }
    if {[validuser $data]} {set hand $data}
    if {$hand != "*" && $hand != ""} {
      if {[string trimleft [lindex $version 1] 0]>1030000} {set hosts [getuser $hand hosts]} {set hosts [gethosts $hand]}
      foreach addr $hosts {
        foreach item [string tolower [bs_seenmask dcc ? $addr]] {
          if {[lsearch -exact [string tolower $matches] [string tolower $item]] == -1} {set matches [concat $matches $item]}
        }
      }
    }
    if {$matches != ""} {
      set matches [string trimleft $matches " "]
      set len [llength $matches]
      if {$len == 1} {return [bs_search $chan [lindex $matches 0]]}
      if {$len > 999} {return [concat Ada $len data yang cocok di database, agak detil dikit napa seh.]}
      set matches [bs_sort $matches]
      set key [lindex $matches 0]
      if {[string tolower $key] == [string tolower $data]} {return [bs_search $chan $key]}
      if {$len <= 5} {
        set output [ concat Ada $len orang yang cocok nih (urut): [join $matches].]
        set output [concat $output  [bs_search $chan $key]] ; return $output
      } {
        set output [ concat Ada $len orang yang cocok, 5 nick terakhir (urut): [join [lrange $matches 0 4]].]
        set output [concat $output  [bs_search $chan $key]] ; return $output
      }
    }
  }
  set temp [bs_search $chan $data]
  if {$temp != 0} { return $temp } {
    #$data not found in $bs_list, so search userfile
    if {![validuser [bs_filt $data]] || [string trimleft [lindex $version 1] 0]<1030000} {
      return "Maaf $nick.. Aku gak pernah liat $data."
    } {
      set seen [getuser $data laston]
      if {[getuser $data laston] == ""} {return "Maaf $nick.. Aku gak pernah liat $data."}
      if {($chan != [lindex $seen 1] || $chan == "bot" || $chan == "msg" || $chan == "dcc") && [validchan [lindex $seen 1]] && [lindex [channel info [lindex  $seen 1]] 23] == "+secret"} {
        set chan "-secret-"
      } {
        set chan [lindex $seen 1]
      }
      return [concat $nick, $data terakhir aku liat dia ada di $chan [bs_when [lindex $seen 0]] yang lalu.]
    }
  }
}
proc bs_search {chan n} {
  global bs_list ; if {![info exists bs_list]} {return 0}
  if {[lsearch -exact [array names bs_list] [string tolower $n]] != "-1"} {
#bugfix:  let's see if the split added below fixes the eggdrop1.4.2 truncation bug
    set data [split $bs_list([string tolower $n])]
#bugfix: added a join on the $n  (c)
    set n [join [lindex $data 0]] ; set addy [lindex $data 1] ; set time [lindex $data 2] ; set marker 0
    if {([string tolower $chan] != [string tolower [lindex $data 4]] || $chan == "dcc" || $chan == "msg" || $chan == "bot") && [validchan [lindex $data 4]] &&  [lindex [channel info [lindex $data 4]] 23] == "+secret"} {
      set chan "-secret-"
    } {
      set chan [lindex $data 4]
    }
    switch -- [lindex $data 3] {
    part {
        set reason [lrange $data 5 e]
        if {$reason == ""} {set reason "."} {set reason " Pesan : \"$reason\"."}
        set output [concat $n ($addy) terakhir aku liat dia part dari $chan [bs_when $time] yang lalu $reason]
      }
    quit { set output [concat $n ($addy) terakhir aku liat dia kuit IRC dari $chan [bs_when $time] yang lalu. Pesan : ([join [lrange  $data 5 e]]).] }
    kick { set output [concat $n ($addy) terakhir aku liat dia di kick dari $chan oleh [lindex $data 5] [bs_when $time] yang lalu  dengan pesan ([join [lrange $data 6 e]]).] }
    rnck {
      set output [concat $n ($addy) terakhir aku liat dia ganti nick dari [lindex $data 5] di [lindex $data 4] [bs_when $time] yang lalu.]
      if {[validchan [lindex $data 4]]} {
        if {[onchan $n [lindex $data 4]]} {
          set output [concat $output $n masih ada di [lindex $data 4] sekarang.]
        } {
          set output [concat $output Sekarang aku gak liat $n tuh.]
        }
      }
    }
    nick {
      set output [concat $n ($addy) terakhir aku liat dia ganti nick ke [lindex $data 5] di [lindex $data 4] [bs_when $time] yang lalu.]
    }
    splt { set output [concat $n ($addy) terakhir aku liat dia keluar $chan karena split server [bs_when $time] yang lalu.] }
    rejn {
      set output [concat $n ($addy) terakhir aku liat dia masuk $chan sesudah terkena split server [bs_when $time] yang lalu.]
      if {[validchan $chan]} {if {[onchan $n $chan]} {set output [concat $output  $n masih ada di $chan.]} {set output [concat $output Aku gak liat $n di $chan sekarang tuh.]}}
    }
    join {
      set output [concat $n ($addy) terakhir aku liat dia masuk $chan [bs_when $time] yang lalu.]
      if {[validchan $chan]} {if {[onchan $n $chan]} {set output [concat $output  $n masih ada di $chan.]} {set output [concat $output Aku gak liat $n di $chan sekarang tuh.]}}
    }
    away {
      set reason [lrange $data 5 e]
        if {$reason == ""} {
        set output [concat $n ($addy) was last seen returning to the partyline on $chan [bs_when $time] ago.]
      } {
        set output [concat $n ($addy) terakhir aku liat dia away ($reason) di $chan [bs_when $time] yang lalu.]
      }
    }
    chon {
      set output [concat $n ($addy) was last seen joining the partyline [bs_when $time] ago.] ; set lnick [string tolower $n]
      foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output  $n is on the partyline right now.] ; set marker  1 ; break}}
      if {$marker == 0} {set output [concat $output  I don't see $n on the partyline now, though.]}
    }
    chof {
      set output [concat $n ($addy) was last seen leaving the partyline [bs_when $time] ago.] ; set lnick [string tolower $n]
      foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output  $n is on the partyline in [lindex $item 1] still.]  ; break}}
    }
    chjn {
      set output [concat $n ($addy) was last seen joining the partyline on $chan [bs_when $time] ago.] ; set lnick [string tolower $n]
      foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output  $n is on the partyline right now.] ; set marker  1 ; break}}
      if {$marker == 0} {set output [concat $output  I don't see $n on the partyline now, though.]}
    }
    chpt {
      set output [concat $n ($addy) was last seen leaving the partyline from $chan [bs_when $time] ago.] ; set lnick [string tolower $n]
      foreach item [whom *] {if {$lnick == [string tolower [lindex $item 0]]} {set output [concat $output  $n is on the partyline in [lindex $item 1] still.]  ; break}}
    }
    default {set output "error"}
    } ; return $output
  } {return 0}
}
proc bs_when {lasttime} {
  #This is equiv to mIRC's $duration() function
  set years 0 ; set days 0 ; set hours 0 ; set mins 0 ; set time [expr [unixtime] - $lasttime]
  if {$time < 60} {return "hanya $time detik"}
  if {$time >= 31536000} {set years [expr int([expr $time/31536000])] ; set time [expr $time - [expr 31536000*$years]]}
  if {$time >= 86400} {set days [expr int([expr $time/86400])] ; set time [expr $time - [expr 86400*$days]]}
  if {$time >= 3600} {set hours [expr int([expr $time/3600])] ; set time [expr $time - [expr 3600*$hours]]}
  if {$time >= 60} {set mins [expr int([expr $time/60])]}
  if {$years == 0} {set output ""} elseif {$years == 1} {set output "1 year,"} {set output "$years years,"}
  if {$days == 1} {lappend output "1 hari,"} elseif {$days > 1} {lappend output "$days hari,"}
  if {$hours == 1} {lappend output "1 jam,"} elseif {$hours > 1} {lappend output "$hours jam,"}
  if {$mins == 1} {lappend output "1 menit"} elseif {$mins > 1} {lappend output "$mins menit"}
  return [string trimright [join $output] ", "]
}
proc bs_add {nick data} {
  global bs_list bs
  if {[lsearch -exact $bs(no_log) [string tolower [lindex $data 3]]] >= 0 || ($bs(log_only) != "" && [lsearch -exact $bs(log_only) [string tolower [lindex $data  3]]] == -1)} {return}
  set bs_list([string tolower $nick]) "[bs_filt $nick] $data"
}
bind time -  "* * * * *" bs_trim
proc bs_lsortcmd {a b} {global bs_list ; set a [lindex $bs_list([string tolower $a]) 2] ; set b [lindex $bs_list([string tolower $b]) 2] ; if {$a > $b} {return 1}  elseif {$a < $b} {return -1} {return 0}}
proc bs_trim {min h d m y} {
  global bs bs_list ; if {![info exists bs_list] || ![array exists bs_list]} {return} ; set list [array names bs_list] ; set range [expr [llength $list] - $bs(limit) - 1] ; if  {$range < 0} {return}
  set list [lsort -increasing -command bs_lsortcmd $list] ; foreach item [lrange $list 0 $range] {unset bs_list($item)}
}
proc bs_seenmask {ch nick args} {
  global bs_list bs ; set matches "" ; set temp "" ; set i 0 ; set args [join $args] ; set chan [lindex $args 1]
  if {$chan != "" && [string trimleft $chan #] != $chan} {
    if {![validchan $chan]} {return "Aku gak pernah join $chan."} {set chan [string tolower $chan]}
  } { set $chan "" }
  if {![info exists bs_list]} {return "ga' ada yang cocok."} ; set data [bs_filt [string tolower [lindex $args 0]]]

#bugfix: unnecessarily complex masks essentially freeze the bot
  set maskfix 1
  while $maskfix {
    set mark 1
    if [regsub -all -- \\?\\? $data ? data] {set mark 0}
    if [regsub -all -- \\*\\* $data * data] {set mark 0}
    if [regsub -all -- \\*\\? $data * data] {set mark 0}
    if [regsub -all -- \\?\\* $data * data] {set mark 0}
    if $mark {break}
  }

  set id [array startsearch bs_list]
  while {[array anymore bs_list $id]} {
    set item [array nextelement bs_list $id] ; if {$item == ""} {continue} ; set i 0 ; set temp "" ; set match [lindex $bs_list($item) 0] ; set addy [lindex  $bs_list($item) 1]
    if {[string match $data $item![string tolower $addy]]} {
      set match [bs_filt $match] ; if {$chan != ""} {
        if {[string match $chan [string tolower [lindex $bs_list($item) 4]]]} {set matches [concat $matches $match]}
      } {set matches [concat $matches $match]}
    }
  }
  array donesearch bs_list $id
  set matches [string trim $matches " "]
  if {$nick == "?"} {return [bs_filt $matches]}
  set len [llength $matches]
  if {$len == 0} {return "ga' ada yang cocok."}
  if {$len == 1} {return [bs_output $ch $nick $matches 1]}
  if {$len > 999} {return "Ada $len data yang cocok di database, agak detil dikit napa seh."}
  set matches [bs_sort $matches]
  if {$len <= 5} {
    set output [concat Ada $lenorang yang cocok (urut): [join $matches].]
  } {
    set output "Ada $len orang yang cocok, 5 nick terakhir (urut): [join [lrange $matches 0 4]]."
  }
  return [concat $output [bs_output $ch $nick [lindex [split $matches] 0] 1]]
}
proc bs_sort {data} {global bs_list ; set data [bs_filt [join [lsort -decreasing -command bs_lsortcmd $data]]] ; return $data}
bind dcc m|m seenstats bs_dccstats
proc bs_dccstats {hand idx args} {putdcc $idx "[bs_stats]"; return 1}

bind msg m|m seenstats bs_msgstats
proc bs_msgstats {nick uhost hand args} {global bs ; if {[bs_flood $nick $uhost]} {return 0} ; puthelp "notice $nick :[bs_stats]" ; return $bs(logqueries)}
proc bs_stats {} {
  global bs_list bs ; set id [array startsearch bs_list] ; set bs_record [unixtime] ; set totalm 0 ; set temp ""
  while {[array anymore bs_list $id]} {
    set item [array nextelement bs_list $id]
    set tok [lindex $bs_list($item) 2] ; if {$tok == ""} {putlog "Damaged seen record: $item" ; continue}
    if {[lindex $bs_list($item) 2] < $bs_record} {set bs_record [lindex $bs_list($item) 2] ; set name $item}
    set addy [string tolower [maskhost [lindex $bs_list($item) 1]]] ; if {[lsearch -exact $temp $addy] == -1} {incr totalm ; lappend temp $addy}
  }
  array donesearch bs_list $id
  return "SeenStats : [array size bs_list]/$bs(limit) nick - $totalm unique host. Oldest : [lindex  $bs_list($name) 0] terlihat [bs_when $bs_record] yang lalu."
}
bind dcc m|m chanstats bs_dccchanstats
proc bs_dccchanstats {hand idx args} {
  if {$args == "{}"} {set args [console $idx]} 
  if {[lindex $args 0] == "*"} {putdcc $idx "$hand, chanstats requires a channel arg, or a valid console channel." ; return 1}
  putdcc $idx "[bs_chanstats [lindex $args 0]]"
  return 1
}

bind msg m|m chanstats bs_msgchanstats
proc bs_msgchanstats {nick uhost hand args} {global bs ; if {[bs_flood $nick $uhost]} {return 0} ; puthelp "notice $nick :[bs_chanstats [lindex $args 0]]" ;  return $bs(logqueries)}
proc bs_chanstats {chan} {
  global bs_list ; set chan [string tolower $chan] ; if {![validchan $chan]} {return "Aku gak di $chan."}
  set id [array startsearch bs_list] ; set bs_record [unixtime] ; set totalc 0 ; set totalm 0 ; set temp ""
  while {[array anymore bs_list $id]} {
    set item [array nextelement bs_list $id] ; set time [lindex $bs_list($item) 2] ; if {$time == ""} {continue}
    if {$chan == [string tolower [lindex $bs_list($item) 4]]} {
      if {$time < $bs_record} {set bs_record $time} ; incr totalc
      set addy [string tolower [maskhost [lindex $bs_list($item) 1]]]
      if {[lsearch -exact $temp $addy] == -1} {incr totalm ; lappend temp $addy}
    }
  }
  array donesearch bs_list $id ; set total [array size bs_list]
  return "$chan : [expr 100*$totalc/$total]% ($totalc/$total) - $totalm unique host telah tersimpan selama [bs_when $bs_record]."
}
foreach chan [string tolower [channels]] {if {![info exists bs_botidle($chan)]} {set bs_botidle($chan) [unixtime]}}
bind join -|- * bs_join_botidle
proc bs_join_botidle {nick uhost hand chan} {
  global bs_botidle botnick
  if {$nick == $botnick} {
   set bs_botidle([string tolower $chan]) [unixtime]
  }
}

bind msgm -|- "help seen" bs_help_msg_seen
bind msgm -|- "help chanstats" bs_help_msg_chanstats
bind msgm -|- "help seenstats" bs_help_msg_seenstats
proc bs_help_msg_seen {nick uhost hand args} {
  global bs ; if {[bs_flood $nick $uhost]} {return 0}
  puthelp "notice $nick :###  seen <query> \[chan\]          $bs(version)"
  puthelp "notice $nick :   Queries can be in the following formats:"
  puthelp "notice $nick :     'regular':  seen lamer; seen lamest "
  puthelp "notice $nick :     'masked':   seen *l?mer*; seen *.lame.com; seen *.edu #mychan" ; return 0
}
proc bs_help_msg_chanstats {nick uhost hand args} {
  global bs ; if {[bs_flood $nick $uhost]} {return 0}
  puthelp "notice $nick :###  chanstats <chan>          $bs(version)"
  puthelp "notice $nick :   Returns the usage statistics of #chan in the seen database." ; return 0
}
proc bs_help_msg_seenstats {nick uhost hand args} {
  global bs ; if {[bs_flood $nick $uhost]} {return 0}
  puthelp "notice $nick :###  seenstats          $bs(version)"
  puthelp "notice $nick :   Returns the status of the bseen database." ; return 0
}
bind dcc -|- seenversion bs_version
proc bs_version {hand idx args} {global bs ; putidx $idx "###  Bass's Seen script, $bs(version)."}
bind dcc -|- help bs_help_dcc
proc bs_help_dcc {hand idx args} {
  global bs
  switch -- $args {
    seen {
      putidx $idx "###  seen <query> \[chan\]          $bs(version)" ; putidx $idx "   Queries can be in the following formats:"
      putidx $idx "     'regular':  seen lamer; seen lamest " ; putidx $idx "     'masked':   seen *l?mer*; seen *.lame.com; seen *.edu #mychan"
    }
    seennick {putidx $idx "###  seen <nick>          $bs(version)"}
    chanstats {putidx $idx "###  chanstats <chan>" ; putidx $idx "   Returns the usage statistics of #chan in the seen database."}
    seenstats {putidx $idx "###  seenstats          $bs(version)" ; putidx $idx "   Returns the status of the bseen database."}
    unseen {if {[matchattr $hand n]} {putidx $idx "###  unseen <chan>          $bs(version)" ; putidx $idx "   Deletes all <chan> entries from the bseen  database."}}
    default {*dcc:help $hand $idx [join $args] ; return 0}
  } ; return 1
}
putlog "eggoez part(2) Loaded!!"

No comments:

Post a Comment