IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   TCL Scriptler (https://www.ircforumlari.net/tcl-scriptler/)
-   -   stackoverflow Tcl (https://www.ircforumlari.net/tcl-scriptler/616295-stackoverflow-tcl.html)

saywhat 23 Eylül 2014 20:31

stackoverflow Tcl
 
programlama , scripting ile ilgilenen kişilerin işine yarayabilecek türden "ingilizce" bir scripttir. kendime özel, diye yapıp aylardır kullandığım scriptlerden biridir.

stackoverflow sitesinden sorgulama yapar.

[Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]

Kod:

# tcllib http paketi gerektirir.
package require http

# .chanset #kanal +over , komutu ile aktif edilir.
setudef flag over

# komuta erişimi olacak kullanıcı flagları
set overflag "-|-"

# komut başına gelecek sembol.
set oversemb "."

# kaç arama sonucu vermeli:
set oversay "3"

# kanal ve özelde kullanılacak komutlar.
set overkmt "stack over flow sof"

# özelde de işlesin mi : 1 = evet 0 = hayır.
set overmsg 1

# komutlar arası beklenmesi gereken süre (saniye)
set overkontr "10"

# ayarlar sonu...
foreach bind [split $overkmt " "] {
      bind pub $overflag $oversemb$bind over_flow_pub
  if {$overmsg >= 1} {
      bind msg $overflag $oversemb$bind over_flow_msg
      }
  }

proc over_flow_pub {nick uhost hand chan text} {
  if {![channel get $chan over]} { return 0 }
      over_flow_main $nick $uhost $hand $chan $text
    }

proc over_flow_msg {nick uhost hand text} {
      over_flow_main $nick $uhost $hand $nick $text
    }
 
proc over_flow_main {nick uhost hand chan text} {
    set q [join [lrange [split [string tolower $text]] 0 end]]
    set host [lindex [split $uhost @] 1]
   
  if {[throttled $host,$chan $::overkontr]} {
      puthelp "notice $nick :\002Flood detected !!!\002 - \
      \00314you have to wait, [expr {[clock seconds] - $::throttled($host,$chan)}] seconds ...\003"
      return 0
    }
   
  if {[llength $q] eq "0"} {
      puthelp "notice $nick :\00304Usage:\003 \002$::lastbind <your search>\002"
      return 0
    }
   
   
    set overurl "http://stackoverflow.com/search?"
    set query [http::formatQuery q $q]
    putlog "$overurl$query"
     
  ::http::config -useragent "Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)"
    set url [::http::geturl $overurl[join $query "+"] -timeout [expr {6*1000}]]
    set data [split [::http::data $url] "\n"]
  ::http::cleanup $url
 
#        putserv "privmsg $chan :\026\"$q\"\026 searching...please wait..."

      regsub -all -- "\n" $data "" data
      regsub -all -- "\r" $data "" data
      regsub -all -- "\b" $data "" data
      regsub -all -- "\t" $data "" data
      regsub -all -- "\v" $data "" data
      regsub -all -- "\f" $data "" data
       
        regexp {results-header">(.*?)</span>.+page-description">(.*?)</p>} $data "" arat sonuc
    if {[info exists sonuc] eq "1"} {
   
        regsub -all -- "<.*?>" $sonuc "" sonuc
        regsub -all -- \} $sonuc "" sonuc
        regsub -all -- \{ $sonuc "" sonuc
        regsub -all -- "<.*?>" $arat "" arat
        regsub -all -- \} $arat "" arat
        regsub -all -- \{ $arat "" arat
       
        puthelp "privmsg $chan :\00303[string trim $arat]\003 \00314[string trim $sonuc]\003 \026$q\026"
        return
      }
     
      regexp {results-header">(.*?)</span>} $data "" result
    if {[info exists result] eq "1"} { 
     
      regsub -all -- "<.*?>" $result "" result
      regsub -all -- \} $result "" result
      regsub -all -- \{ $result "" result
     
          puthelp "privmsg $chan :\00303[string trim $result] found :\003"   
      }
     
        set i 0
        set ans "";set vote ""; set page ""; set int "" ; set yazar ""
  while {[regexp -line {votes answered">(.*?)</div>.+<a href="(.*?)" title=".*?">(.*?)</a>.+excerpt">(.*?)</div>.+started fr">(.*?)</a>} $data g vote page ans int yazar]} {
        regsub -line {votes answered">(.*?)</div>.+<a href="(.*?)" title=".*?">(.*?)</a>.+excerpt">(.*?)</div>.+started fr">(.*?)</a>} $data "" data
       
        set cikti "\00312$ans\003 \00304$vote\003 \00302$yazar\003"
       
        regsub -all -- "<.*?>" $cikti "" cikti
        regsub -all -- "<.*?>" $int "" int
        regsub -all -- \} $cikti "" cikti
        regsub -all -- \{ $cikti "" cikti
       
       
    if {[info exists page] && $page ne ""} {
        lappend cikti \037http://stackoverflow.com$page\037
        }
       
        set int [string map {\\ ""} $int]
        set cikti [string map {\\ ""} $cikti]
 
 
    if {$i == $::oversay} break
        putserv "privmsg $chan :[string trim [entityToChar $cikti]]"
        putserv "privmsg $chan :\00314[string trim [string map -nocase {\} "" \{ ""} [entityToChar $int]]]\003"
            incr i
        }
  return 0
}

set authr "\00300,04 \u262A \003 \002\026\u006E\u0072\u0074 \u0028\u0053\u0061\u0079\u0057\u0068\u0061\u0074\u0029\002"


# http://is.gd/SVU9r1
# credits to user for this proc

proc throttled {id time} {
    global throttled
    if {[info exists throttled($id)]} {
      return 1
    } {
      set throttled($id) [clock seconds]
      utimer $time [list unset throttled($id)]
      return 0
    }
 }

# i have to say thank you, to speechles and perplexa ..
# also creators of htmlparse for this useful proc.
 
proc entityToChar {text {char utf-8}} {
    if {![string match *&* $text]} {return $text}
   
    set escapes {
        &nbsp; \xa0 &iexcl; \xa1 &cent; \xa2 &pound; \xa3 &curren; \xa4
        &yen; \xa5 &brvbar; \xa6 &sect; \xa7 &uml; \xa8 &copy; \xa9
        &ordf; \xaa &laquo; \xab &not; \xac * \xad &reg; \xae
        &macr; \xaf &deg; \xb0 &plusmn; \xb1 ² \xb2 ³ \xb3
        &acute; \xb4 &micro; \xb5 &para; \xb6 &middot; \xb7 &cedil; \xb8
        ¹ \xb9 &ordm; \xba &raquo; \xbb ¼ \xbc ½ \xbd
        ¾ \xbe &iquest; \xbf &Agrave; \xc0 &Aacute; \xc1 &Acirc; \xc2
        &Atilde; \xc3 &Auml; \xc4 &Aring; \xc5 &AElig; \xc6 &Ccedil; \xc7
        &Egrave; \xc8 &Eacute; \xc9 &Ecirc; \xca &Euml; \xcb &Igrave; \xcc
        &Iacute; \xcd &Icirc; \xce &Iuml; \xcf &ETH; \xd0 &Ntilde; \xd1
        &Ograve; \xd2 &Oacute; \xd3 &Ocirc; \xd4 &Otilde; \xd5 &Ouml; \xd6
        &times; \xd7 &Oslash; \xd8 &Ugrave; \xd9 &Uacute; \xda &Ucirc; \xdb
        &Uuml; \xdc &Yacute; \xdd &THORN; \xde &szlig; \xdf &agrave; \xe0
        &aacute; \xe1 &acirc; \xe2 &atilde; \xe3 &auml; \xe4 &aring; \xe5
        &aelig; \xe6 &ccedil; \xe7 &egrave; \xe8 &eacute; \xe9 &ecirc; \xea
        &euml; \xeb &igrave; \xec &iacute; \xed &icirc; \xee &iuml; \xef
        &eth; \xf0 &ntilde; \xf1 &ograve; \xf2 &oacute; \xf3 &ocirc; \xf4
        &otilde; \xf5 &ouml; \xf6 &divide; \xf7 &oslash; \xf8 &ugrave; \xf9
        &uacute; \xfa &ucirc; \xfb &uuml; \xfc &yacute; \xfd &thorn; \xfe
        &yuml; \xff &fnof; \u192 &Alpha; \u391 &Beta; \u392 &Gamma; \u393 &Delta; \u394
        &Epsilon; \u395 &Zeta; \u396 &Eta; \u397 &Theta; \u398 &Iota; \u399
        &Kappa; \u39A &Lambda; \u39B &Mu; \u39C &Nu; \u39D &Xi; \u39E
        &Omicron; \u39F &Pi; \u3A0 &Rho; \u3A1 &Sigma; \u3A3 &Tau; \u3A4
        &Upsilon; \u3A5 &Phi; \u3A6 &Chi; \u3A7 &Psi; \u3A8 &Omega; \u3A9
        &alpha; \u3B1 &beta; \u3B2 &gamma; \u3B3 &delta; \u3B4 &epsilon; \u3B5
        &zeta; \u3B6 &eta; \u3B7 &theta; \u3B8 &iota; \u3B9 &kappa; \u3BA
        &lambda; \u3BB &mu; \u3BC &nu; \u3BD &xi; \u3BE &omicron; \u3BF
        &pi; \u3C0 &rho; \u3C1 &sigmaf; \u3C2 &sigma; \u3C3 &tau; \u3C4
        &upsilon; \u3C5 &phi; \u3C6 &chi; \u3C7 &psi; \u3C8 &omega; \u3C9
        &thetasym; \u3D1 &upsih; \u3D2 &piv; \u3D6 &bull; \u2022
        &hellip; \u2026 &prime; \u2032 &Prime; \u2033 &oline; \u203E
        &frasl; \u2044 &weierp; \u2118 &image; \u2111 &real; \u211C
        &trade; \u2122 &alefsym; \u2135 &larr; \u2190 &uarr; \u2191
        &rarr; \u2192 &darr; \u2193 &harr; \u2194 &crarr; \u21B5
        &lArr; \u21D0 &uArr; \u21D1 &rArr; \u21D2 &dArr; \u21D3 &hArr; \u21D4
        &forall; \u2200 &part; \u2202 &exist; \u2203 &empty; \u2205
        &nabla; \u2207 &isin; \u2208 &notin; \u2209 &ni; \u220B &prod; \u220F
        &sum; \u2211 &minus; \u2212 &lowast; \u2217 &radic; \u221A
        &prop; \u221D &infin; \u221E &ang; \u2220 &and; \u2227 &or; \u2228
        &cap; \u2229 &cup; \u222A &int; \u222B &there4; \u2234 &sim; \u223C
        &cong; \u2245 &asymp; \u2248 &ne; \u2260 &equiv; \u2261 &le; \u2264
        &ge; \u2265 &sub; \u2282 &sup; \u2283 &nsub; \u2284 &sube; \u2286
        &supe; \u2287 &oplus; \u2295 &otimes; \u2297 &perp; \u22A5
        &sdot; \u22C5 &lceil; \u2308 &rceil; \u2309 &lfloor; \u230A
        &rfloor; \u230B &lang; \u2329 &rang; \u232A &loz; \u25CA
        &spades; \u2660 &clubs; \u2663 &hearts; \u2665 &diams; \u2666
        &quot; \x22 &amp; \x26 &lt; \x3C &gt; \x3E O&Elig; \u152 &oelig; \u153
        &Scaron; \u160 &scaron; \u161 &Yuml; \u178 &circ; \u2C6
        &tilde; \u2DC &ensp; \u2002 &emsp; \u2003 &thinsp; \u2009
        &zwnj; \u200C &zwj; \u200D &lrm; \u200E &rlm; \u200F &ndash; \u2013
        &mdash; \u2014 &lsquo; \u2018 &rsquo; \u2019 &sbquo; \u201A
        &ldquo; \u201C &rdquo; \u201D &bdquo; \u201E &dagger; \u2020
        &Dagger; \u2021 &permil; \u2030 &lsaquo; \u2039 &rsaquo; \u203A
        &euro; \u20AC &apos; \u0027 &lrm; ""
    };
   
    set text [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] [string map $escapes $text]]
    regsub -all -- {&#([[:digit:]]{1,5});} $text {[format %c [string trimleft "\1" "0"]]} text
    regsub -all -- {&#x([[:xdigit:]]{1,4});} $text {[format %c [scan "\1" %x]]} text
    return [subst "$text"]
  }

  putlog "\00304Tcl Surumu\003 :\00311 $tcl_patchLevel \003- \00304Tcl Dizin\003 :\00311 $tcl_library \003- \00304Eggdrop Surumu\003 :\00311 [lindex $version 0] \003 $authr"
  putlog "\00304Http Paket Surumu\003 :\00311 [package present http] \003- \00304Sistem Encoding\003 :\00311 [encoding system] \003"
  putlog "\00304Host\003 :\00311 [info hostname] \003- \00304OS\003 :\00311 $::tcl_platform(os) $::tcl_platform(osVersion)/$::tcl_platform(machine) \003"
  putlog "\00304PID Numarasi\003 :\00311 [pid] \003- \00304Sunucuya Bagli Oldugu Sure\003 :\00311 [duration [expr {[clock seconds] - ${server-online}}]] \003"
  putlog "\00304Bot Uptime\003 :\00311 [duration [expr {[clock seconds] - $::uptime}]] \003- \00304Tarih\003 :\00311 [ctime [unixtime]] $::timezone \003"
  putlog "\00304Irc Gorunumu\003 :\00311 $::botname $::realname \003- \00304Bagli Oldugu Sunucu\003 :\00311 $::serveraddress \003- \00304.Conf Dosyasi\003 :\00311 $::config \003"



Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 07:02.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2025 IRCForumlari.Net Sparhawk