Ford

Advanced Google bot script for mIRC

Jul 26th, 2012
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 7.65 KB | None | 0 0
  1. ;Advanced Google Search by Ford_Lawnmower irc.mindforge.org #USA-Chat
  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 12G04o08o14g09l04e
  10.   ;;Change %NameColor(below) to change the color of the results description.(You cannot remove this, only change)
  11.   var %NameColor 04
  12.   ;;Change %LinkColor(below) to change the color of the results link.(You cannot remove this, only change)
  13.   var %LinkColor 
  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|site).*/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.     elseif (%type == site) { GetAdvancedGoogle %method $replace(%type,oogle,web,site,web) $+(+site:,$2-) }
  59.     else { GetAdvancedGoogle %method $replace(%type,oogle,web) $2- }
  60.   }
  61. }
  62. #AdvancedGoogle end
  63. alias Google {
  64.   if ($istok(-local -video -news -books -images -patent,$1,32)) { GetAdvancedGoogle echo -a $mid($1,2) $2- }
  65.   else { GetAdvancedGoogle echo -a web $1- }
  66. }
  67. On *:sockopen:AdvancedGoogle*: {
  68.   if (!$sockerr) {
  69.     hmake $sockname
  70.     hadd $sockname max $gettok($sock($sockname).mark,3,32)
  71.     hadd $sockname urlcount 1
  72.     hadd $sockname itemcount 1
  73.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,8,32) HTTP/1.1
  74.     sockwrite -n $sockname Host: ajax.googleapis.com
  75.     sockwrite -n $sockname User-Agent: Opera 9.6
  76.     sockwrite -n $sockname $crlf
  77.   }
  78.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  79. }
  80. On *:sockread:AdvancedGoogle*: {
  81.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  82.   else {
  83.     sockread &AdvancedGoogle
  84.     var %count 1
  85.     while ($hget($sockname,max) >= $hget($sockname,urlcount)) && ($bintween(&AdvancedGoogle,"url":",",%count)) {
  86.       hadd $sockname $+(url,$hget($sockname,urlcount)) $dehex($ifmatch)
  87.       hinc $sockname urlcount      
  88.       inc %count
  89.     }
  90.     %count = 1
  91.     while ($hget($sockname,max) >= $hget($sockname,itemcount)) && ($bintween(&AdvancedGoogle,"content":",",%count) || $bintween(&AdvancedGoogle,"titlenoformatting":",",%count)) {
  92.       hadd $sockname $+(item,$hget($sockname,itemcount)) $replace($fix&#($dehex($ifmatch)),<b>,,</b>,)
  93.       hinc $sockname itemcount      
  94.       inc %count
  95.     }
  96.     if ($matchtok($hget($sockname,itemcount) $hget($sockname,urlcount),$hget($sockname,max),0,32) > 1) || ($bintween(&AdvancedGoogle,"responseStatus",200,1)) { clearhash }
  97.   }
  98. }
  99. On *:sockclose:AdvancedGoogle*: { hfree $+(AdvancedGoogle,$sockname) }
  100. alias -l clearhash {
  101.   tokenize 32 $sock($sockname).mark
  102.   var %start 1, %matches $hfind($sockname,item[1-9],0,r)
  103.   if (%matches) {
  104.     while (%start <= %matches) {
  105.       if ($7) { Tiny $1-2 $hget($sockname,$+(url,%start)) $4 $+($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }
  106.       else { $1-2 $4 $+($5,$hget($sockname,$+(item,%start))) $+(,$6,$hget($sockname,$+(url,%start)),) }
  107.       inc %start
  108.     }
  109.   }
  110.   else { $1-2 $4 Sorry, No results were found for your search. If you are having trouble type !ghelp }
  111.   hfree $sockname
  112.   sockclose $sockname
  113.   return
  114. }
  115. alias -l AdvancedGoogleHelp {
  116.   $1-2 Google Triggers are: $+($3,google) $+($3,glocal) $+($3,gvideo) $+($3,gnews) $+($3,gbooks) $+($3,gimages) $+($3,gpatent)
  117.   $1-2 Google Searches must include at least one search word: Example $+($3,gnews) Obama
  118. }
  119. alias -l urlencode return $regsubex($1-,/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
  120. alias -l fix&# { return $replace($regsubex($1-,/&#([0-9]{2});/g,$chr(\t)),&quot;,",&amp;,&,&middot;,·) }
  121. alias -l bintween {
  122.   var %count = 1, %mark = 0, %mark2 = 0
  123.   while (%count <= $4) {
  124.     if ($bfind($1, %mark2, $2).text) {
  125.       %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
  126.       if ($bfind($1, %mark, $3).text) {
  127.         %mark2 = $bfind($1, %mark, $3).text
  128.       }
  129.       else { return 0 }
  130.     }
  131.     else { return 0 }
  132.     inc %count
  133.   }
  134.   return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
  135. }
  136. alias -l dehex { return $regsubex($1-,/\\u([a-f0-9]{4})|\%([a-f0-9]{2})/gi,$chr($base(\t,16,10))) }
  137. alias -l Tiny {
  138.   var %sockname $+(GTinyUrl,$network,$ticks,$r(1,$ticks))
  139.   sockopen %sockname tinyurl.com 80
  140.   sockmark %sockname $1-2 $+(/create.php?url=,$3) $3 $4-
  141. }
  142. On *:sockopen:GTinyUrl*: {
  143.   if (!$sockerr) {
  144.     sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
  145.     sockwrite -n $sockname Host: tinyurl.com
  146.     sockwrite -n $sockname $crlf
  147.   }
  148.   else { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  149. }
  150. On *:sockread:GTinyUrl*: {
  151.   if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  152.   else {
  153.     var %Tiny | sockread %Tiny
  154.     if ($regex(%Tiny,/<blockquote><b>(.*)<\/b><br><small>/i)) {
  155.       tokenize 32 $sock($sockname).mark
  156.       $1-2 $replace($5-,$4,$regml(1))
  157.       sockclose $sockname
  158.       return
  159.     }
  160.   }
  161. }
  162. On *:Unload: { unset %AdvancedGoogleChanList* | hfree -w AdvancedGoogle* }
Add Comment
Please, Sign In to add comment