Guest User

Untitled

a guest
Dec 25th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #google.tcl v0.31 - Using the "I'm feeling lucky" button this script returns the best result based on the string you input. Also can return image and regional results. This script is future proof. (Default public commands are !google, !image and !googleuk).
  2. #based on scripts by aNa|0Gue
  3.  
  4. set google(ver) "0.31"
  5.  
  6. #Simulate a browser, ie: Mozilla
  7. set google(agent) "MSIE 6.0"
  8.  
  9. #google search trigger
  10. set google(g_cmd) "!google"
  11.  
  12. #google uk search trigger
  13. set google(guk_cmd) "!googleuk"
  14.  
  15. #google image search trigger
  16. set google(gi_cmd) "!image"
  17.  
  18. #google prefix
  19. set google(prefix) "* Google:"
  20.  
  21. package require http
  22.  
  23. bind pub - $google(g_cmd) pub:google
  24. bind pub - $google(guk_cmd) pub:googleuk
  25. bind pub - $google(gi_cmd) pub:image
  26.  
  27. proc google:go { url arg } {
  28. global google
  29. regsub -all " " $arg "+" query
  30. set lookup "$url$query"
  31. set token [http::config -useragent $google(agent)]
  32. set token [http::geturl $lookup]
  33. puts stderr ""
  34. upvar #0 $token state
  35. set max 0
  36. foreach {name value} $state(meta) {
  37. if {[regexp -nocase ^location$ $name]} {
  38. set newurl [string trim $value]
  39. regsub -all "btnI=&" $url "" url
  40. if {[regexp {imgres} $newurl]} { set newurl "http://[string range $newurl [expr [string first = $newurl]+1] [expr [string first & $newurl]-1]]" }
  41. return "$newurl More: $url$query"
  42. }
  43. }
  44. }
  45.  
  46. proc pub:google { nick uhost handle channel arg } {
  47. global google
  48. if {[llength $arg]==0} { putserv "NOTICE $nick :Usage: $google(g_cmd) <string>" }
  49. set url "http://www.google.com/search?btnI=&q="
  50. set output [google:go $url $arg]
  51. putserv "PRIVMSG $channel :$nick, $google(prefix) $output"
  52. }
  53.  
  54. proc pub:googleuk { nick uhost handle channel arg } {
  55. global google
  56. set arg "$arg&meta=cr%3DcountryUK%7CcountryGB"
  57. if {[llength $arg]==0} { putserv "NOTICE $nick :Usage: $google(guk_cmd) <string>" }
  58. set url "http://www.google.co.uk/search?btnI=&q="
  59. set output [google:go $url $arg]
  60. putserv "PRIVMSG $channel :$nick, $google(prefix) $output"
  61. }
  62.  
  63. proc pub:image { nick uhost handle channel arg } {
  64. global google
  65. if {[llength $arg]==0} { putserv "NOTICE $nick :Usage: $google(gi_cmd) <string>" }
  66. set url "http://images.google.com/images?btnI=&q="
  67. set output [google:go $url $arg]
  68. putserv "PRIVMSG $channel :$nick, $google(prefix) $output"
  69. }
  70.  
  71. putlog "google.tcl $google(ver) loaded"
Advertisement
Add Comment
Please, Sign In to add comment