Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;##########################################################
- ;# Stand-alone Google link lookup Script
- ;# No HTTP-script needed
- ;###########################################################
- set max_links 1
- set allowed_chans "d2bs"
- set msg_targ 0 ;# 0 = chan, 1 = pv
- set google_trigger "!google"
- set google_host 173.194.66.104
- ;# unquote when used on eggdrop
- bind pub - $google_trigger google
- set link_prefix "\00312G\003\00304o\003\00308o\003\00312g\003\00303l\003\00304e\003\00314:\003 "
- proc shrinkif { string argfront argback } {
- set beg [expr [expr [string length [set argfront [string tolower $argfront]]]] - 1]
- if {[string tolower [string range $string 0 $beg]] == "$argfront"} { set string [string range $string [expr [expr $beg] + 1] end] }
- set end [expr [expr [string length $string]] - [string length [set argback [string tolower $argback]]]]
- if {[string tolower [string range $string $end end]] == "$argback"} {
- set string [string range $string 0 [expr [expr $end] - 1]] }
- ; return $string }
- proc obg_html_descape { content } {
- if {![string match *&* $content]} { return $content }
- set escapes {
- \x20 " \x22 & \x26 ' \x27 – \x2D
- < \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
- ¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6
- § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
- ¬ \xAC ­ \xAD ® \xAE &hibar; \xAF ° \xB0
- ± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
- ¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA
- » \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
- À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4
- Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
- Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE
- Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
- Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \xD8
- Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD
- Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2
- ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
- è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC
- í \xED î \xEE ï \xEF ð \xF0 ñ \xF1
- ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6
- ÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
- ü \xFC ý \xFD þ \xFE ÿ \xFF }
- set content [string map $escapes $content] ;
- set content [string map -nocase [list "\&rsaquo\;" "ø" "\&lsaquo\;" "ï"] $content] ;
- set content [string map [list "\]" "\\\]" "\[" "\\\[" "\$" "\\\$" "\\" "\\\\"] $content] ;
- regsub -all -- {&#([[:digit:]]{1,5});} $content {[format %c [string trimleft "\1" "0"]]} content ;
- regsub -all -- {&#x([[:xdigit:]]{1,4});} $content {[format %c [scan "\1" %x]]} content ;
- regsub -all -- {&#?[[:alnum:]]{2,7};} $content "?" content ;
- set content [subst $content] ;
- return [string map [list "=\" " "=" "\"" ""] $content] }
- proc google { nick host hand chan arg } {
- global max_links google_host link_prefix allowed_chans msg_targ
- set page ""
- if {[string map -nocase [list " $chan " ""] " $allowed_chans "] != " $allowed_chans " || $allowed_chans == "*"} {
- set search [string map [list + %2B] $arg]
- if {$msg_targ == 0} { set msg_trg $chan } else { set msg_trg $nick }
- set zoek [string map [list " " "+"] $search]
- if {[catch { set socket [socket $google_host 80] } error]} { putlog "ERROR opening socket to $google_host; $error." } elseif {[catch {
- puts $socket "GET /search?q=$zoek&hl=en HTTP/1.1"
- puts $socket "User-Agent: Opera/9.80 (X11; Linux i686; U; Linux Mint; en) Presto/2.2.15 Version/10.00"
- puts $socket "Host: $google_host"
- puts $socket "Accept: text/html, text/xml"
- puts $socket "Accept-Language: en-US,en;q=0.9"
- puts $socket "Accept-Charset: iso-8859-1, utf-8"
- puts $socket "Accept-Encoding: deflate"
- puts $socket "Connection: close
- "
- ; flush $socket } error]} { putlog "Write error on writing to $google_host; $error." } else {
- if {[eof $socket] != 1} {
- set page [obg_html_descape [string map -nocase [list \{ "" \} "" \[ "" \] "" \"> \n> < \n< > >\n] [read $socket]]] } }
- catch { close $socket }
- if {[set lindex [lsearch $page */images/icons/onebox/calculator-40.gif*]] != -1} {
- set page [string map [list "<font size=-2>" "" </font> ""] $page]
- set a [lsearch [lrange $page $lindex end] *<b>*]
- lappend a [lsearch [lrange $page $lindex end] *</b>*]
- putserv "PRIVMSG $msg_trg :$link_prefix\002[lrange [lrange $page $lindex end] [expr [expr [lindex $a 0]] +1] [expr [expr [lindex $a 1]] -1]]\002"
- ; } elseif {[set plindex [lsearch [string map -nocase [list ID=IRES id=ires] $page] id=ires*]] != -1} {
- set page [lrange $page $plindex end]
- set res_cnt -1
- while {[set link [lsearch [string map -nocase [list HREF= href=] $page] href=*]] != -1 && [incr res_cnt] < $max_links} {
- set page [string map [list [set link [lindex $page $link]] ""] $page]
- set link [shrinkif $link href= class=]
- if {[string index $link 0] == "/"} { set link http://$google_host$link }
- if {$plindex == "-1"} { set link "no results." }
- ; putserv "PRIVMSG $msg_trg :$link_prefix$link" } } } }
- putlog "Google Link Look Up"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement