# google.irc # version 1.0 # by blue-elf # # About: # This addon allows other users in your channel to do a !google # By default, it gives out 5 replies (I'll change that later). I STRONGLY RECOMMEND # YOU ENABLE THIS IF YOU HAVE OPS IN YOUR CHANNEL. Because most channels will kick # for text flooding. Don't say I didn't warn you.. # # # 15 March 2005 # # Ok I updated this!@ Because butane didn't release it the first time. # He forced me to script till 4AM the last time :( # # ADDITION: # - Can now toggle this thing ON/OFF # # 14 March 2005 # # Scripting at 3AM-4AM. I haven't done that in a long time.. # I'll improve this in the next version. # # TO DO LIST: # - Add option to select which channels to enable # - Add option to choose how many results to show # - Maybe language options # # --- begin lame code --- menu channel { menu "&Google" { item "ON" { google("ON"); } item "OFF" { google("OFF"); } } } on public { if ('!google *' iswm $parms) { $googlechan = $target; google( getTokenFrom( tokenize($parms, chr(32)) , 1) ); } } sub google { if ($1 eq "ON" || $1 eq "OFF") { setProperty('google', $1); echo("$active", 'Google search is now ' . getProperty('google') ); return 0; } if ($1 eq "" || getProperty('google') ne "ON") { return; } local('$socket @data $string $end $g'); $end = chr(10) . chr(13); $string = strrep($1, " ", "%20", "&" , "%26", "=" , "%3D"); $string = 'GET /ie?q=' . $string . '&num=5&hl=en&lr=&ie=UTF-8&oe=UTF-8&btnG=Google+Search HTTP/1.1'; $socket = connect("www.google.com", 80); println($socket, $string); println($socket, "Host: www.google.com"); println($socket, "Connection: close"); println($socket, "$end"); @data = readAll($socket); closef($socket); $g = 1000; foreach $string (@data) { if ("**HREF*" iswm $string) { $blah = addTimer(&slowDown, $g, 1, "/msg $googlechan " . nohtml($string) . " " . strURL($string)); $g = $g + 1000; } } } sub slowDown { call($1); } sub nohtml { return replace($1, '<[^>]+>', ''); } sub strURL { local('$s'); foreach $s (split(" ", $1)) { if ('*HREF=*' iswm $s) { return "\c18\u" . getToken( tokenize(getToken( tokenize($s,"=") , 1), '>'), 0) . "\u"; } } } # EOF