egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug in Google.tcl by eRUPT

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
slot
Voice


Joined: 12 Jun 2005
Posts: 1

PostPosted: Sat Jan 27, 2007 2:32 pm    Post subject: Bug in Google.tcl by eRUPT Reply with quote

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:

# 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 {‘|&lsquo;} $quotes "\`" quotes
  regsub -all {’|&rsquo;} $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
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Jan 27, 2007 8:30 pm    Post subject: Reply with quote

Any Tcl errors?
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber