# google-soap.tcl by dre at mac dot com, 5-27-07 # This Eggdrop TCL script uses Google's SOAP API to perform searches and # spelling suggestions. Even though the barrier to entry here is rather high, # none of the other eggdrop TCL scripts use the API (they all screen-scrape). # To get this rolling, you need a lot of dependencies. It's all described here: # http://www.tclscripting.com/articles/nov06/article1.html # The list of items you need is as follows: # * The Web Services for Tcl distribution: # -- http://members.cox.net/~gerald.lester/WebServicesForTcl.html # * tdom 0.8.1 (I had to build it from cvs; 0.8.0 isn't good enough) # * tls (I used tls1.5) # * TclLib (I used tcllib-1.9) # * The 'dict' extension for tcl8.4 (I used tclDict-8.5.2) # Follow the instructions on the tclscripting site mentioned above. package require WS::Client package require dict bind dcc - !g gSearch-dcc bind pub - !g gSearch-pub bind pub - !s gSpell-pub # your google API key here. Hope you got one before Dec 2006! set apikey "YourKeyHere" # Get a copy of http://api.google.com/GoogleSearch.wsdl and put it somewhere set WSDLFILE {/home/dre/egg/scripts/GoogleSearch.wsdl} proc gSearch-dcc {handle idx text} { putlog "gSearch-dcc triggered by handle $handle, idx $idx, with text $text" set args [setCommonSearchArgs] dict set args q $text dict set args maxResults 3 set result [::WS::Client::DoCall GoogleSearchService doGoogleSearch $args] if {[dict exists $result return resultElements item]} { foreach item [dict get $result return resultElements item] { putdcc $idx [dict get $item URL] } } else { puthelp "PRIVMSG $channel :no results for $text!" } } proc gSearch-pub {nick userhost handle channel text} { putlog "gSearch-pub triggered by $nick!$userhost, with text $text" set args [setCommonSearchArgs] dict set args q $text dict set args maxResults 2 set result [::WS::Client::DoCall GoogleSearchService doGoogleSearch $args] if {[dict exists $result return resultElements item]} { foreach item [dict get $result return resultElements item] { puthelp "PRIVMSG $channel :[dict get $item URL]" } } else { puthelp "PRIVMSG $channel :no results for $text!" } #putlog $result } proc gSpell-pub {nick userhost handle channel text} { putlog "gSpell-pub triggered by $nick!$userhost, with text $text" global apikey dict set args key ${apikey} dict set args phrase $text set result [::WS::Client::DoCall GoogleSearchService doSpellingSuggestion\ $args] #putlog $result if {[string equal "[dict get $result return]" ""]} { puthelp "PRIVMSG $channel :no suggestions for $text!" } else { puthelp "PRIVMSG $channel :did you mean [dict get $result return]?" } } proc initGsearch {} { global WSDLFILE set fd [open $WSDLFILE r+] set wsdlXML [read $fd] close $fd WS::Client::ParseWsdl $wsdlXML } proc setCommonSearchArgs {} { global apikey dict set args key ${apikey} dict set args start 0 dict set args filter true dict set args restrict {} dict set args safeSearch false dict set args lr {} dict set args ie latin1 dict set args oe latin1 return $args } initGsearch putlog "google-soap by dre^ loaded!"