Advanced Google Eggdrop Script

By FordLawnmower on May 28, 2010

This is a tcl script for eggdrop. Not for mIRC!
Loading:

  • Save this code to a file called AdvancedGoogle.tcl
  • Place the file in your eggdrop scripts directory
  • Add this line to eggdrop.conf -->> source scripts/AdvancedGoogle.tcl
  • Rehash or restart your eggdrop
  • (In the console) type .chanset #channelname +google "where #channelname is the channel you want the script on in"
    Triggers:
  • !google search words (general searches)
  • !glocal search words (returns results related to a local area search)
  • !gvideo search words (returns video results)
  • !gnews search words (returns news results related you your search words)
  • !gbook search words (returns book results)
  • !gimage search words (returns image/picture results)
  • !gpatent search words (does a search of registered patents)
    Example Output:
    21:02:04 !google eggdrop
    21:02:06 google Eggheads.org - Main Index http://www.eggheads.org/
    21:02:07 google Eggheads.org - Downloads http://www.eggheads.org/downloads/
    21:02:07 google slennox''s eggdrop page http://www.egghelp.org/
##############################################################################################
##  ## Advanced Google.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help  ##  ##
##############################################################################################
##  ## To use this script you must set channel flag +google (ie .chanset #chan +google) ##  ##
##############################################################################################
##############################################################################################
##  ##                             Start Setup.                                         ##  ##
##############################################################################################
## Change the character between the "" below to change the command character/trigger.       ##
set googlecmdchar "!"
proc google {nick host hand chan type search} {
  if {[lsearch -exact [channel info $chan] +google] != -1} {
## Change the country code between the "" below to change the language of your results.     ##
    set googlectry "en"
## Change the number between the "" below to change the number of results returned.         ##
    set googlemax "3"
## Change the characters between the "" below to change the logo shown with each result.    ##
    set googlelogo "\002\0032g\0034o\0038o\00314g\0039l\0034e\002\003"
## Change the format codes between the "" below to change the color/state of the text.      ##
    set textf "\0034"
## Change the format codes between the "" below to change the color/state of the links.     ##
    set linkf "\003\037"
##############################################################################################
##  ##                           End Setup.                                              ## ##
##############################################################################################
    set googlesite ajax.googleapis.com
    set googleurl /ajax/services/search/${type}?v=1.0&rsz=large&q=${search}&ql=${googlectry}&lr=lang_${googlectry}
    if {[catch {set googlesock [socket -async $googlesite 80]} sockerr]} {
      putlog "$googlesite $googleurl $sockerr error"
      return 0
      } else {
      puts $googlesock "GET $googleurl HTTP/1.0"
      puts $googlesock "Host: $googlesite"
      puts $googlesock "User-Agent: Opera 9.6"
      puts $googlesock ""
      flush $googlesock
      while {![eof $googlesock]} {
        set googlevar " [gets $googlesock] "
        set googlelink [regexp -all -nocase -inline {\"url\":\"([^\"]*)\"} $googlevar]
        set googledesc [regexp -all -nocase -inline {\"title\":\"([^\"]*)\"} $googlevar]
        if {$googledesc != "" && $googlelink != ""} {
          for {set x 1} {$x <= [expr 2 * $googlemax]} {incr x 2} {
            if {[lindex $googledesc $x] != "" && [lindex $googlelink $x] != ""} {
             putserv "PRIVMSG $chan :$googlelogo $textf[dehex [lindex $googledesc $x]] $linkf[dehex [lindex $googlelink $x]]" 
            }
          }
        }
      }
      close $googlesock
      return 0 
    }
  }
}
proc asc {chr} {
  scan $chr %c asc
  return $asc
}
proc chr {asc} { return [format %c $asc] }
proc hex {decimal} { return [format %x $decimal] }
proc decimal {hex} { return [expr 0x$hex] }
proc dehex {string} {
  set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} [noeval $string] {[format %c [decimal \1]]}]]
  set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} [noeval $string] {[format %c [decimal \1]]}]]
  set string [subst [regsub -nocase -all {\&#([0-9]{2});} [noeval $string] {[format %c \1]}]]
  set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002} $string]
  return $string
}
proc noeval {string} {
  return [string map {[ \\[ ] \\] $ \\$ ( \\( ) \\)} $string]
}
proc urlencode {string} {
  regsub -all {^\{|\}$} $string "" string
  return [subst [regsub -nocase -all {([^a-z0-9])} $string {%[format %x [scan "\\&" %c]]}]]
}
proc googleweb {nick host hand chan args} { google $nick $host $hand $chan "web" [urlencode $args] }
proc googlelocal {nick host hand chan args} { google $nick $host $hand $chan "local" [urlencode $args] }
proc googlevideo {nick host hand chan args} { google $nick $host $hand $chan "video" [urlencode $args] }
proc googlenews {nick host hand chan args} { google $nick $host $hand $chan "news" [urlencode $args] }
proc googlebook {nick host hand chan args} { google $nick $host $hand $chan "books" [urlencode $args] }
proc googleimage {nick host hand chan args} { google $nick $host $hand $chan "images" [urlencode $args] }
proc googlepatent {nick host hand chan args} { google $nick $host $hand $chan "patent" [urlencode $args] }
bind pub - ${googlecmdchar}google googleweb
bind pub - ${googlecmdchar}glocal googlelocal
bind pub - ${googlecmdchar}gvideo googlevideo
bind pub - ${googlecmdchar}gnews googlenews
bind pub - ${googlecmdchar}gbook googlebook
bind pub - ${googlecmdchar}gimage googleimage
bind pub - ${googlecmdchar}gpatent googlepatent
setudef flag google

