This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

google script without package http

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

google script without package http

Post by De Kus »

I looked around a bit, but all script I found where using the lib http which functions tend to crash my windrop. I have noticed using egghttp is save for me, so I wonder if there is any based on this one? either way I'd have to do it myself again @_o.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

The only google script i found that actually worked uses

Code: Select all

package require http
I can send it you if you wish tho.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

and thats exakt the kind useless for me, because the package http (avaible under lib/tcl8.4/http2.5) is useless for me, it crachs (more or less randomly. one day it will crash on query xy, next week on yz @_o), dont ask me why... I believe its a problem with cygwin and tcl (but seems noone on windrop.sourceforge.com knows any more, either). I guess I'll have to rewrite it to egghttp myself, I hoped I could spare the work :D.

Code: Select all

# De Kus' google port from http to egghttp
#
# 1.0.0 24.02.2005 rewrote done
#
#	following orignal header:
#
# google.tcl v0.2.1
#
# !google keywords - displays the first related website found from google in the channel
# !image keywords  - displays the first related image found on google in the channel
# !file keywords   - displays the first mirror download link found on filemirrors in the channel
#
# by aNa|0Gue - analogue@glop.org - http://www.glop.org/
#
# 04/17/2002 v0.2.1 useragent fix by FAN

if { ![info exists egghttp(version)] } {
	putlog "Could not verify egghttp.tcl beeing loaded!"
} else {
# close bracet extra documentated

bind pub - !google pub:google:cmd
bind pub - !image pub:image:cmd
#bind pub - !file pub:file:cmd

# with this we avoid using the syncronous gethostbyname with CONNECT in egghttp
dnslookup www.google.de getgoogledns:cb
proc getgoogledns:cb {ip host status} {
	set ::googleip $ip
}

proc pub:google:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan google $arg
	return 1
}

proc pub:image:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan image $arg
	return 1
}

#proc pub:file:cmd {nick uhost hand chan arg} {
#	pub:google $nick $uhost $hand $chan file $arg
#	return 1
#}

proc pub:google {nick uhost handle chan type arg} {
	if {[llength $arg]==0} {
		putserv "PRIVMSG $channel :Baka, baka, baka !!!"
	} else {
		set query "http://$::googleip/search?btnI=&q="
		for { set index 0 } { $index<[llength $arg] } { incr index } {
			set query "$query[lindex $arg $index]"
			if {$index<[llength $arg]-1} then {
				set query "$query+"
			}
		}
		switch $type {
			image	{append query &imgsafe=off}
			file	{return 0}
			default {}
		}
# Note: Useragent must start with Mozilla/ for google
		if { [catch {egghttp:geturl $query "pub:google:cb $nick $chan" -useragent "Mozilla/4.0 (TCL 8.4.7; egghttp 1.1.0; CYGWIN_NT-5.1)"} err] } {
			puthelp "NOTICE $nick :$err"
		}
	}
}
		
proc pub:google:cb {nick chan token} {
	set headers [egghttp:headers $token]
	if {[regexp "Location:(.*)\n" $headers {} newurl]} {
		puthelp "PRIVMSG $chan :[string trim $newurl]"
	} elseif { [string match -nocase "*HTTP/1.? 200 OK*" $headers] } {
		puthelp "NOTICE $nick :No match found"
	} else {
		puthelp "NOTICE $nick :Unknown error while phrasing google output"
	}
}

#proc pub:file { nick uhost handle channel arg } {
# global agent
#	if {[llength $arg]==0} {
#		putserv "PRIVMSG $channel :hey ! tappes un nom de fichier boulet !"
#	} else {
#		set query "http://www.filemirrors.com/find.src?file="
#		set query "$query[lindex $arg 0]"
#    set token [http::config -useragent $agent]
#		if {[catch {set token [http::geturl $query]} sockerr]} {
#			puthelp "NOTICE $nick :$sockerr"
#			puthelp "NOTICE $nick :Try again later, look out the window till then!"
#			return 0
#		}
#		set html  [http::data $token]
#		upvar #0 $token state
#		set max 0
#		set result "[lindex $html 1]"
#		set result [string range $result [expr [string first = $result]+2] [expr [string first > $result]-2]]
#		putserv "PRIVMSG $channel :$result"
#		return 1
#	}
#}

putlog "Google 1.0.0 - LOADED!"

# close bracet from egghttp check
}
Note: !image doesnt work correctly atm., and I haven't rewritten the !file search, since its not google, but filemirror.com :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
L
Longbow
Voice
Posts: 29
Joined: Thu Jan 13, 2005 9:24 am

