All pastes #421276 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-02 19:10 UTC
rendered paste body
on $*:TEXT:/^[!@]google/Si:#:{
  if ($2 == $null) {
    $iif($left($1,1) == @, msg $chan, notice $nick) 7[14Google7] 14Please enter something to search for.
  }
  else {
    /inc %t
    set $+(%,return.,%t) $iif($left($1,1) == @, msg $chan, notice $nick)
    set $+(%,google.,%t) $replace($2-,$chr(32),+)
    sockopen $+(google.,%t) www.google.com 80
  }
}
on *:SOCKOPEN:google.*: {
  sockwrite -nt $sockname GET /search?hl=en&q= $+ %google. [ $+ [ %t ] ] $+ &btnI=I%27m+Feeling+Lucky HTTP/1.1
  sockwrite -nt $sockname Host: www.google.com
  sockwrite -nt $sockname $crlf
}
on *:SOCKREAD:google.*: {
  if ($sockerr) {
    %return. [ $+ [ %t ] ] 7[14Google7]14 Socket error, please notify my owner.
    halt
  }
  var %read
  sockread %read
  if (*Your search* iswm %read) { %return. [ $+ [ %t ] ] 7[14Google7]14 %google. [ $+ [ %t ] ] - Word not found.
    sockclose $sockname 
    /unset %google. [ $+ [ %t ] ]
    /unset %return. [ $+ [ %t ] ]
  }
  if (*Location* iswm %read) {
    %return. [ $+ [ %t ] ] 7[14Google7]14 Top result:7 $gettok(%read,2,32) $+ 
    sockclose $sockname
    /unset %google. [ $+ [ %t ] ]
    /unset %return. [ $+ [ %t ] ]
  }
}