Comments

Sign in to comment.
trotro45   -  Sep 16, 2016

Hello still no response after more than a month?

 Respond  
trotro45   -  Aug 01, 2016

Hello, yesterday I submitted my eggdrop on and I realize that the script does not work anymore.
Me and my friends we used it a lot.
Is it possible that you put it a day I do not have the knowledge to do so.
I thank you in advance.

Regards,

 Respond  
ThePHX   -  Feb 18, 2013

Thanks so much!

 Respond  
Nashman   -  Sep 29, 2012

Works like a charm! Thx alot :)

 Respond  
FordLawnmower   -  Sep 29, 2012

@Nashman aside from editing the colors in the setup at the top of the script, you will need to change line 64 of the script from:

set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002} $string]

to:

set string [string map {&quot; \" &middot; · &amp; & <b> "" </b> ""} $string]

The colors in the setup will also need to be changed to ""
And the logo to just plain "Youtube"

 Respond  
Nashman   -  Sep 29, 2012

@FordLawnmower I removed the script, restarted the bot and then added the script again. Didn't work. I reset the chanmode file, didn't work. Then i completely redid the bot and now it's working again... i dunno what sorcery this is but ye.. it's working again.
Thanks for your reply tho! :)

Edit: it appears that the +c chanmode had some influence in that aswell (no bold/colored text). I've removed the colored google links before but the bold part is still there. Could you point me to how i can remove the bold highlight part of the displayed link?

 Respond  
FordLawnmower   -  Sep 29, 2012

@Nashman I can't find any problems with this script. I just loaded it from here to a new bot with no issues.
Can you explain your problem a little.

 Respond  
Nashman   -  Sep 27, 2012

Hey Ford.
Thanks for that great script.. however, it's not working anymore.
I think the googleapi has changed and i don't know how to fix it.

Could you please point me in the right direction? :)
Much appreciated.

 Respond  
Dramakus   -  May 30, 2012

thanks man :)

 Respond  
FordLawnmower   -  May 30, 2012