Post by Longbow »

This doesn't help the original poster but...
Note: !image doesnt work correctly atm., and I haven't rewritten the !file search, since its not google, but filemirror.com :D.

Code: Select all

bind pub - !image pub:image

proc pub:image { nick uhost handle channel arg } {
 global agent
	if {[llength $arg]==0} {
		putserv "NOTICE $nick :You need to enter a image."
	} else {
		set query "http://images.google.de/images?btnI=&q="
		for { set index 0 } { $index<[llength $arg] } { incr index } {
			set query "$query[lindex $arg $index]"
			if {$index<[llength $arg]-1} then {
				set query "$query+"
			}
		}
		append query &imgsafe=off
                set token [http::config -useragent $agent]
		set token [http::geturl $query]
		puts stderr ""
		upvar #0 $token state
		set max 0
		foreach {name value} $state(meta) {
			if {[regexp -nocase ^location$ $name]} {
				set starturl "http://"
				set newurl [string trim $value]
				set newurl [string range $newurl [expr [string first = $newurl]+1] [expr [string first & $newurl]-1]]
				append starturl $newurl
				putserv "PRIVMSG $channel :$arg: $starturl"
			}
		}
	}
}
^^ Thats what i've got for google image.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

no need to copy google-0.2.1.tcl, I already said it is a rewrite from this script as its original (even you maybe nolonger would recognize it, because I nearly rewrote everything).

Code: Select all

# De Kus' google port from http to egghttp
#
# 1.1.1 25.02.2005 fixed remote code execution from $nick
# 1.1.0 25.02.2005 !image rewrote done
# 1.0.1 24.02.2005 changed query string creation
# 1.0.0 24.02.2005 rewrote done
#
#	following orignal header:
#
# google.tcl v0.2.1
#
# !google keywords - displays the first related website found from google in the channel
# !image keywords  - displays the first related image found on google in the channel
# !file keywords   - displays the first mirror download link found on filemirrors in the channel
#
# by aNa|0Gue - analogue@glop.org - http://www.glop.org/
#
# 04/17/2002 v0.2.1 useragent fix by FAN

if { ![info exists egghttp(version)] } {
	putlog "Could not verify egghttp.tcl beeing loaded!"
} else {
# close bracet extra documentated

bind pub - !google pub:google:cmd
bind pub - !image pub:image:cmd
#bind pub - !file pub:file:cmd

# with this we avoid using the syncronous gethostbyname with CONNECT in egghttp
dnslookup www.google.de getgoogledns:cb
proc getgoogledns:cb {ip host status} {
	set ::googleip $ip
}

proc pub:google:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan google $arg
	return 1
}

proc pub:image:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan image $arg
	return 1
}

#proc pub:file:cmd {nick uhost hand chan arg} {
#	pub:google $nick $uhost $hand $chan file $arg
#	return 1
#}

proc pub:google {nick uhost handle chan type arg} {
	if {[llength $arg]==0} {
		putserv "PRIVMSG $channel :Baka, baka, baka !!!"
	} else {
		set query "?btnI=&q=[string map {" " + \" %22 , %2C : %3A ; %3B \t %09 ! %21 # %23 \$ %24 % %25 & %26 ' %27 ( %28 ) %29 = %3D § %C2%A7} $arg]"
		switch $type {
			image	{set query "http://$::googleip/images${query}&imgsafe=off"}
			file	{return 0}
			default {set query "http://$::googleip/search$query"}
		}
# Note: Useragent must start with Mozilla/ for google
		if { [catch {egghttp:geturl $query [split "pub:google:cb $nick $chan $type"] -useragent "Mozilla/4.0 (TCL 8.4.7; egghttp 1.1.0; CYGWIN_NT-5.1)"} err] } {
			puthelp "NOTICE $nick :$err"
		}
	}
}

proc pub:google:cb {nick chan type token} {
	set headers [egghttp:headers $token]
	switch $type {
		image	{
			if { [set found [regexp "imgurl\075(.*)\046imgrefurl" $headers {} newurl]] } {
				set newurl "http://$newurl"
			}
		}
		file	{return 0}
		default {set found [regexp "Location:(.*)\n" $headers {} newurl]}
	}
	if {$found} {
		puthelp "PRIVMSG $chan :[string trim $newurl]"
	} elseif { [string match -nocase "*HTTP/1.? 200 OK*" $headers] } {
		puthelp "NOTICE $nick :No match found"
	} else {
		puthelp "NOTICE $nick :Unknown error while phrasing google output"
	}
}

#proc pub:file { nick uhost handle channel arg } {
# global agent
#	if {[llength $arg]==0} {
#		putserv "PRIVMSG $channel :hey ! tappes un nom de fichier boulet !"
#	} else {
#		set query "http://www.filemirrors.com/find.src?file="
#		set query "$query[lindex $arg 0]"
#    set token [http::config -useragent $agent]
#		if {[catch {set token [http::geturl $query]} sockerr]} {
#			puthelp "NOTICE $nick :$sockerr"
#			puthelp "NOTICE $nick :Try again later, look out the window till then!"
#			return 0
#		}
#		set html  [http::data $token]
#		upvar #0 $token state
#		set max 0
#		set result "[lindex $html 1]"
#		set result [string range $result [expr [string first = $result]+2] [expr [string first > $result]-2]]
#		putserv "PRIVMSG $channel :$result"
#		return 1
#	}
#}

putlog "Google 1.0.0 - LOADED!"

# close bracet from egghttp check
}
Note: I replaced the stupid foreach with a string map expression, which replaces most important special charters. you should be able to search like in google itself, something like

Code: Select all

eggdrop "news & more" -porn
will be absolutly fine.

Things you might want to change:
Line 30: dnslookup ... getgoogledns:cb
Line 61: -useragent "..."

yes, google.de has a sligthly diffrent search result than google.com! maybe you use your local google.whatever to optimize your result :).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

^DooM^ wrote:The only google script i found that actually worked uses

Code: Select all

package require http
I can send it you if you wish tho.

it is not the working but the crashing using http lib crashes the bot .. ive seen it manytimes .. main reason why i never use that package anywhere ..
XplaiN but think of me as stupid
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

how can that googgle script (I also use it) work with filemirror?
That is the only part of the script that does not work.... :|
and how can one show 3 or X google results instead of one?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Code: Select all

# De Kus' google port from http to egghttp
#
# 1.2.1 18.03.2005 regexp for !file rewritten, fixed remote code execution
# 1.2.0 18.03.2005 !file rewrote done
# 1.1.1 25.02.2005 fixed remote code execution from $nick
# 1.1.0 25.02.2005 !image rewrote done
# 1.0.1 24.02.2005 changed query string creation
# 1.0.0 24.02.2005 rewrote done
#
#	following orignal header:
#
# google.tcl v0.2.1
#
# !google keywords - displays the first related website found from google in the channel
# !image keywords  - displays the first related image found on google in the channel
# !file keywords   - displays the first mirror download link found on filemirrors in the channel
#
# by aNa|0Gue - analogue@glop.org - http://www.glop.org/
#
# 04/17/2002 v0.2.1 useragent fix by FAN

if { ![info exists egghttp(version)] } {
	putlog "Could not verify egghttp.tcl beeing loaded! Failed to load google."
} else {
# close bracet extra documentated

bind pub - !google pub:google:cmd
bind pub - !image pub:image:cmd
bind pub - !file pub:file:cmd

# with this we avoid using the syncronous gethostbyname with CONNECT in egghttp
dnslookup www.google.de getgoogledns:cb
dnslookup www.filemirrors.com getfmdns:cb
proc getgoogledns:cb {ip host status} {	set ::googleip $ip }
proc getfmdns:cb {ip host status} {	set ::fmip $ip }

set googleflood 0

proc pub:google:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan google $arg
	return 1
}

proc pub:image:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan image $arg
	return 1
}

proc pub:file:cmd {nick uhost hand chan arg} {
	pub:google $nick $uhost $hand $chan file $arg
	return 1
}

