All pastes #637681 Raw Edit

Google script

public text v1 · immutable
#637681 ·published 2007-07-29 03:41 UTC
rendered paste body
;@@@
;@@@ DreamBot IRC Bot 5.4
;@@@ File description: google search script
;@@@ Search scripted by: daGroove ( www.grooves-welt.de )
;@@@ Dialog box scripted by: Dreambot Development team
;@@@ (C) Copyright 2004-2006 DreamBot development team & daGroove 
;@@@

;@@@ Dialog

alias google_search { dialog -ma google google }

dialog google {
  title "Google search configuration"
  option dbu
  size -1 -1 135 73
  icon "img/set.ico", 0
  button "Ok", 2, 30 55 35 12
  button "Cancel", 3, 70 55 35 12, cancel
  text "You can enable/disable Google script or change the max. number of results here.", 4, 10 10 115 15
  text "Max. results:", 20, 10 35 50 15
  edit "", 5, 45 32 30 10
  check "Enable script", 6, 10 45 50 10
}

on *:dialog:google:init:0: {
  if $group(#google) == on { did -c google 6 }
  if $group(#google) == off { did -u google 6 }
  if %google.max.results == $null { did -ra google 5 3 | halt }
  did -ra google 5 %google.max.results
}

on *:dialog:google:sclick:2: {
  if $did(google,5).text == $null { _error Please specify the maximum number of results! | halt }
  if $did(google,5).text <= 0 || $did(google,5).text > 9999 { _error Invalid number. Enter one between 1 and 9999. | halt }
  set %google.max.results $did(google,5).text
  if $did(google,6).state == 1 { .enable #google }
  if $did(google,6).state == 0 { .disable #google }
  dialog -c google
}

#google on
on *:text:*google*:#: { 
  if $1 == %c $+ google && $2- { set %google.num 0 | set %google.channel $chan | set %google.suche $replace($ifmatch,$chr(32),$chr(43)) | sockclose google | sockopen google www.google.com 80 }
  elseif $1 == %c $+ google { msg $chan Erm... I've no idea what to search for. Use %c $+ google keyword(s)! }
}
on *:sockopen:google: {
  if %google.max.results == $null { set %google.max.results 3 }
  sockwrite -n $sockname GET $+(/search?sourceid=navclient&hl=en&ie=UTF-8&rls=GGLD,GGLD:2004-04,GGLD:en&q=,%google.suche) HTTP/1.1
  sockwrite -n $sockname Host: www.google.com 
  sockwrite -n $sockname $crlf
}
on *:sockread:google: {
  $event %google.tmp
  if ($regex(%google.tmp,/<h2 class=.*><a href="(.*)" class=l>.*<b>/)) { $+(.timer.google,%google.num) 1 %google.num msg %google.channel 15*** 12G4o8o12g9l4e: 3 $regml(1) | inc %google.num 1 }
  if (%google.num == %google.max.results) { sockclose google | unset %google* }
}
#google end