@Dramakus Sure. Just change line 12 from:

  if {[lsearch -exact [channel info $chan] +google] != -1} {

To:

  if {[lsearch -exact [channel info $chan] +google] != -1 && [isvoice $nick $chan]} {

Keep in mind that this method uses the irc module which keeps track of voiced users by recording mode changes.
In other words, if the bot didn't see a user get voiced it will not recognize him/her as a voiced user.

 Respond  
Dramakus   -  May 30, 2012

Could anyone tell me how to make this command only usable by voiced or above?

 Respond  
FordLawnmower   -  May 15, 2012

@GravitaZ The "unmatched open quote" error should be resolved in all scripts now.
Hawkee fixed it yesterday. Please try copying the code for twitter search again and let me know if you have any problems. This was just a simple matter of " being converted to " inside the code box, causing a unmatched quote in a call to "string map" . It should be fine now :)

 Respond  
GravitaZ   -  May 15, 2012

Thanks FordLawnmower! It looks like your twitter search has the same issue.

 Respond  
FordLawnmower   -  May 12, 2012

Thanks for noticing this GravitaZ.
Due to a parsing issue , the code at the top is broken.
For now just use this code please: http://pastebin.com/46NsLDJG

 Respond  
GravitaZ   -  May 10, 2012

I am getting this error
" Tcl error [googleweb]: unmatched open quote in list"

 Respond  
FordLawnmower   -  Aug 09, 2011

I still have this working fine rmnts .
Did you go to the console and turn the script on for a channel?

.chanset #ChannelName +google
albanezo  -  Jun 28, 2016

what is Console ?

Sign in to comment

rmnts   -  Aug 09, 2011

is it working any more? 'cause for me it isn't :(

 Respond  
Brock   -  Mar 18, 2011

Thanks.. this script is very good

 Respond  
SweetBD   -  Dec 23, 2010

Hi, i done the step 1, 2, 3 and 4 which is to restar the eggdrop which was all fine but where or how do i do step five "In the console" please help me many Thanks

 Respond  
Get_A_Fix   -  Jun 13, 2010

yes, it only outputs 1 line, even if i googlemax "5" or googlemax "10" - not sure why, i've played around with it a bit

.google sex <- should return more than 1 :>

 Respond  
FordLawnmower   -  Jun 13, 2010

Hmm, No idea there Get_A_Fix. The only time I get that is when the search only returns one result.
If you change googlemax to a higher number do you still get only one result?

 Respond  
Get_A_Fix   -  Jun 13, 2010

weird, only returns 1 line for me, no errors. Code looks fine, not sure why

set googlemax "3"

 Respond  
Firstmate   -  May 31, 2010

Yeah that's just because he has not updated to 5.3
You can just ignore it.

 Respond  
Jethro   -  May 29, 2010

I get these upon entry to that link:> Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 114

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 474

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 488

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 503

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 522

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 545

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 583

Deprecated: Call-time pass-by-reference has been deprecated in E:\Inetpub\wwwroot\mIRC\engine.php on line 589

 Respond  
Firstmate   -  May 29, 2010

It's not a full interpreter, but it's still pretty dam amazing.

 Respond  
FordLawnmower   -  May 29, 2010

Oh, thanks Firstmate. I'll have a look at it later :)

 Respond  
Firstmate   -  May 29, 2010

@Ford: It was made by FleshTH and Wiz126 on SwiftIRC. Link: http://fleshth.no-ip.org/mIRC/

 Respond  
FordLawnmower   -  May 29, 2010

@darkc0de a conversion script from mIRC to tcl would be a monster task as tcl has very few built in functions. It could be done but you would have to have nothing but time on your hands.
I have seen some routines for mIRC re-written in perl and php. If you look around you can find them. I have also heard about a full mSL interpreter written in php, but I've never seen it myself.
I'm pretty decent at converting them but it would have to be a script that would be used by a large number of people before I would consider it.

 Respond  
darkc0de   -  May 28, 2010

@kent : for free eggrop try install in your computer 1st.. Is use eggdrop for windows.. Or try to install in some shell or vps..

 Respond  
darkc0de   -  May 28, 2010

Bro can u write converter script from mirc script to tcl/php/perl script ?.. N can u give some suggestions software to cek php n perl scrpt?.. Thx ford..

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.