Advanced Google Bot Search

By FordLawnmower on Mar 27, 2010

*First: Yes I know I already had a google search post. It has been trunicated to just a dialog search because I felt the dialog was slowing down the bot search and vise-versa. This script was written from scratch to take advantage of some new features of googles api.

*Now: This script will do web, local, video, news, books, images, and patent searches.
Triggers are as follows:
(!trigger for notice user - @trigger for message channel.)
!google = web search
!glocal = local search
!gvideo = video search
!gnews = news search
!gbooks = book search
!gimages = image search
!gpatent = patent search
!ghelp = trigger/syntax help

/google alias flags are as follows:
/google -local = local search
/google -video = video search
/google -news = news search
/google -books = book search
/google -images = image search
/google -patent = patent search

Getting the script running:
First: Copy this code, paste it into a new remote and save it with a unique filename.
Second: Review the Simple Setup portion of the script and make any changes to the script you feel necessary.
Third: Right click the channel or status, scroll to Advanced Google and turn on the script.
Last: Go to each channel that you want to run this script in and type +google .(you must have ops or higher to activate the script in a channel)(Note -google will deactivate the script in a channel.)

Example Output:
20:06:14 @gnews final 4
20:06:15 <Mind|Force> Searching Google........
20:06:16 <Mind|Force> Google Butler did it beats KSU 63-56 to make Final Four http://tinyurl.com/yekmz79
20:06:17 <Mind|Force> Google Butler Goes Home to Indianapolis for Final Four http://tinyurl.com/yd5f2e9
20:06:17 <Mind|Force> Google But on Saturday Butler earned another title: Final Four team. The fifth-seeded Bulldogs defeated second-seeded Kansas State 63-56 in Saturday's West ... http://tinyurl.com/yak2grf
20:06:19 <Mind|Force> Google Butler Beats Kansas State Is First Team to Reach Final Four http://tinyurl.com/ybesm4b

