Google Search

By tye on Oct 20, 2003

This snippet will retrieve the first search result for a query off of Google and execute a command on it.

; Tye @ DALnet, Undernet
; tye at mirc . net
;
; This snippet will retrieve the first search result for a query off of Google and execute a command on it.
; Copy this code into your remotes (Alt+R)
;
; /googlesearch alias query
; Results will be passed to command
alias googlesearch {
  var %x = 1
  while ($sock($+(google,%x))) inc %x
  sockopen $+(google,%x) www.google.com 80
  sockmark $+(google,%x) $1-
}
ON *:SOCKOPEN:google*: {
  if ($sockerr) {
    var %cmd = $gettok($sock($sockname).mark,1,32)
    %cmd Socket error $sockerr
    return
  }

  sockwrite -n $sockname GET $+(/search?q=,$phex($gettok($sock($sockname).mark,2-,32)),&btnI=I%27m+Feeling+Lucky HTTP/1.0)
  sockwrite $sockname $crlf
}
on *:SOCKREAD:google*: {
  var %f, %cmd, %result
  %cmd = $gettok($sock($sockname).mark,1,32)

  if ($sockerr) {
    %cmd Socket error $sockerr
    return
  }

  while (1) {
    sockread %f
    if (!$sockbr) break
    if (<A HREF="*">here</a>. iswm %f) {
      %result = $gettok(%f,2,34)
      sockclose $sockname
      break
    }
    elseif (HTTP/1.0 200 OK = %f) {
      %result = There are no results.
      sockclose $sockname
      break
    }
  }

  if (%result) {
    %cmd %result
  }
}
alias google { googlesearch google2 $1- }
alias google2 { echo $colour(info) -a *** Google search: $1- }

; !google query in a channel will message the channel with the results.
alias google3 { msg %google3 Google search: $1- | unset %google3 }
on *:TEXT:!google *:#: {
  set %google3 $chan
  googlesearch google3 $2-
}

; Convert some text to hexadecimal form
alias phex {
  var %x = 1, %s = $len($1), %r, %w
  while (%x <= %s) {
    %w = $mid($1,%x,1)
    if ($asc(%w) = 32) {
      %r = $+(%r,+)
    }
    elseif ($asc(%w) !isnum 65-90) && ($asc(%w) !isnum 97-122) && ($asc(%w) !isnum 48-57) {
      %r = $+(%r,%,$base($asc(%w),10,16,2))
    }
    else {
      %r = $+(%r,%w)
    }
    inc %x
  }
  return %r
}

Comments

Sign in to comment.
Skafandri   -  Jan 03, 2023

2022 - Works like a charm! (v7.72)
Best 1 :)

 Respond  
dma   -  Jul 19, 2015

works for me

 Respond  
Mrmot   -  Dec 01, 2014
xbox_gamer1   -  Oct 31, 2010

best code :)

 Respond  
Sikksens   -  Feb 22, 2010

Is there any way to add a google image search to this?
With the same type of random image result not just a whole page
full of your image results?

 Respond  
guest598594   -  May 03, 2008

; Tye @ DALnet, Undernet
; tye at mirc . net
;
; This snippet will retrieve the first search result for a query off of Google and execute a command on it.
; Copy this code into your remotes (Alt+R)
;

Eugenio: It\'s /google , not /googlesearch. ;)

; /googlesearch alias query
; Results will be passed to command
alias googlesearch {
  var %x = 1
  while ($sock($+(google,%x))) inc %x
  sockopen $+(google,%x) www.google.com 80
  sockmark $+(google,%x) $1-
}

;)

 Respond  
Akishoot   -  May 03, 2008

Eugenio: It\'s /google , not /googlesearch. ;)

 Respond  
Eugenio   -  Mar 07, 2008

THERE Unknown command i get that!

 Respond  
napa182   -  Mar 07, 2008

Eugenio
!google query in a channel will message the channel with the results. or /googlesearch alias query Results will be passed to command

 Respond  
Eugenio   -  Mar 07, 2008

How do i trigger this ?!?

 Respond  
yordan   -  Feb 18, 2008

i got no words for this is great work you irc maniac :)

 Respond  
Shadow Clash   -  Aug 11, 2007

Awesome google script ;]

 Respond  
Trav   -  May 26, 2007

Even though it has it\'s downs it\'s a great script and it can be very useful :D Is there a google search (not feeling lucky) script? Anyways nice work :D Good job

 Respond  
dragon_3290   -  Feb 11, 2007

anyway you can make this that other people in channel can do it like
!google search (subject)

---> Me <---- Noob Scripter

 Respond  
tye   -  Jan 05, 2007

You can\'t show more than one result without rewriting the snippet. The snippet uses the \"I\'m Feeling Lucky\" feature which returns only one result.

 Respond  
petrillo2000   -  Jan 05, 2007

how can u incraese the amount of sites it displays?

 Respond  
Cyber_God   -  Dec 09, 2006

Is it possible to show more than one result?

 Respond  
makkenai   -  Nov 05, 2006

very nice script , unfortunately while using it, it displayed urls which are on the ircqnet spamfilter list and it got my z:lined (network ban)

i have to disable it sadly enough to prevent such thing from happening again,
gonna me it :(

cya :)

 Respond  
Chainchomp   -  Sep 18, 2006

Nothing is better than this, total brilliance.

 Respond  
Pikachuh   -  Mar 13, 2005

it works total, and its an awesome google script wich includes space support!

 Respond  
tye   -  Mar 08, 2005

It works fine for me under 6.16. Make sure you put it in a new remote file and that your remotes are on: /remote on.

 Respond  
BullHorn   -  Feb 12, 2005

Not working in 6.16 or am I just too dumb? O_o

 Respond  
[-Superboyz-]   -  Feb 06, 2005

not working for mirc 6.14 and 6.16 why ???

 Respond  
tye   -  Sep 10, 2004

The script will work on the newest version of mIRC.

 Respond  
[-Superboyz-]   -  Aug 26, 2004

nice job but now why cant read for mirc613 ? thx

 Respond  
UTUCS.com-Admin   -  Feb 17, 2004

That\'s a cool script, Tye!

 Respond  
blue-elf   -  Dec 18, 2003

/me borrow some code

 Respond  
tye   -  Oct 21, 2003

yeah, that\'s basically all it does. Then it takes the URL and sends it to the aliases that was given in the initial command.

 Respond  
Hawkee   -  Oct 21, 2003

cool, so you take the I\'m feeling Lucky site and return the URL from the resulting redirect page?

 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.