Guest User

Ford_Lawnmower - Google Search with Dialog

a guest
Mar 27th, 2010
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 8.53 KB | None | 0 0
  1. ;Google Script by Ford_Lawnmower irc.mindforge.org #USA
  2. dialog Google_Search {
  3.   title "Google Search"
  4.   size -1 -1 184 248
  5.   option dbu
  6.   edit "", 1, 8 14 130 10, autohs
  7.   button "Search", 2, 139 14 37 12
  8.   text "Enter your Search Below", 3, 56 6 73 8
  9.   text "Results:", 4, 82 24 25 8, center
  10.   text "", 5, 1 32 183 24, left
  11.   text "", 6, 1 72 183 24, left
  12.   text "", 7, 1 112 183 24, left
  13.   text "", 8, 1 152 183 24, left
  14.   text "", 9, 1 192 183 24, left
  15.   link "", 10, 1 56 182 16
  16.   link "", 11, 1 96 182 16
  17.   link "", 12, 1 136 182 16
  18.   link "", 13, 1 176 182 16
  19.   link "", 14, 1 216 182 16
  20.   button "Close", 15, 144 235 37 12, Cancel
  21.   text "", 16, 0 232 137 16
  22.   box "", 17, 0 28 184 44
  23.   box "", 18, 0 68 184 44
  24.   box "", 19, 0 108 184 44
  25.   box "", 20, 0 148 184 44
  26.   box "", 21, 0 188 184 44
  27.   icon 22, 0 2 47 11
  28. }
  29. On *:Dialog:Google_Search:init:*: {
  30.   if (!$isfile(logo_sm.gif)) { getlogo | .timer 1 2 did -g Google_Search 22 logo_sm.gif }
  31.   else { did -g Google_Search 22 logo_sm.gif }
  32.   google hawkee mirc scripts
  33. }
  34. On *:Dialog:Google_Search:Close:*: {
  35.   unset GoogleDialog.*
  36.   if ($sock(GoogleDialog)) { sockclose GoogleDialog }
  37. }
  38. On *:Dialog:Google_Search:Sclick:2: {
  39.   if ($did(Google_Search,1).text) {
  40.     var %count = 5
  41.     while (%count <= 14) {
  42.       did -r Google_Search %count
  43.       inc %count
  44.     }
  45.     did -r Google_Search 16
  46.     Google $did(Google_Search,1).text
  47.   }
  48.   else { return }
  49. }
  50. On *:Dialog:Google_Search:Sclick:10-14: {
  51.   if ($did(Google_Search,$did).text) {
  52.     if (http:// isin $left($did(Google_Search,$did).text,7)) {
  53.       if ($input(Are you sure you want to load $did(Google_Search,$did).text $+ ?,y,,,)) { run $did(Google_Search,$did).text }
  54.       else { return }
  55.     }
  56.     else {
  57.       did -r Google_Search 16
  58.       Google $did(Google_Search,$did).text    
  59.     }
  60.   }
  61.   else { return }
  62. }
  63. alias -l Google.timeout {
  64.   echo -at >Connection Timed Out< Google Script
  65.   Google.clear
  66. }
  67. alias -l Google.clear {
  68.   sockclose Google*
  69.   unset %Google*
  70.   .timer-Google* off
  71.   halt
  72. }
  73. alias -l Google {
  74.   set $+(%,Google,dialog,.count) 1  
  75.   sockclose $+(Google,dialog)
  76.   set $+(%,Google,dialog,.search) $replace($1-,$chr(32),+)
  77.   sockopen $+(Google,dialog) www.google.com 80
  78.   .timer $+ $+(Google,dialog) 1 10 Google.Clear
  79. }
  80. #GoogleTrigger on
  81. on *:TEXT:!Google*:# {
  82.   if ($sock($+(Google,$chan))) { .notice $nick Google in use!! | halt }
  83.   if (!$2) { .notice $nick Please provide something for me to search for!! Syntax is !Google search words here | halt }
  84.   set $+(%,Google,$chan,.nick) $nick
  85.   set $+(%,Google,$chan,.chan) $chan
  86.   set $+(%,Google,$chan,.count) 1
  87.   set $+(%,Google,$chan,.search) $replace($2-,$chr(32),+)
  88.   sockclose $+(Google,$chan)
  89.   sockopen $+(Google,$chan) www.google.com 80
  90.   .timer $+ $+(Google,$chan) 1 10 Google.Clear
  91. }
  92. #GoogleTrigger End
  93. on *:sockopen:Google*: {
  94.   var %search = $eval($+(%,$sockname,.search),2)
  95.   sockwrite -n $sockname GET $+(/search?client=opera&rls=en&q=,%search,&sourceid=opera&ie=utf-8&oe=utf-8) HTTP/1.1
  96.   sockwrite -n $sockname Host: www.google.com $+ $CRLF $+ $CRLF
  97. }
  98. on *:sockread:Google*: {
  99.   if ($sockerr > 0) { echo -a >Sock Error< Google | Google.clear }
  100.   else {
  101.     sockread  &Google
  102.     if ($bintween(&Google,class=p><b><i>,</i></b>,1)) {
  103.       if ($sockname == Googledialog)  {
  104.         did -a Google_Search 16 $strip($eval($+(%,$sockname,.chan),2) $fixhtml($+(Did You Mean,$chr(32),$bintween(&Google,class=p><b><i>,</i></b>,1),?)))
  105.       }
  106.       else { .msg $eval($+(%,$sockname,.chan),2) $fixhtml($+(Did You Mean,$chr(32),$bintween(&Google,class=p><b><i>,</i></b>,1),?)) }
  107.     }
  108.     if ($bintween(&Google,<p>Your search,did not match any documents.,1)) {
  109.       if ($sockname == Googledialog) { did -a Google_Search 5 Your Search Did not Match any Documents }
  110.       else { .msg $eval($+(%,$sockname,.chan),2) $fixhtml(Zero Results found for your Search) }
  111.       Google.Cleanup $sockname
  112.     }
  113.     if ($bintween(&Google,class=l>,<cite>,1)) && ($bintween(&Google,=r><a href="http://," class=l>,1)) && (results for <em> !isin $bintween(&Google,=r><a href=,s=l>,2)) {
  114.       if (results for <em> !isin $bintween(&Google,=r><a href=,s=l>,1)) {
  115.         if ($sockname == Googledialog) {
  116.           did -a Google_Search $calc($+(%,$sockname,.count) + 4) $dfix($eval($+(%,$sockname,.chan),2)  $fixhtml($bintween(&Google,class=l>,<cite>,1)))
  117.           did -a Google_Search $calc($+(%,$sockname,.count) + 9) $httpstrip($+(http://,$bintween(&Google,=r><a href="http://," class=l>,1)))
  118.         }
  119.         else { .msg $eval($+(%,$sockname,.chan),2)  $fixhtml($bintween(&Google,class=l>,<cite>,1)   $+(http://,$bintween(&Google,=r><a href="http://," class=l>,1))) }
  120.         inc $+(%,$sockname,.count)
  121.       }
  122.       if ($eval($+(%,$sockname,.count),2) >= 6) { Google.Cleanup $sockname }
  123.       if ($httpstrip($bintween(&Google,class=l>,</cite>,2)))  && ($httpstrip($bintween(&Google,=r><a href="http://," class=l>,2))) {
  124.         if ($sockname == Googledialog) {
  125.           did -a Google_Search $calc($+(%,$sockname,.count) + 4) $dfix($eval($+(%,$sockname,.chan),2)  $fixhtml($bintween(&Google,class=l>,<cite>,2)))
  126.           did -a Google_Search $calc($+(%,$sockname,.count) + 9) $httpstrip($+(http://,$bintween(&Google,=r><a href="http://," class=l>,2)))
  127.         }
  128.         else { .msg $eval($+(%,$sockname,.chan),2)  $fixhtml($bintween(&Google,class=l>,<cite>,2)   $+(http://,$bintween(&Google,=r><a href="http://," class=l>,2))) }
  129.         inc $+(%,$sockname,.count)
  130.       }
  131.       if ($eval($+(%,$sockname,.count),2) >= 6) { Google.Cleanup $sockname }
  132.       if ($httpstrip($bintween(&Google,class=l>,</cite>,3))) && ($httpstrip($bintween(&Google,=r><a href="http://," class=l>,3))) {
  133.         if ($sockname == Googledialog) {
  134.           did -a Google_Search $calc($+(%,$sockname,.count) + 4) $dfix($eval($+(%,$sockname,.chan),2)  $fixhtml($bintween(&Google,class=l>,<cite>,3)))
  135.           did -a Google_Search $calc($+(%,$sockname,.count) + 9) $httpstrip($+(http://,$bintween(&Google,=r><a href="http://," class=l>,3)))
  136.         }
  137.         else { .msg $eval($+(%,$sockname,.chan),2)  $fixhtml($bintween(&Google,class=l>,<cite>,3)   $+(http://,$bintween(&Google,=r><a href="http://," class=l>,3))) }
  138.         inc $+(%,$sockname,.count)
  139.       }
  140.       if ($eval($+(%,$sockname,.count),2) >= 6) { Google.Cleanup $sockname }
  141.     }
  142.   }
  143. }
  144. menu * {
  145.   Google
  146.   .Dialogs:Google_Search
  147.   .$iif($group(#GoogleTrigger) == On,$style(1)) GoogleTrigger
  148.   ..$iif($group(#GoogleTrigger) == On,$style(2)) On: .enable #GoogleTrigger
  149.   ..$iif($group(#GoogleTrigger) == Off,$style(2)) Off: .disable #GoogleTrigger
  150. }
  151. alias -l Google.Cleanup {
  152.   unset $+(%,$1,.*)
  153.   .timer $+ $1 off
  154.   sockclose $1
  155.   halt
  156. }
  157. alias -l Google_Search {
  158.   if ($dialog(Google_Search)) { dialog -v Google_Search Google_Search }
  159.   else { dialog -m Google_Search Google_Search }
  160. }
  161. alias -l dfix {
  162.   return $left($remove($strip($1-),**google**),200)
  163. }
  164. alias -l fixhtml {
  165.   var %fixmatch = $regex($1-,/(&#.*?;)/g), %fixtext = $replace($1-,<div class="s">,$chr(32))
  166.   while (%fixmatch) {
  167.     %fixtext = $replace(%fixtext,$regml(%fixmatch),$chr($remove($regml(%fixmatch),&#,;)))
  168.     dec %fixmatch
  169.   }
  170.   return 12**04G07o06o09g08l13e12** $httpstrip($replace($remove(%fixtext,&gt;,&lt;,&amp;,&quot;,&middot;,$chr(124)),$CRLF,$chr(32)))
  171. }
  172. alias -l bintween {
  173.   var %count = 1, %mark = 0, %mark2 = 0
  174.   while (%count <= $4) {
  175.     if ($bfind($1, %mark2, $2).text) {
  176.       %mark = $calc($bfind($1, %mark2, $2).text + $len($2))
  177.       if ($bfind($1, %mark, $3).text) {
  178.         %mark2 = $bfind($1, %mark, $3).text
  179.       }
  180.       else { return 0 }
  181.     }
  182.     else { return 0 }
  183.     inc %count
  184.   }
  185.   if ($calc(%mark2 - %mark) > 960) && ($version < 6.32) { return 0 }
  186.   else { return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text }
  187. }
  188. alias -l httpstrip {
  189.   var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
  190.   return %x
  191. }
  192. Alias -l GetLogo {
  193.   if ($isfile(logo_sm.gif)) { return }
  194.   set %GetLogo.Site www.google.com
  195.   set %GetLogo.URL /images/logo_sm.gif
  196.   set %GetLogo.PicName logo_sm.gif
  197.   sockclose GetLogo
  198.   sockopen GetLogo %GetLogo.site 80
  199. }
  200. On *:sockopen:GetLogo:{
  201.   sockwrite -nt $sockname GET %GetLogo.url HTTP/1.0
  202.   sockwrite $sockname Host: %GetLogo.site $+ $crlf $+ $crlf
  203. }
  204. On *:sockread:GetLogo:{
  205.   if (!$sock($sockname).mark) {
  206.     var %GetLogo.var | sockread %GetLogo.var
  207.     if (%GetLogo.var == $null) { sockmark $sockname 1 }
  208.   }
  209.   else {
  210.     sockread &logo
  211.     bwrite logo_sm.gif -1 -1 &logo
  212.   }
  213. }
  214. On *:sockclose:GetLogo:{
  215.   unset %GetLogo.*
  216. }
Add Comment
Please, Sign In to add comment