<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/17620" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2010-02-27T23:45:37-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/17620</id>

		<entry>
		<author><name><![CDATA[x-y-no]]></name></author>
		<updated>2010-02-27T23:45:37-04:00</updated>

		<published>2010-02-27T23:45:37-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92276#p92276</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92276#p92276"/>
		<title type="html"><![CDATA[google autocomplete]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92276#p92276"><![CDATA[
Somebody in the #eggdrop irc channel last night asked about a google autocomplete script and it seemed to me it would be a fun thing to try and write, so I whipped this out this evening ...<br><br>It seems to work OK, but I suck at tcl so I'm sure there's a lot of things that could be improved.  For one thing, I tried to write the parsing with regex but kept screwing it up so I devolved to string.<br><br>Also, it would be neat to add country codes, i.e. if the user puts ".fr" in the search, change the url to contain "hl=fr" in place of "hl=en".  That one I'm sure I can do - just didn't bother yet.<br><br>Anyway, I'd love some constructive criticism of my code as well as any suggestions for other features.<br><br>(EDIT to add: Obviously, I ripped the HTTP stuff out of scripts by incith and/or speechles - all credit for what I got right belongs there)<br><br>Enjoy!<br><div class="codebox"><p>Code: </p><pre><code># autocomplete v.0.1# usage: !autocomplete &lt;phrase&gt;set AutoCompleteVer 0.1package require httpsetudef flag autocompletenamespace eval autocomplete {    bind pub - !autocomplete ::autocomplete::do_autocomplete    bind pub - !ac ::autocomplete::do_autocomplete    proc do_autocomplete {nick uhost handle channel arg {re 0}} {        if {[lsearch -exact [channel info $channel] "+autocomplete"] != -1} {          set where $channel        } else {          set where $nick        }            # set up http         set baseurl "http://www.google.com/complete/search?hl=en&amp;q="        regsub -all " " $arg "%20" foo        set query $baseurl        append query $foo        set ua "Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.7e"        set http [::http::config -useragent $ua -urlencoding "utf-8"]        # stole this bit from rosc2112 on egghelp forums        # borrowed is a better term, all procs eventually need this error handler.        catch {set http [::http::geturl "$query" -timeout [expr 1000 * 10]]} error        if {[string match -nocase "*couldn't open socket*" $error]} {            dccbroadcast "Socket Error accessing $query"            return        }        if { [::http::status $http] == "timeout" } {            dccbroadcast "Connection has timed out..."             return        }        # CHECK CHECK        upvar #0 $http state        set html [::http::data $http]        ::http::cleanup $http        set data [split $html {[}]        set linecount 0        foreach line $data {            # skip first three lines            incr linecount            if {$linecount &gt; 3} {               set f1 [string first {","} $line]               set f2 [string last {","} $line]               set e1 [expr $f1-1]               set s2 [expr $f1+3]               set e2 [expr $f2-1]                  set foo [string range $line 1 $e1]               set bar [string range $line $s2 $e2]               set b "\002"               set s "  - "               set out $b$foo$b$s$bar               putserv "PRIVMSG $where : $out"            }        }    }}</code></pre></div><br>Sample output:<br><blockquote class="uncited"><div>[21:46] &lt;x-y-no&gt; !autocomplete how can i get my girlfriend<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to shave  - 340,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to sleep with me  - 8,260,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to lose weight  - 944,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to break up with me  - 12,700,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend back  - 28,100,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend in the mood  - 1,470,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to love me again  - 17,600,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend pregnant  - 3,940,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to  - 28,600,000 results<br>[21:46] &lt;@s2k_testing&gt;  how can i get my girlfriend to kiss me  - 2,810,000 results<br></div></blockquote><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=10800">x-y-no</a> — Sat Feb 27, 2010 11:45 pm</p><hr />
]]></content>
	</entry>
	</feed>
