Advanced Google Bot Search

Platform:  mIRC
Published  Mar 27, 2010
Updated  Jul 26, 2012
*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 <Ford> @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.mindforge.org #USA-Chat
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).*/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 }
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;,ยท) }
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 $+(/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 {
var %Tiny | sockread %Tiny
if ($regex(%Tiny,/<blockquote><b>(.*)<\/b><br><small>/i)) {
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.
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 toclafane1
 Respond  
toclafane1   -  Aug 18, 2012
Change line 37 to

Code

 

 Respond  
dagohill   -  Aug 17, 2012
o/\o to the Lawnmower tested and all workin with no errors
 Respond  
toclafane1   -  Aug 14, 2012

Quote

[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
@toclafane1 Please get the script from here:: http://pastebin.com/77JFz4uS
The hawkee version will not work because <br> is being removed from the code boxes on posts here.
 Respond  
toclafane1   -  Aug 13, 2012
This don't work anymore. :/

Quote

[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:

Code

 


Remove that line or change it to:

Code

 

; = 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.)

Code

 

You can also just use /google
 Respond  
commy   -  Jun 05, 2011
Nice script, but I'm having one major problem with it. I generally don't run a seperate bot, as I don't want a seperate mIRC open. So in the past all !google, !imdb etc. commands would just go through me. The problem is that with other scripts, when I type !/@g test, it shows the results. This doesn't work in this script. It only acknowledges when other people use the command.

Secondly, when someone else uses it, the search results are sent to the channel, yet on my screen, I don't see it at all. Is there anyway to fix this? I was really looking forward to using this script. Thanks :)
 Respond  
Donovan   -  May 07, 2011
nvm
 Respond  
toclafane1   -  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 :
 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  
Kingc44   -  Feb 02, 2011
@Pangaea try typing +google first
 Respond  
Pangaea   -  Feb 02, 2011
having trouble getting this to work:

<Pangaea> !google test search
<Pangaea> !google test search
<Pangaea> @google test search
<Pangaea> @google test search
<Pangaea> !google test search

the right click menu shows the trigger is on for the channel, what else can i do? any ideas?
 Respond  
FordLawnmower   -  Oct 27, 2010
Thanks Brock :)
 Respond  
Brock   -  Oct 27, 2010
Best Google script so far +1
 Respond  
FordLawnmower   -  Oct 26, 2010
Ok BonesX. Make sure you turn tinyurl off in that pastebin version. I forgot to change it.
The adjustments I made don't apply to tinyurl, only normal url.
 Respond  
BonesX   -  Oct 26, 2010
yes same with tiny url I will try the one posted at the link above and let you know
 Respond  
FordLawnmower   -  Oct 23, 2010
Okay. Try this edit BonesX -->> http://pastebin.com/L7PwnWmj
Just curious: Did you have the same hyphen issue with tinyurl or didn't you try it?
 Respond  
BonesX   -  Oct 23, 2010
No using full url
 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.