Advertisement
Ford

Advanced Google TCL tinyurl edit

Aug 30th, 2012
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 5.55 KB | None | 0 0
  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[gtinyurl [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 gtinyurl {link} {
  57.  set gtinyurlsite tinyurl.com
  58.  set gtinyurlurl /api-create.php?url=${link}
  59.  if {[catch {set gtinyurlsock [socket -async $gtinyurlsite 80]} sockerr]} {
  60.    putlog "$gtinyurlsite $gtinyurlurl $sockerr error"
  61.    return 0
  62.  } else {
  63.    puts $gtinyurlsock "GET $gtinyurlurl HTTP/1.0"
  64.    puts $gtinyurlsock "Host: $gtinyurlsite"
  65.    puts $gtinyurlsock "User-Agent: Opera 9.6"
  66.    puts $gtinyurlsock ""
  67.    flush $gtinyurlsock
  68.    while {![eof $gtinyurlsock]} {
  69.      set gtinyurlvar " [gets $gtinyurlsock] "
  70.      if {[regexp {(http:\/\/.*)} $gtinyurlvar match gtinyurlresult]} {
  71.         close $gtinyurlsock
  72.         return $gtinyurlresult
  73.       }
  74.    }
  75.    close $gtinyurlsock
  76.    return 0
  77.  }
  78. }
  79. proc chr {asc} { return [format %c $asc] }
  80. proc hex {decimal} { return [format %x $decimal] }
  81. proc decimal {hex} { return [expr 0x$hex] }
  82. proc dehex {string} {
  83.  regsub -all {^\{|\}$} $string "" string
  84.  set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} $string {[format %c [decimal \1]]}]]
  85.  set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} $string {[format %c [decimal \1]]}]]
  86.  set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
  87.  set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002} $string]
  88.  return $string
  89. }
  90. proc urlencode {string} {
  91.  regsub -all {^\{|\}$} $string "" string
  92.  return [subst [regsub -nocase -all {([^a-z0-9])} $string {%[format %x [scan "\\&" %c]]}]]
  93. }
  94. proc googleweb {nick host hand chan args} { google $nick $host $hand $chan "web" [urlencode $args] }
  95. proc googlelocal {nick host hand chan args} { google $nick $host $hand $chan "local" [urlencode $args] }
  96. proc googlevideo {nick host hand chan args} { google $nick $host $hand $chan "video" [urlencode $args] }
  97. proc googlenews {nick host hand chan args} { google $nick $host $hand $chan "news" [urlencode $args] }
  98. proc googlebook {nick host hand chan args} { google $nick $host $hand $chan "books" [urlencode $args] }
  99. proc googleimage {nick host hand chan args} { google $nick $host $hand $chan "images" [urlencode $args] }
  100. proc googlepatent {nick host hand chan args} { google $nick $host $hand $chan "patent" [urlencode $args] }
  101. bind pub - ${googlecmdchar}google googleweb
  102. bind pub - ${googlecmdchar}glocal googlelocal
  103. bind pub - ${googlecmdchar}gvideo googlevideo
  104. bind pub - ${googlecmdchar}gnews googlenews
  105. bind pub - ${googlecmdchar}gbook googlebook
  106. bind pub - ${googlecmdchar}gimage googleimage
  107. bind pub - ${googlecmdchar}gpatent googlepatent
  108. setudef flag google
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement