// Type '!google search' to get the first result from google. Says result to channel.
// Includes some protection, to limit the number of queries a user can get from you, to avoid abuse. Limit is 1 query/minute. Queries from self are not restricted.
// There is some room for improvement, like fetching images, news, etc... any takers ? ;)
// Uses a slighty modified fetch.vsc from wombat :)
// This software is in the public domain.
// Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, without any conditions or restrictions.
// This software is provided "as is" without express or implied warranty.
// by THeLooX
// http://www.visualscripts.com
Alias google
@l $q = $1
for (@l $i = 1; $i < $listelementcount($1-); $i++)
@l $q = $q+$listindex($i $1-)
endfor
@l $page = $lxfetch(http:\/\/www.google.com/search?q=$q)
-@ $fetchlist
@l $j = $listelementcount($page)
@l $token =
$s)
@l $t = $substr($s $p1 $($p2 - $p1))
@l $url = $strtokl(> $t)
@l $text = $strtokr(> $t)
@ $fresult = $text - $url
break
endif
endfor
if ($i == $j)
TextOut clRed error parsing google page!! please report it to the autor - www.visualscripts.com
endif
EndAlias
Event GoogleSearch -after "% PRIVMSG % :!google"
@l $n = $removebrackets($nick)
@l $chan = $2
halt if ([$4] == [])
if ([$LXT[google]]==[])
@ $LXT[google] = [$n]
@l $g = $google($4-)
say $chan \b[google]\b $g
^timer 60 1 @ $$LXT[google] = $$removefromset($$LXT[google] [$n])
else if (!$isinset([$n] $LXT[google]))
@ $LXT[google] = $addtoset([$n] $LXT[google])
@l $g = $google($4-)
say $chan \b[google]\b $g
^timer 60 1 @ $$LXT[google] = $$removefromset($$LXT[google] [$n])
endif
EndEvent
Event -after "*"
halt if ([$1] != [!google])
halt if ([$2] == [])
@l $chan = $0
@l $g = $google($2-)
say $chan \b[google]\b $g
EndEvent
Alias REMOVEBRACKETS
@l $otext
@l $text = $1-
@l $ltext = $($length($text)+1)
for (@l $i=1;$i<$ltext;$i++)
@l $c = $substr($text $i 1)
if (([$c]==[$char(91)])||([$c]==[$char(93)]))
//@l $c=_
@l $otext = $otext_
else
@l $otext = $otext$c
endif
endfor
@ $fresult=$otext
EndAlias
Alias LXFetch
@ $fetchlist =
fetch $1-
while ([$fetchlist] == [])
yield
endwhile
@ $fresult = $fetchlist
EndAlias
//fetch starts here.. thanks wombat :)
// Saved by ViRC 2.0 at 4/26/2002 19:17:01
// FETCH.vsc (c)2002 by wombat@ing.twinwave.net
//
// Syntax: /fetch [Filter]
//
// Example:
// /fetch MyALIAS http://www.yahoo.com/
// This will fetch the index page of yahoo.com, and pass
// it on to MyALIAS as a list, containing the page line
// by line
//
// The URL can contain a port, but it MUST start with http://
// The port would be written in like this: http://www.somewhere.com:4711/
//
// If you only want lines of the page which contain a
// certain filter word, you can optionally tack a filter
// to the call, like this:
//
// /fetch http://www.shoutcast.com/ href
// This would give you all the lines on the shoutcast
// homepage that contain the word "href" in it, and
// write the output on screen.
//
// In case the connection fails, you'll get an error 500
// back to your alias, in the first line.
Alias FETCH
// Syntax:
// FETCH
// Returns a list with all the received lines
// or "HTTP/1.0 500 errormessage xyz"
@l $param=$1-
@ $fetchcallback=$listindex(0 $param)
@ $fetchfilter=$listindex(2 $param)
// Parse the URL
@l $URL=$listindex(0 $param)
@ $fetchhost=$substr($strtokr(: $URL) 3 1024)
@ $fetchget=/$strtokr(/ $substr($fetchhost 3 1024))
@ $fetchhost=$strtokl(/ $fetchhost)
@ $fetchport=80
if ([$strtokr(: $fetchhost)]!=[])
@ $fetchport=$strtokr(: $fetchhost)
@ $fetchhost=$strtokl(: $fetchhost)
endif
// Empty the receiving buffer
@ $fetchbuffer=
// create socket
@ $FETCHsocket = $new(TSockets)
// set up events
@p $FETCHsocket.OnSessionConnected = FETCHCONNECT
@p $FETCHsocket.OnErrorOccurred = FETCHERROR
@p $FETCHsocket.OnDataAvailable = FETCHINCOMINGDATA
@p $FETCHsocket.OnSessionClosed = FETCHDISCONNECT
@p $FETCHsocket.IPAddr = $fetchhost
@p $FETCHsocket.Port = $fetchport
// connect
$FETCHsocket.SConnect
EndAlias
Alias FETCHCONNECT
// Request the desired file off the server
$FETCHsocket.SendCRLF GET $fetchget HTTP/1.0
$FETCHsocket.SendCRLF Accept: */*
$FETCHsocket.SendCRLF User-Agent: FETCH.vsc for $ver build $build
$FETCHsocket.SendCRLF Host: $fetchhost
$FETCHsocket.SendCRLF Connection: Close
$FETCHsocket.SendCRLF
EndAlias
Alias FETCHERROR
// an error occured - don't do anything
textout > . clBlue bah
$fetchcallback
// Unmap all our variables
-@ $fetchhost
-@ $fetchget
-@ $fetchport
-@ $fetchbuffer
-@ $fetchcallback
EndAlias
Alias FETCHINCOMINGDATA
@ $fetchbuffer=$fetchbuffer$prop($FETCHsocket.text)
EndAlias
Alias FETCHDISCONNECT
// We got disconnected, so we close the socket and parse the collected data
$FETCHsocket.SClose
// Parse the result into a list
@l $resultlist=$null
@l $i=0
if ([$fetchfilter]==[])
while ([$rstrtokl(\L $fetchbuffer)]!=[])
@l $resultlist=$resultlist <$striplinks($strtokl(\L $fetchbuffer))>
@ $fetchbuffer=$strtokr(\L $fetchbuffer)
@l $i=$($i+1)
Yield
endwhile
else
while ([$rstrtokl(\L $fetchbuffer)]!=[])
@l $fetchline=$striplinks($strtokl(\L $fetchbuffer))
if ($strpos($fetchfilter $fetchline)>0)
@l $resultlist=$resultlist <$fetchline>
endif
@ $fetchbuffer=$strtokr(\L $fetchbuffer)
@l $i=$($i+1)
Yield
endwhile
endif
@ $fetchlist = $resultlist
// Unmap all our variables
-@ $fetchhost
-@ $fetchget
-@ $fetchport
-@ $fetchbuffer
-@ $fetchcallback
EndAlias