;Advanced Google Search by Ford_Lawnmower irc.Geekshed.net #Script-Help
alias -l GetAdvancedGoogle {
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;Start of Simple Setup;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;Change %MaxResults(below) to get a different number of results.(must be a number between 1 and 9)
  var %MaxResults 4
  ;;Change %GoogleLogo(below) to change the logo at the start of each line.(You cannot remove this, only change)
  var %GoogleLogo 12G04o08o14g09l04e
  ;;Change %NameColor(below) to change the color of the results description.(You cannot remove this, only change)
  var %NameColor 04
  ;;Change %LinkColor(below) to change the color of the results link.(You cannot remove this, only change)
  var %LinkColor 
  ;;Change %UseTinyURL(below) if you don't want links converted to tinyurl. Valid numbers are: 1 for convert and 0 for don't convert.
  var %UseTinyURL 1
  ;;Change %CountryCode(below) if you want your searches in a different language. Look here if you don't know your code -->> http://xml.coverpages.org/country3166.html
  var %CountryCode en
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;Do not leave any of these variables blank!!!;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
  ;;;;;;End of Setup;;;;;; 
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
  $1-2 Searching Google........
  var %sockname $+(AdvancedGoogle,$network,$2,$ticks)
  sockopen %sockname ajax.googleapis.com 80
  sockmark %sockname $1-2 %MaxResults %GoogleLogo %NameColor %LinkColor %UseTinyURL $+(/ajax/services/search/,$3,?v=1.0&rsz=large&q=,$urlencode($4-),&ql=,%CountryCode,&lr=lang_,%CountryCode)
}
menu Channel,Status {
  .$iif($group(#AdvancedGoogle) == On,$style(1)) AdvancedGoogle Trigger
  ..$iif($group(#AdvancedGoogle) == On,$style(2)) On: .enable #AdvancedGoogle
  ..$iif($group(#AdvancedGoogle) == Off,$style(2)) Off: .disable #AdvancedGoogle
}
#AdvancedGoogle on
On $*:Text:/^(\+|-|!|@)G(oogle|local|video|news|books|images|patent|help|site).*/Si:#: {
  var %action $regml(1), %type $regml(2)
  if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
    if (%action == +) {
      if ($istok(%AdvancedGoogleChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the AdvancedGoogle script }
      else { 
        .enable #AdvancedGoogle
        Set %AdvancedGoogleChanList $addtok(%AdvancedGoogleChanList,$+($network,$chan),32)
        .msg $chan $nick has activated the AdvancedGoogle script for $chan .
      }
    }
    else {
      if (!$istok(%AdvancedGoogleChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the AdvancedGoogle script }
      else { 
        Set %AdvancedGoogleChanList $remtok(%AdvancedGoogleChanList,$+($network,$chan),1,32)
        .msg $chan $nick has deactivated the AdvancedGoogle script for $chan . 
      }
    }
  }
  elseif (!$timer($+(AdvancedGoogle,$network,$nick))) && ($istok(%AdvancedGoogleChanList,$+($network,$chan),32)) {
    .timer $+ $+(AdvancedGoogle,$network,$nick) 1 6 noop
    var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%|\+)/),.msg $chan,.notice $nick))
    if (%type == help) || (!$2) { AdvancedGoogleHelp %method %action }
    elseif (%type == site) { GetAdvancedGoogle %method $replace(%type,oogle,web,site,web) $+(+site:,$2-) }
    else { GetAdvancedGoogle %method $replace(%type,oogle,web) $2- }
  }
}
#AdvancedGoogle end
alias Google {
  if ($istok(-local -video -news -books -images -patent,$1,32)) { GetAdvancedGoogle echo -a $mid($1,2) $2- }
  else { GetAdvancedGoogle echo -a web $1- }
}
On *:sockopen:AdvancedGoogle*: {
  if (!$sockerr) {
    hmake $sockname
    hadd $sockname max $gettok($sock($sockname).mark,3,32)
    hadd $sockname urlcount 1
    hadd $sockname itemcount 1
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,8,32) HTTP/1.1
    sockwrite -n $sockname Host: ajax.googleapis.com
    sockwrite -n $sockname User-Agent: Opera 9.6
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:AdvancedGoogle*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    sockread &AdvancedGoogle
    var %count 1
    while ($hget($sockname,max) >= $hget($sockname,urlcount)) && ($bintween(&AdvancedGoogle,"url":",",%count)) {
      hadd $sockname $+(url,$hget($sockname,urlcount)) $dehex($ifmatch)
      hinc $sockname urlcount      
      inc %count
    }
    %count = 1
    while ($hget($sockname,max) >= $hget($sockname,itemcount)) && ($bintween(&AdvancedGoogle,"content":",",%count) || $bintween(&AdvancedGoogle,"titlenoformatting":",",%count)) {
      hadd $sockname $+(item,$hget($sockname,itemcount)) $replace($fix&#($dehex($ifmatch)),<b>,,</b>,)
      hinc $sockname itemcount      
      inc %count
    }
    if ($matchtok($hget($sockname,itemcount) $hget($sockname,urlcount),$hget($sockname,max),0,32) > 1) || ($bintween(&AdvancedGoogle,"responseStatus",200,1)) { clearhash }
  }
}
On *:sockclose:AdvancedGoogle*: { hfree $+(AdvancedGoogle,$sockname) }
alias -l clearhash {
  tokenize 32 $sock($sockname).mark
  var %start 1, %matches $hfind($sockname,item[1-9],0,r)
  if (%matches) {
    while (%start <= %matches) {
      if ($7) { Tiny $1-2 $hget($sockname,$+(url,%start)) $4 $+($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }
      else { $1-2 $4 $+($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }
      inc %start
    }
  }
  else { $1-2 $4 Sorry, No results were found for your search. If you are having trouble type !ghelp }
  hfree $sockname
  sockclose $sockname
  return
}
alias -l AdvancedGoogleHelp {
  $1-2 Google Triggers are: $+($3,google) $+($3,glocal) $+($3,gvideo) $+($3,gnews) $+($3,gbooks) $+($3,gimages) $+($3,gpatent)
  $1-2 Google Searches must include at least one search word: Example $+($3,gnews) Obama
}
alias -l urlencode return $regsubex($1-,/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
alias -l fix&# { return $replace($regsubex($1-,/&#([0-9]{2});/g,$chr(\t)),&quot;,",&amp;,&,&middot;,·,\n,$chr(32)) }
alias -l bintween {
  var %count = 1, %mark = 0, %mark2 = 0
  while (%count <= $4) {
    if ($bfind($1, %mark2, $2).text) {
      %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
      if ($bfind($1, %mark, $3).text) {
        %mark2 = $bfind($1, %mark, $3).text
      }
      else { return 0 } 
    }
    else { return 0 }
    inc %count
  }
  return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
}
alias -l dehex { return $regsubex($1-,/\\u([a-f0-9]{4})|\%([a-f0-9]{2})/gi,$chr($base(\t,16,10))) }
alias -l Tiny {
  var %sockname $+(GTinyUrl,$network,$ticks,$r(1,$ticks))
  sockopen %sockname tinyurl.com 80
  sockmark %sockname $1-2 $+(/api-create.php?url=,$3) $3 $4-
}
On *:sockopen:GTinyUrl*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
    sockwrite -n $sockname Host: tinyurl.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
}
On *:sockread:GTinyUrl*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    sockread -f &tiny | var %tiny $bvar(&tiny,1-).text
    if ($regex(%tiny,(http://[^\s]*))) {
      tokenize 32 $sock($sockname).mark
      $1-2 $replace($5-,$4,$regml(1))
      sockclose $sockname
      return
    }
  }
}
On *:Unload: { unset %AdvancedGoogleChanList* | hfree -w AdvancedGoogle* }

Comments

Sign in to comment.
ovelayer   -  Jun 11, 2017

can anyone get this script working again?
was the best google script out..
would be greatly appreciated

 Respond  
^WeSt   -  May 16, 2016

I had create an addon Google-Search you can download it via this manager

More informations here: http://hawkee.com/snippet/17050/

commy  -  May 23, 2016

Sweet, thanks West. I've ran your module, and per your instructions there should be a seperate set of options for the Google module, but I cannot find them anywhere. It's properly loaded, it's working, but there's no dialogue popups for further option tweaking. Nothing in the pop-up for the module installer lets me further config the google module.

^WeSt  -  May 24, 2016

You can open the Google-Search module settings dialog from Menubar or /wgs_sets command.

  • Thanks!
Protheus  -  Nov 27, 2016

I have a question about your Google search: There is a slightly annoying series of characters (➜) i can't seem to edit out of the code. Would you mind telling me where i can find it?

Sign in to comment

commy   -  May 09, 2016

Hey Ford. Doesn't seem to be working anymore, I'm getting "Sorry, No results were found for your search. If you are having trouble type !ghelp" for everything. I'd been getting that message for a couple of months now with !gimages, but !google just recently started giving me that as well.

Somsubhra1  -  May 15, 2016

I think because google has stopped giving free APIs.

Grimnir  -  May 20, 2016

Yep, it no longer works for me either.

Sign in to comment

Somsubhra1   -  Jan 11, 2016

Can you add a filter for bad words here? :D Nice script though

 Respond  
commy   -  May 05, 2015

Something must have changed with Tinyurl, because I'm only getting results now if I disable it.

 Respond  
Subzeri   -  Apr 20, 2014

Very nice script but i have this problem....
if the command is !google obama it work well (send notice to user)...if use instead @google obama it work but "cannot send to the channel"
working on mirc 7.32 , server quakenet.org....any ideas how to fix?

 Respond  
MoonCrawlerVG   -  Nov 21, 2013

good scrpt but how do i make it so everyone sees it not just the user?

MoonCrawlerVG  -  Nov 23, 2013

Never mind that I figured it out.

Sanity  -  Mar 19, 2014

Care to clarify?

BonesX  -  Mar 19, 2014

Use @Google and make sure your notices go to your active window

Sanity  -  Mar 20, 2014

can you explain what I need to change in the code?

Sign in to comment

^WeSt   -  Oct 06, 2013

Not working on me! i have done +Google but when i use !google only return me an notice that said: Searching Google........
But no results appeared...

FordLawnmower  -  Oct 06, 2013

I still have this working 100% ^West. I don't see any problems scanning the code here. Pls. try loading the code from here to make sure: http://scriptbin.net/view/2bc2b6d3
If this works for you I will update the code here.

^WeSt  -  Oct 08, 2013

Well i try it from your url but still not working man, had an mini-test to on my currently bot i set a timer for msg the command: /timer 1 10 msg #test_chan !google IRC well after this i gone to my bot and using /socklist command to see if the add-on opens the socks the socks have been opened have a look into the socks. ALSO i have try it to an Clean mIRC with not any addons,dlls,aliases and still have this problem, stucking into the Searching.. notice!

SOCKS:

  • Open sockets:
  • GTinyUrlIRC9302222859544702 tinyurl.com:80 tcp connecting
    GTinyUrlIRC9302222885988378 tinyurl.com:80 tcp connecting
    GTinyUrlIRC9302222810312678 tinyurl.com:80 tcp connecting
    GTinyUrlIRC9302222819507000 tinyurl.com:80 tcp connecting

Also with the /google IRC command the /socklist result was:

GTinyUrlIRC9373864788866108 tinyurl.com:80 (195.66.135.249) tcp active (on: .146.243.84 57084)
GTinyUrlIRC9373864711705585 tinyurl.com:80 (195.66.135.249) tcp active (on:
.146.243.84 57085)

NOTE: i am using 7.32 mIRC version!!!!!

  • Thanks!
FordLawnmower  -  Oct 09, 2013

It sounds like you have an issue with tinyurl. Perhaps they are blocking you for some reason.
Try changing the var UseTinyURL to 0

;;Change %UseTinyURL(below) if you don't want links converted to tinyurl. Valid numbers are: 1 for convert and 0 for don't convert.
var %UseTinyURL 1

If this works , I can make an edit for you that uses a different link shortener. I have made a few of these because tinyurl is blocked by some countries.

^WeSt  -  Oct 09, 2013

Yes you're right now work perfect! i set it to 0 and worked!

FordLawnmower  -  Oct 09, 2013

What country are you in @^WeSt ?

^WeSt  -  Oct 09, 2013

Greece (Flag :P)

^WeSt  -  Oct 09, 2013

Also if you have a way to make the google commands to work without an +google or any other command to enable/disable the google just if anyone uses the command to display the results.

  • Thanks!
^WeSt  -  May 10, 2014

I found an way to work the tinyurl using %UseTinyURL 1 i have just edit an other code and thinking to change and yours so i try and find an way with this code mine is working , check it and if it is working and with yours so you can replace it.

On :sockread:GTinyUrl: {
if ($sockerr) { sockclose $sockname | return }
else {
sockread -f &tiny | var %tiny $bvar(&tiny,1-).text
var %tiny2 = $remove($gettok(%tiny,$numtok(%tiny,32),32),close,$crlf)
if (http://* iswm %tiny2) {
tokenize 32 $sock($sockname).mark
$1-2 $replace($5-,$4,%tiny2)
sockclose $sockname
return
}
}
}

Sign in to comment

cj42057   -  Jul 02, 2013

awesome script and I've used on it on my bot for awhile, just a heads up that something has changed in the tinyurl site causing the script to give links to the tinyurl preview link and not the actual link, screenshot here-> http://puu.sh/3ttej.png

 Respond  
FordLawnmower   -  Nov 06, 2012

It looks right now Hawkee . Thanks :)

 Respond  
Hawkee   -  Nov 04, 2012

@FordLawnmower I finally got to the bottom of this issue. I had hacked the JavaScript to remove the br's because I pass comments through a parser that calls nl2br. This was adding br's to each line of the code within comments, so I explicitly removed them from the code snippet. The side effect was it was also removing br's that should have been in the code. I came up with a solution to run nl2br on text outside the code tags. I wrote this function to solve it, http://www.hawkee.com/snippet/9705/

 Respond  
dagohill   -  Aug 22, 2012

grazie

 Respond  
Stewie1k94   -  Aug 18, 2012

Change line 37 to

 if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/)) {
 Respond  
dagohill   -  Aug 17, 2012

o/\o to the Lawnmower tested and all workin with no errors

 Respond  
Stewie1k94   -  Aug 14, 2012

[11:06am] <~Stewie> @Google google
[11:06am] <&thunderbolt> Searching Google........
[11:06am] <&thunderbolt> Google Find local businesses, view maps and get driving directions in Google Maps. http://tinyurl.com/6z3f3
[11:06am] <&thunderbolt> Google Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking ... http://tinyurl.com/161
[11:06am] <&thunderbolt> Google Google's free online language translation service instantly translates text and web pages. This translator supports: English, Afrikaans, Albanian, Arabic, ... http://tinyurl.com/eay43
[11:06am] <&thunderbolt> Google Google Earth lets you fly anywhere on Earth to view satellite imagery, maps, terrain, 3D buildings, from galaxies in outer space to the canyons of the ocean. http://tinyurl.com/cw4r9 Your amazing. :D

 Respond  
FordLawnmower   -  Aug 13, 2012

@Stewie1k94 Please get the script from here:: http://pastebin.com/77JFz4uS
The hawkee version will not work because
is being removed from the code boxes on posts here.

 Respond  
Stewie1k94   -  Aug 13, 2012

This don't work anymore. :/ > [8:15am] <~Stewie> +Google
[8:15am] <&thunderbolt> Stewie has activated the AdvancedGoogle script for #thunderbolt .
[8:15am] <~Stewie> @Google Google
[8:15am] <&thunderbolt> Searching Google........
[8:16am] <~Stewie> :/

 Respond  
MashhitDK   -  Jun 26, 2012

I've got a edited version of this and it's still working here

 Respond  
RIcko   -  Jun 26, 2012

It says Searching... then nothing appears, the script needs an update since its from 2010 =]


(Jun-Tue-26)(7:50:30:pm) <07~Ricko> @glocal kids
(Jun-Tue-26)(7:50:31:pm) 03@Pyro Searching Google........
(Jun-Tue-26)(7:50:48:pm) <07~Ricko> @gnews obama
(Jun-Tue-26)(7:50:49:pm) 03@Pyro Searching Google........


Please update it if its not gonna take alot of your time

good job though, 10/10.

 Respond  
FordLawnmower   -  May 23, 2012

@amclay To remove the "searching google" message just remove line 24 or put a ; in front of it.
Line 24:

$1-2 Searching Google........

Remove that line or change it to:

;$1-2 Searching Google........

; = This is a comment line. Do not process.

 Respond  
amclay   -  May 23, 2012

How would you make it not use two lines on the bot? I run this on a channel that has a time limit between posts, so messaging "searching google......" and then posting is not feasible. I think the answer is in this line, though I've tried cutting parts of it to no success.

  else { $1-2 $4 $+ ($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }

I think the $1-2 is banded to the text, though I'm not that familiar with mirc -quite- yet.

 Respond  
DhanRahl   -  Jan 14, 2012

Love this script, but for some reason I can't get it to only show 1 result...it gives me a "No results found" reply, but works fine with 2. Any fix for this? or did I do something wrong?

 Respond  
FordLawnmower   -  Jun 05, 2011

@commy this version will echo back to your screen: http://pastebin.com/MjX6HV6h
As for calling the script from the same client it is loaded in, you can make a On Input event to handle this but I would just suggest using botserv. (If you are on a network with botserv.)

//bs say # @google words here

You can also just use /google

 Respond  
Donovan   -  May 07, 2011

nvm

 Respond  
Stewie1k94   -  Apr 10, 2011

i find this script very usefull

 Respond  
FordLawnmower   -  Mar 05, 2011

@poopie You must have ops to turn on the script with +google
The script checks for one of these symbols ~ ! & @
If you don't have one of them when you type +google , the bot will ignore you.
The script will also notice you when you use the !google trigger. It's better to test with the @google trigger.
Try this command from the bots status: /google test

If this is working fine it could just be a matter of having the proper symbol by your nickname.

Also: Any other info you could post would be helpful. IRC type, OS, etc.

 Respond  
poopie   -  Mar 05, 2011

I think I did that right...
I have pasted it in to a new script ,save it with mrc extension,loaded in mIRC.Didn`t made any changes to it.
I have mIRC 6.5 with NoNameScript and owner in that channel.I dont get any replay from bot.
Look here :
Image

 Respond  
SoulMuncher   -  Mar 04, 2011

nice :D

 Respond  
FordLawnmower   -  Mar 04, 2011

@poopie I have this script still working.
Try following these instructions...
Getting the script running:

  • First: Copy this code, paste it into a new remote and save it with a unique filename.
  • Second: Review the Simple Setup portion of the script and make any changes to the script you feel necessary.
  • Third: Right click the channel or status, scroll to Advanced Google and turn on the script.
  • Last: Go to each channel that you want to run this script in and type +google .(you must have ops or higher to activate the script in a channel)(Note -google will deactivate the script in a channel.)
 Respond  
poopie   -  Mar 04, 2011

Same as imdb,not working at all

 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.