This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Bug in Google.tcl by eRUPT

Support & discussion of released scripts, and announcements of new releases.
Post Reply
s
slot
Voice
Posts: 1
Joined: Sun Jun 12, 2005 10:59 am

Bug in Google.tcl by eRUPT

Post by slot »

Hi, could someone please tell me where the Bug is? define works perfect! but swtich search stops at regexp! i dont know why.

heres the code

Code: Select all

# Title: Google TCL For eggdrop
#
# Description: Searches google.com for url results via search terms
#
# Features: Multiple result urls, Can set number of results to return
#
# Author: eRUPT(erupt@ruptbot.com)
#


#########################
# Version History
#
# - 0.1b -
# First Release
#
# - 0.2 -
# Fixed Googles browser checking features.
#
# - 0.3 -
# Fixed Googles new formatting
#
# - 0.4 -
# Fixed Categories showing as first result.
#
# - 0.5 -
# Added option to limit channels script can be used on.
#
# - 0.6 -
# Fixed Googles new formatting
# Added Page titles to results if a page title exists.
#
# - 0.7 -
# Rewrote the whole text grabbing code.
# Added entity code replacing.
#
# - 0.8 -
# Rewrote pattern matching.
# Added "Define: <word>" support
#
#########################

set google(MAX) 10

set google(deny_CHANS) {
  #channel1
  #channel2
}
set google(VER) 0.8

package require http
bind pub - !google pub_google

proc html_replace {quotes} {
  regsub -all {‘|‘} $quotes "\`" quotes
  regsub -all {’|’} $quotes "\'" quotes
  foreach index [lsort -decreasing [regexp -all -indices -inline {&#[0-9]+;} $quotes]] {
     set binary_value [string range $quotes [lindex $index 0] [lindex $index 1]]
     regexp {[0-9]+} $binary_value match
     set quotes [string replace $quotes [lindex $index 0] [lindex $index 1] [format %c $match]]
  }
  return $quotes
}

proc pub_google {nick uhost hand chan arg} {
  global google
  if {[lsearch [string tolower $google(deny_CHANS)] [string tolower $chan]]!="-1"} {
    return 0
  }
  if {$arg==""} {
    putnot $nick "Usage: !google <search terms>"
    putnot $nick "Flags: -c1(Results to return) -a(Boolean And)"
    putnot $nick "(Use define: prefix to query definitions)"
    return 0
  }
  set type q
  set results 1
  foreach flag $arg {
    if {$flag=="-a"} { set type as_q ; continue } else {
      if {[regexp -- {-c[0-9]*} $flag]} {
	set results [string range $flag 2 end]
        continue
      }
    }
    lappend search $flag
  }
  if {$results>$google(MAX)} {
    putnot $nick "Max results allowed is \002$google(MAX)\002, omitting extra"
    set results $google(MAX)
  }
  search_google $chan $results $type $search
}

proc search_google {chan results type search} {
  regsub -all " " $search "+" search
  if {[string match -nocase define:* $search]} {
    set extra &oi=glossary_definition
    set result dict
    regsub {[Dd]efine:} $search {define:} search
  } else {
    set extra ""
    set result search
  }
  set url http://www.google.com/search?$type=$search&num=$results$extra
  http::config -useragent "Mozilla/5.0"
  set conn [http::geturl $url -headers "Referer http://www.google.com"]
  set data [http::data $conn]
  set count 0
  regsub -all {<b>|</b>} $data \002 data
  switch $result {
	search {
	  foreach {match url desc} [regexp -all -inline {<p class=g><a class=l href="([^"]*)">([^<]*)</a>} $data] {
  	    set desc [html_replace $desc]
 	    if {$count==$results} { break }
	    incr count 1
  	    if {$results>1} {
   	      putserv "PRIVMSG $chan :Result($count): \002$url\002 ($desc)"
   	    } else { putserv "PRIVMSG $chan :Result: \002$url\002 ($desc)" ; break }
  	  }
	}
	dict {
          foreach {match desc} [regexp -all -inline {<li>([^<]*)<br>} $data] {
            set desc [html_replace $desc]
            if {$count==$results} { break }
            incr count 1
            if {$results>1} {
              putserv "PRIVMSG $chan :Result($count): $desc"
            } else { putserv "PRIVMSG $chan :Result: $desc" ; break }
          }
	}
  }
  if {$count!=$results} {
    putserv "PRIVMSG $chan :Only could find \002$count\002 results"
  }
}

putlog "Google script $google(VER) by erupt loaded"
thanks
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Any Tcl errors?
Post Reply