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.

Url output

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
i
iggy
Voice
Posts: 5
Joined: Tue Apr 27, 2010 6:05 pm

Url output

Post by iggy »

I'm looking for a script that does the following. You type !fighter joachim hansen and the script will go to http://www.sherdog.com/stats/ and insert joachim in the field firstname and hansen in the field lastname and then output the resulting URL.

I'm not sure if this of any help, but this url will redirect to the URL I want to output on irc http://www.sherdog.com/fightfinder.php? ... search=yes

The output I want is this http://www.sherdog.com/fighter/Joachim-Hansen-3177

Is this a tricky script to do? Can somebody do it? or can someone point me to similar looking scripts(I've been looking myself for the past hours) which I can work on?

Hoping for the best, Thanks :)
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

something for you to work on :)

Code: Select all

# Rls: Fighter.tcl v1.0
# Date: 30/04/10
# Coded by: doggo
# Contact: #a.b.inner-sanctum@EFNET
###################################

bind pub - !fighter fight

proc fight {nick uhost hand chan arg} {    
set first  [lindex $arg 0]
set last [lindex $arg 1 end]
if { $last == "" } {
putserv "PRIVMSG $chan :\[Syntax\] !fighter \<FIRST NAME\> \<LASTNAME\>"
return
}
putserv "PRIVMSG $chan :http://www.sherdog.com/fightfinder.php?firstname=$first&lastname=$last&nickname=&search=yes"
}

putlog "fighter #alt.binaries.inner-sanctum"
tested and working, but ill let you figure out how to get the redirected address to display in channel ;)

Code: Select all

[07:51pm] <dogga> !fighter joachim
[07:51pm] <tsara> [Syntax] !fighter <FIRST NAME> <LASTNAME>
[07:52pm] <dogga> !fighter joachim hansen
[07:52pm] <tsara> http://www.sherdog.com/fightfinder.php?firstname=joachim&lastname=hansen&nickname=&search=yes
i
iggy
Voice
Posts: 5
Joined: Tue Apr 27, 2010 6:05 pm

Post by iggy »

Ohh, such beauty! That's how easy it can be done. Thank you very, very much! -- you're the best :-)

Are you willing to also give any hints on how I can output the redirected URL too? :-)

Thanks again, much apreciated!!
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

package require http

bind pub - !fighter fight

proc fight {nick uhost hand chan arg} {
	if {[llength [set s [split $arg]]] != 2} {
		putserv "PRIVMSG $chan :\[Syntax\] !fighter <first-name> <last-name>"
		return 1
	}
	set first  [lindex $s 0]
	set last [lindex $s 1]
	set url "http://www.sherdog.com/fightfinder.php?[http::formatQuery firstname $first lastname $last nickname "" search yes]
	catch {set http [::http::geturl "$url" -timeout 5000]} error
	if {![string match -nocase "::http::*" $error]} {
		putserv "privmsg $chan :[string totitle [string map {"\n" " | "} $error]] ( $url )"
		return 1
	}
	if {![string equal -nocase [::http::status $http] "ok"]} {
		putserv "privmsg $chan :[string totitle [::http::status $http]] ( $url )"
		http::cleanup $http
		return 1
	}
	upvar #0 $http state
	foreach {name value} $state(meta) {
		if {[regexp -nocase ^location$ $name]} {
			set newurl $value
		}
	}
	if {[string match "30*" [::http::ncode $http]] || [info exists newurl]} {
		putserv "privmsg $chan :$newurl"
	} else {
		putserv "privmsg $chan :Nothing found for \"$first $last\""
	}
	http::cleanup $http
}
edit: Using an array would've been nice, but it's not case insensitive, it has no -nocase. Hence the foreach looping through checking against a regular expression in it's place. This should work as expected.
Last edited by speechles on Mon May 03, 2010 5:26 pm, edited 6 times in total.
i
iggy
Voice
Posts: 5
Joined: Tue Apr 27, 2010 6:05 pm

Post by iggy »

This just keeps getting better. But there seems to be an error in your script speechles :(.

It doesnt seem to find the location of the url, so the only output is: Nothing found for \"$first $last\

Ideas? :)

Thanks a bunch, this is perfect, all we need to do is make it workable :)
i
iggy
Voice
Posts: 5
Joined: Tue Apr 27, 2010 6:05 pm

Post by iggy »

Hello. Thank you for the fix, but we're still not on the finish line :p

I think there may be an error in

Code: Select all

set url "http://www.sherdog.com/fightfinder.php?[http::formatQuery firstname $first lastname $last nickname ""
because that didn't work, but your older solution

Code: Select all

set url "http://www.sherdog.com/fightfinder.php?firstname=$first&lastname=$last&nickname=&search=yes"
seemed to partially work. Ideas? :-)

Also, I'm wondering. There are three possible outcomes from a search; direct hit, multiple hits and no hits. Is it possible to separate these three possibilities? You've already separated direct hit.

If your search returns multiple hits, this is the message: We found 2 Fighter(s) matching your search criteria.

If the search return blank, this is the message: Sorry, your search came up with zero records.

Could this be included in the script, so that the bot will output whether there were zero or multiple hits?

Thanks for all your help :-)
Post Reply