proc pub:google {nick uhost handle chan type arg} {
	global googleflood
	if { $googleflood > 4 } {
		puthelp "NOTICE $nick :Genug gesucht erstmal."
		return 0
	} elseif { $::googleip == "0.0.0.0" || $::fmip == "0.0.0.0" } {
		puthelp "NOTICE $nick :Sorry, I don't have the cached IPs. If this persists DNS lookup is broken. Requesting now..."
		dnslookup www.google.de getgoogledns:cb
		dnslookup www.filemirrors.com getfmdns:cb
		return 0
	}
	incr googleflood
	timer 5 [list incr googleflood -1]
	if {[llength [split $arg]]==0} {
		putserv "PRIVMSG $channel :Baka, baka, baka !!!"
	} else {
		set query [string map {" " + \" %22 , %2C : %3A ; %3B \t %09 ! %21 # %23 \$ %24 % %25 & %26 ' %27 ( %28 ) %29 = %3D § %C2%A7} $arg]
		switch $type {
			image	{set query "http://$::googleip/images?btnI=&q=${query}&imgsafe=off"}
			file	{set query "http://$::fmip/find.src?file=$query"}
			default {set query "http://$::googleip/search?btnI=&q=$query"}
		}
# Note: Useragent must start with Mozilla/ for google
		if { [catch {egghttp:geturl $query [split "pub:google:cb $nick $chan $type"] -useragent "Mozilla/4.0 (TCL 8.4.7; egghttp $::egghttp(version); de-DE; OpenBSD 3.4)"} err] } {
			puthelp "NOTICE $nick :$err"
		}
	}
}

proc pub:google:cb {nick chan type token} {
	set headers [egghttp:headers $token]
	switch $type {
		image	{
			if { [set found [regexp "imgurl\075(.*)\046imgrefurl" $headers {} newurl]] } {
				set newurl "http://$newurl"
			}
		}
		file		{set found [regexp {(?n)<a href=\"(.*)\">} [egghttp:data $token] {} newurl]}
		default	{set found [regexp "Location:(.*)\n" $headers {} newurl]}
	}
	if {$found} {
		puthelp "PRIVMSG $chan :[string trim [string map {%25 %} $newurl]]"
	} elseif { [string match -nocase "*HTTP/1.? 200 OK*" $headers] || $type == "file" && [string match -nocase "*not found" [egghttp:data $token]] } {
		puthelp "NOTICE $nick :No match found"
	} else {
		puthelp "NOTICE $nick :Unspecified error while phrasing webserver output."
	}
}

putlog "Google 1.2.2 - LOADED!"

# close bracet from egghttp check
}
This should do for filemirror, but still everything in "single output". I am not absolutly sure about the url part string length, currently filename must shorter than 40 chars (included %xx codes) and hostname shorter than 50 chars. extension must be 1-5 chars. why? Because regexp tends to catch the widest string avaible, which could more be than 1 line in case of multimatchs (at least it did once for me :D).

for multiline you would have to rewrite a lot. Feel free to change it, I won't that soon :D.
For xgoogle goes the same, I don't need xgoogle, but I am sure, it could be easily integreated ^-^.

PS: I am running that script with a "sligthly" changed/enhanced egghttp.tcl, but it should not matter, but there is no guarantee for that ;).
Last edited by De Kus on Sun Apr 24, 2005 6:05 pm, edited 2 times in total.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
Thunderdome
Op
Posts: 187
Joined: Tue Mar 15, 2005 4:42 pm

Post by Thunderdome »

ftp://ftp.nero.com/Nero-6.6.0.8a.exe">N ... exe</a><br>

for example... is the result for the search of Nero-6.6.0.8a.exe!
so something must be wrong... but it works... :)
Anyway, why can't one search just "nero"? if one does that no results are shown... do I need to use the full name to search it?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

stupid regex, the gimmi a headache. but finally I know how to corectly prevent multiline matching, so the best regexp is:

regexp {(?n)<a href=\"(.*)\">} [egghttp:data $token] {} newurl

filemirror is intended to be used for searching an alternitive server (so Ill probably add a feature to get something else than mirror #1) and not a file search. for a file search your are better with !google :).

PS: I replaced the code above, better copy completly, because I added a [split ] to where llengeth is used.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
cambodia
Halfop
Posts: 73
Joined: Sun Aug 22, 2004 1:03 am
Location: cambodia

Post by cambodia »

yeah better copy all and change it or you can make as tcl release for everybody to use , i interesting in this tcl too :lol:
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

cambodia wrote:yeah better copy all and change it or you can make as tcl release for everybody to use , i interesting in this tcl too :lol:
Posted: Today at 3:19 am Reply with quoteEdit/Delete this postBack to top
stupid regex, ...
Last edited by De Kus on Fri Mar 18, 2005 3:20 am; edited 1 time in total
maybe I have already updated the previous post?!
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
N
NTHosts
Op
Posts: 100
Joined: Mon Oct 10, 2005 9:57 pm
Location: UK
Contact:

ummm

Post by NTHosts »

Hi, just tried to use this script but keep getting this error on rehash :-(

[06:25] Could not verify egghttp.tcl beeing loaded! Failed to load google.

any ideas ? :(
www.NT-Hosts.Net - More than just a host
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

load egghttp before google?! :P
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
N
NTHosts
Op
Posts: 100
Joined: Mon Oct 10, 2005 9:57 pm
Location: UK
Contact:

...

Post by NTHosts »

DOH !!

/me slaps his forehead :P
www.NT-Hosts.Net - More than just a host
Post Reply