Ford

Advanced Google / Echo back version

Jun 5th, 2011
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 7.61 KB | None | 0 0
  1. ;Advanced Google Search by Ford_Lawnmower irc.Geekshed.net #Script-Help
  2. alias -l GetAdvancedGoogle {
  3.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.   ;;;;;;Start of Simple Setup;;;;;;
  5.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.   ;;Change %MaxResults(below) to get a different number of results.(must be a number between 1 and 9)
  7.   var %MaxResults 4
  8.   ;;Change %GoogleLogo(below) to change the logo at the start of each line.(You cannot remove this, only change)
  9.   var %GoogleLogo $+($chr(2),$chr(3),12G,$chr(3),04o,$chr(3),08o,$chr(3),14g,$chr(3),09l,$chr(3),04e,$chr(3),$chr(2))
  10.   ;;Change %NameColor(below) to change the color of the results description.(You cannot remove this, only change)
  11.   var %NameColor $+($chr(3),04)
  12.   ;;Change %LinkColor(below) to change the color of the results link.(You cannot remove this, only change)
  13.   var %LinkColor $+($chr(3))
  14.   ;;Change %UseTinyURL(below) if you don't want links converted to tinyurl. Valid numbers are: 1 for convert and 0 for don't convert.
  15.   var %UseTinyURL 1
  16.   ;;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
  17.   var %CountryCode en
  18.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19.   ;;;;;;;Do not leave any of these variables blank!!!;;;;;;
  20.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
  22.   ;;;;;;End of Setup;;;;;;
  23.   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24.   $1-2 Searching Google........
  25.   var %sockname $+(AdvancedGoogle,$network,$2,$ticks)
  26.   sockopen %sockname ajax.googleapis.com 80
  27.   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)
  28. }
  29. menu Channel,Status {
  30.   .$iif($group(#AdvancedGoogle) == On,$style(1)) AdvancedGoogle Trigger
  31.   ..$iif($group(#AdvancedGoogle) == On,$style(2)) On: .enable #AdvancedGoogle
  32.   ..$iif($group(#AdvancedGoogle) == Off,$style(2)) Off: .disable #AdvancedGoogle
  33. }
  34. #AdvancedGoogle on
  35. On $*:Text:/^(\+|-|!|@)G(oogle|local|video|news|books|images|patent|help).*/Si:#: {
  36.   var %action $regml(1), %type $regml(2)
  37.   if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
  38.     if (%action == +) {
  39.       if ($istok(%AdvancedGoogleChanList,$+($network,$chan),32)) { msg $chan $nick $chan is already running the AdvancedGoogle script }
  40.       else {
  41.         .enable #AdvancedGoogle
  42.         Set %AdvancedGoogleChanList $addtok(%AdvancedGoogleChanList,$+($network,$chan),32)
  43.         msg $chan $nick has activated the AdvancedGoogle script for $chan .
  44.       }
  45.     }
  46.     else {
  47.       if (!$istok(%AdvancedGoogleChanList,$+($network,$chan),32)) { msg $chan $nick $chan is not running the AdvancedGoogle script }
  48.       else {
  49.         Set %AdvancedGoogleChanList $remtok(%AdvancedGoogleChanList,$+($network,$chan),1,32)
  50.         msg $chan $nick has deactivated the AdvancedGoogle script for $chan .
  51.       }
  52.     }
  53.   }
  54.   elseif (!$timer($+(AdvancedGoogle,$network,$nick))) && ($istok(%AdvancedGoogleChanList,$+($network,$chan),32)) {
  55.     .timer $+ $+(AdvancedGoogle,$network,$nick) 1 6 noop
  56.     var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),msg $chan,.notice $nick))
  57.     if (%type == help) || (!$2) { AdvancedGoogleHelp %method %action }
  58.     else { GetAdvancedGoogle %method $replace(%type,oogle,web) $2- }
  59.   }
  60. }
  61. #AdvancedGoogle end
  62. alias Google {
  63.   if ($istok(-local -video -news -books -images -patent,$1,32)) { GetAdvancedGoogle echo -a $mid($1,2) $2- }
  64.   else { GetAdvancedGoogle echo -a web $1- }
  65. }
  66. On *:sockopen:AdvancedGoogle*: {
  67.   if (!$sockerr) {
  68.     hmake $sockname
  69.     hadd $sockname max $gettok($sock($sockname).mark,3,32)
  70.     hadd $sockname urlcount 1
  71.     hadd $sockname itemcount 1
  72.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,8,32) HTTP/1.1
  73.     sockwrite -n $sockname Host: ajax.googleapis.com
  74.     sockwrite -n $sockname User-Agent: Opera 9.6
  75.     sockwrite -n $sockname $crlf
  76.   }
  77.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  78. }
  79. On *:sockread:AdvancedGoogle*: {
  80.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  81.   else {
  82.     sockread &AdvancedGoogle
  83.     var %count 1
  84.     while ($hget($sockname,max) >= $hget($sockname,urlcount)) && ($bintween(&AdvancedGoogle,"url":",",%count)) {
  85.       hadd $sockname $+(url,$hget($sockname,urlcount)) $dehex($ifmatch)
  86.       hinc $sockname urlcount      
  87.       inc %count
  88.     }
  89.     %count = 1
  90.     while ($hget($sockname,max) >= $hget($sockname,itemcount)) && ($bintween(&AdvancedGoogle,"content":",",%count) || $bintween(&AdvancedGoogle,"titlenoformatting":",",%count)) {
  91.       hadd $sockname $+(item,$hget($sockname,itemcount)) $replace($fix&#($dehex($ifmatch)),<b>,,</b>,)
  92.       hinc $sockname itemcount      
  93.       inc %count
  94.     }
  95.     if ($matchtok($hget($sockname,itemcount) $hget($sockname,urlcount),$hget($sockname,max),0,32) > 1) || ($bintween(&AdvancedGoogle,"responseStatus",200,1)) { clearhash }
  96.   }
  97. }
  98. On *:sockread:AdvancedGoogle*: { hfree $+(AdvancedGoogle,$sockname) }
  99. alias -l clearhash {
  100.   tokenize 32 $sock($sockname).mark
  101.   var %start 1, %matches $hfind($sockname,item[1-9],0,r)
  102.   if (%matches) {
  103.     while (%start <= %matches) {
  104.       if ($7) { Tiny $1-2 $hget($sockname,$+(url,%start)) $4 $+($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }
  105.       else { $1-2 $4 $+($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }
  106.       inc %start
  107.     }
  108.   }
  109.   else { $1-2 $4 Sorry, No results were found for your search. If you are having trouble type !ghelp }
  110.   hfree $sockname
  111.   sockclose $sockname
  112.   return
  113. }
  114. alias -l AdvancedGoogleHelp {
  115.   $1-2 Google Triggers are: $+($3,google) $+($3,glocal) $+($3,gvideo) $+($3,gnews) $+($3,gbooks) $+($3,gimages) $+($3,gpatent)
  116.   $1-2 Google Searches must include at least one search word: Example $+($3,gnews) Obama
  117. }
  118. alias -l urlencode return $regsubex($1-,/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
  119. alias -l fix&# { return $replace($regsubex($1-,/&#([0-9]{2});/g,$chr(\t)),&quot;,",&amp;,&) }
  120. alias -l bintween {
  121.   var %count = 1, %mark = 0, %mark2 = 0
  122.   while (%count <= $4) {
  123.     if ($bfind($1, %mark2, $2).text) {
  124.       %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
  125.       if ($bfind($1, %mark, $3).text) {
  126.         %mark2 = $bfind($1, %mark, $3).text
  127.       }
  128.       else { return 0 }
  129.     }
  130.     else { return 0 }
  131.     inc %count
  132.   }
  133.   return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
  134. }
  135. alias -l dehex { return $regsubex($1-,/\\u([a-f0-9]{4})|\%([a-f0-9]{2})/gi,$chr($base(\t,16,10))) }
  136. alias -l Tiny {
  137.   var %sockname $+(GTinyUrl,$network,$ticks,$r(1,$ticks))
  138.   sockopen %sockname tinyurl.com 80
  139.   sockmark %sockname $1-2 $+(/create.php?url=,$3) $3 $4-
  140. }
  141. On *:sockopen:GTinyUrl*: {
  142.   if (!$sockerr) {
  143.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
  144.     sockwrite -n $sockname Host: tinyurl.com
  145.     sockwrite -n $sockname $crlf
  146.   }
  147.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  148. }
  149. On *:sockread:GTinyUrl*: {
  150.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  151.   else {
  152.     var %Tiny | sockread %Tiny
  153.     if ($regex(%Tiny,/<blockquote><b>(.*)<\/b><br><small>/i)) {
  154.       tokenize 32 $sock($sockname).mark
  155.       $1-2 $replace($5-,$4,$regml(1))
  156.       sockclose $sockname
  157.       return
  158.     }
  159.   }
  160. }
  161. On *:Unload: { unset %AdvancedGoogleChanList* | hfree -w AdvancedGoogle* }
Add Comment
Please, Sign In to add comment