SHARE
TWEET

Advanced Google for eggdrop

Ford May 12th, 2012 337 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##############################################################################################
  2. ##  ## Advanced Google.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help  ##  ##
  3. ##############################################################################################
  4. ##  ## To use this script you must set channel flag +google (ie .chanset #chan +google) ##  ##
  5. ##############################################################################################
  6. ##############################################################################################
  7. ##  ##                             Start Setup.                                         ##  ##
  8. ##############################################################################################
  9. ## Change the character between the "" below to change the command character/trigger.       ##
  10. set googlecmdchar "!"
  11. proc google {nick host hand chan type search} {
  12.   if {[lsearch -exact [channel info $chan] +google] != -1} {
  13. ## Change the country code between the "" below to change the language of your results.     ##
  14.     set googlectry "en"
  15. ## Change the number between the "" below to change the number of results returned.         ##
  16.     set googlemax "3"
  17. ## Change the characters between the "" below to change the logo shown with each result.    ##
  18.     set googlelogo "\002\0032g\0034o\0038o\00314g\0039l\0034e\002\003"
  19. ## Change the format codes between the "" below to change the color/state of the text.      ##
  20.     set textf "\0034"
  21. ## Change the format codes between the "" below to change the color/state of the links.     ##
  22.     set linkf "\003\037"
  23. ##############################################################################################
  24. ##  ##                           End Setup.                                              ## ##
  25. ##############################################################################################
  26.     set googlesite ajax.googleapis.com
  27.     set googleurl /ajax/services/search/${type}?v=1.0&rsz=large&q=${search}&ql=${googlectry}&lr=lang_${googlectry}
  28.     if {[catch {set googlesock [socket -async $googlesite 80]} sockerr]} {
  29.       putlog "$googlesite $googleurl $sockerr error"
  30.       return 0
  31.       } else {
  32.       puts $googlesock "GET $googleurl HTTP/1.0"
  33.       puts $googlesock "Host: $googlesite"
  34.       puts $googlesock "User-Agent: Opera 9.6"
  35.       puts $googlesock ""
  36.       flush $googlesock
  37.       while {![eof $googlesock]} {
  38.         set googlevar " [gets $googlesock] "
  39.         set googlelink [regexp -all -nocase -inline {\"url\":\"([^\"]*)\"} $googlevar]
  40.        set googledesc [regexp -all -nocase -inline {\"title\":\"([^\"]*)\"} $googlevar]
  41.        if {$googledesc != "" && $googlelink != ""} {
  42.          for {set x 1} {$x <= [expr 2 * $googlemax]} {incr x 2} {
  43.            putserv "PRIVMSG $chan :$googlelogo $textf[dehex [lindex $googledesc $x]] $linkf[dehex [lindex $googlelink $x]]"
  44.          }
  45.        }
  46.      }
  47.      close $googlesock
  48.      return 0
  49.    }
  50.  }
  51. }
  52. proc asc {chr} {
  53.  scan $chr %c asc
  54.  return $asc
  55. }
  56. proc chr {asc} { return [format %c $asc] }
  57. proc hex {decimal} { return [format %x $decimal] }
  58. proc decimal {hex} { return [expr 0x$hex] }
  59. proc dehex {string} {
  60.  regsub -all {^\{|\}$} $string "" string
  61.  set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} $string {[format %c [decimal \1]]}]]
  62.  set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} $string {[format %c [decimal \1]]}]]
  63.  set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  64.  set string [string map {&quot; \" &middot; ยท &amp; & <b> \002 </b> \002} $string]
  65.  return $string
  66. }
  67. proc urlencode {string} {
  68.  regsub -all {^\{|\}$} $string "" string
  69.  return [subst [regsub -nocase -all {([^a-z0-9])} $string {%[format %x [scan "\\&" %c]]}]]
  70. }
  71. proc googleweb {nick host hand chan args} { google $nick $host $hand $chan "web" [urlencode $args] }
  72. proc googlelocal {nick host hand chan args} { google $nick $host $hand $chan "local" [urlencode $args] }
  73. proc googlevideo {nick host hand chan args} { google $nick $host $hand $chan "video" [urlencode $args] }
  74. proc googlenews {nick host hand chan args} { google $nick $host $hand $chan "news" [urlencode $args] }
  75. proc googlebook {nick host hand chan args} { google $nick $host $hand $chan "books" [urlencode $args] }
  76. proc googleimage {nick host hand chan args} { google $nick $host $hand $chan "images" [urlencode $args] }
  77. proc googlepatent {nick host hand chan args} { google $nick $host $hand $chan "patent" [urlencode $args] }
  78. bind pub - ${googlecmdchar}google googleweb
  79. bind pub - ${googlecmdchar}glocal googlelocal
  80. bind pub - ${googlecmdchar}gvideo googlevideo
  81. bind pub - ${googlecmdchar}gnews googlenews
  82. bind pub - ${googlecmdchar}gbook googlebook
  83. bind pub - ${googlecmdchar}gimage googleimage
  84. bind pub - ${googlecmdchar}gpatent googlepatent
  85. setudef flag google
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top