# configure the channels where the service will be availableset netcraft(chans) "*"# Google script for the eggdropset google(triggers) "!google"set google(flags) "-|-"set google(nopub) ""set google(antiflood) 5set google(method) 1set google(results) 3set google(perline) 1set google(version) 0.4
if {[catch { package require http } err]} {putlog "Cannot load [file tail [info script]]: Problem loading the http package: $err"return 1}
if {[info tclversion] < 8.1} {putlog "Cannot load [file tail [info script]]: You need at least Tcl version 8.1 and you have Tcl version [info tclversion]."return 1}
foreach trigger [split $google(triggers)] {bind pub $google(flags) $trigger google:pub}catch { unset trigger }
proc google:output {chan nick output} {global google
switch $google(method) {0 { putquick "NOTICE $nick :$output" }1 { putquick "NOTICE $nick :$output" }2 { putquick "NOTICE $nick :$output" }3 { putquick "NOTICE $nick :$output" }default { putquick "NOTICE $nick :$output" }}}
proc google:pub {nick uhost hand chan text} {global lastbind google
if {[lsearch -exact $google(nopub) [string tolower $chan]] >= 0} { return 0 }
if {[string length [string trim [lindex $text 0]]] == 0} {putquick "NOTICE $nick :Usage: $lastbind <keywords>"return 0}
if {[info exists google(floodprot)]} {set diff [expr [clock seconds] - $google(floodprot)]if {$diff < $google(antiflood)} {putquick "NOTICE $nick :Trigger has just been used! Please wait [expr $google(antiflood) - $diff] seconds..."return 0}catch { unset diff }}set google(floodprot) [clock seconds]
regsub -all { } [join $text] {+} searchset google(url) "http://www.google.com/search?hl=en&ie=ISO-8859-1&q=$search"set google(page) [http::config -useragent "Mozilla"]if {[catch {set google(page) [http::geturl $google(url) -timeout 15000]} msg]} {putquick "NOTICE $nick :Can't connect ($msg)"return 0}set google(data) [http::data $google(page)]
if {$google(results) >= 1} {regexp -nocase {related:(.*?)>} $google(data) t link1}if {$google(results) >= 2} {regexp -nocase {related:.*?>.*?related:(.*?)>} $google(data) t link2}if {$google(results) >= 3} {regexp -nocase {related:.*?>.*?related:.*?>.*?related:(.*?)>} $google(data) t link3}
if {$google(perline) == 1} {set separator "\n"} else {set separator "-"}
if {[info exists link3]} {set output "http://$link1 $separator http://$link2 $separator http://$link3"} elseif {[info exists link2]} {set output "http://$link1 $separator http://$link2"} elseif {[info exists link1]} {set output "http://$link1"} else {set output "Nothing found."}regsub -all {%26} $output {\&} outputregsub -all {%3F} $output {?} outputregsub -all {%3D} $output {=} output
if {$google(perline) == 1} {foreach line [split $output \n] {google:output $chan $nick [string trim $line]}} else {google:output $chan $nick [string trim $output]}
catch { unset output separator t link1 link2 link3 }catch { http::cleanup $google(page) }
return 0}putlog "Google v1.0 EdiTeD By g0eZ loaded"
Sunday, August 28, 2011
Google.tcl
Labels:
tCL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment