All pastes #268018 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-05 07:39 UTC
rendered paste body
----- validate.tcl -----

set valtrig "!validate"
set valtrig2 "!v"

bind pub - $valtrig pub_validate
bind pub - $valtrig2 pub_validate

proc pub_validate {nick uhost hand chan arg} {
	if {[llength $arg]==0} {
		putserv "privmsg $nick :Usage: !validate <url>" 
	} elseif { [llength $arg] > 2 } {
		putserv "privmsg $nick :Usage: !validate <url>" 
	} else {
		set url $arg
		
		if {[string range $arg 0 3] != "www."} { 
			if {[string range $arg 0 6] != "http://"} { 
				putserv "privmsg $chan :$nick: valid url's must begin with either http:// or www."
				return
			}
		}
		 
		set results [split [exec "/home/tballard/eggdrop/scripts/validate.rb" $url] "\n"]

		if {[llength $results] == 0} {
      set rnd [rand 4]
      
      switch $rnd {
        0 {
          putserv "privmsg $chan :$nick: aye holmes, i aint got nothin for $url. please check the url."
			    return
        }
        1 {
          putserv "privmsg $chan :$nick: hey bitch, check your damn url and then get back to me eh?"
			    return
        }
        2 {
          putserv "privmsg $chan :$nick: well aint this about a bitch. i got nuttin'. check your url."
			    return
        }
        3 {
          putserv "privmsg $chan :$nick: failed to fetch any information for $url, please verify that it is valid."
			    return
        }
        4 {
          putserv "privmsg $chan :$nick: well douche me with dishwater, aint this a turd in the punch bowl... $url returned nothing."
			    return
        }
        default {
          putserv "privmsg $chan :$nick: No results for $url."
			    return
        }
      }
			
		 }
		 
		 foreach line $results {
			regsub -all "<strong>" $line {} line
			regsub -all "<\/strong>" $line {} line
			if {[lsearch -exact [string tolower $line] "not"]!=-1} {
				set errCnt [exec "/home/tballard/eggdrop/scripts/validate_error.rb" $url]
				set cgiEsc [exec "/home/tballard/eggdrop/scripts/cgi_escape.rb" $url]
				append line " \(\002$errCnt errors\002\) - http://validator.w3.org/check?uri=$cgiEsc" 	
			}
			putserv "privmsg $chan :Result for $url: $line"
		 }
	}
}
putlog "VALIDATE DOT TCL LOADED. -ansimation"





--- validate.rb ---

#!/usr/bin/ruby
require 'open-uri'
require 'cgi'
urll = CGI::escape(ARGV[0])

open( "http://validator.w3.org/check?uri=#{ urll }" ) { |html|
    text = html.read
        text.scan /<h2.*?>(.+?)<\/h2>/m do |url|
            puts url
        end
}




--- validate_error.rb ---

#!/usr/bin/ruby
require 'open-uri'
require 'cgi'
url = CGI::escape(ARGV[0])

open( "http://validator.w3.org/check?uri=#{ url }" ) { |html|
    text = html.read
        text.scan /Failed validation, (\d+) error[s]?/m do |url|
            puts url
        end
}