# CrazyCat Programming Factory # ___ ____ ____ # / __)___( _ \ ___( ___) # ( (__(___))___/(___))__) # \___) (__) (__) # # http://www.c-p-f.org # ###################################### # # bash.tcl 1.0 # ###################################### # # Get the bash quotes # ###################################### # # COMMANDS # # !bash # : gives you the # quote # !randbash [nb] : # if no nb given, show one random quote # if nb <= limit, show nb random quotes # # REQUIRED # # This TCL need the http package # # VARIABLES # the max number of quotes to show set bash_limit 10 ### DON'T EDIT ABOVE ### bind pub - "!bash" bash:get bind pub - "!randbash" bash:random package require http set bash_url "http://www.bash.org/?quote=" set rand_url "http://www.bash.org/?random" proc uncode {code_text} { regsub -all {<[^>]+>} $code_text "" code_text regsub -all "<" $code_text "<" code_text regsub -all ">" $code_text ">" code_text regsub -all """ $code_text "\"" code_text regsub -all " " $code_text " " code_text regsub -all "{" $code_text "" code_text regsub -all "}" $code_text "" code_text return $code_text } proc bash:get {nick uhost handle chan args} { set queue [lindex $args 0] if {[regsub -all {[^0-9]} $queue ""] != $queue} { putserv "PRIVMSG $chan :Error: $queue is not a good value" return } set get_url [concat $::bash_url$queue] set key [http::geturl $get_url] set line [http::data $key] if {[string first "Quote #$queue does not exist." $line] != -1} { putserv "PRIVMSG $chan :Error: Quote #$queue does not exist." return } putserv "PRIVMSG $chan :\002Quote #$queue asked by $nick\002" set quote [regexp -all -inline {

[^\f\t\v]{1,}

} $line] foreach qt [split $quote "\n"] { set show_quote [uncode $qt] if {$show_quote != ""} { putserv "PRIVMSG $chan :$show_quote" } } putserv "PRIVMSG $chan :\002End of quote\002" } proc bash:random {nick uhost handle chan args} { set qmax $args if {[bash_isnum $qmax]} { if {$qmax > $::bash_limit} { set qmax $::bash_limit } } else { set qmax 1 } set key [http::geturl $::rand_url] set line [http::data $key] set quote [regexp -all -inline {

[^\f\t\v]{1,}

[^\f\t\v]{1,}

} $line] set max 0 putserv "PRIVMSG $chan :\002$qmax random quotes asked by $nick\002" foreach qt [split $quote "\n"] { if {[string first "#" [string tolower $qt]] > 0} { if { $max == $qmax } { break } incr max set e_ref [string first "" [string tolower $qt]] incr e_ref -1 set ref [uncode [string range $qt [string first "#" [string tolower $qt]] $e_ref]] putserv "PRIVMSG $chan :\002-=: Citation $ref :=-\002" set qt [string range $qt [string first "

" $qt] end] } set show_quote [uncode $qt] if {$show_quote != ""} { putserv "PRIVMSG $chan :$show_quote" } } putserv "PRIVMSG $chan :\002End of quote\002" } proc bash_isnum {number} { if {($number != "") && (![regexp \[^0-9\] $number])} { return 1 } else { return 0 } }