proc quote:pub:quote {nick uhost hand chan arg} {
global quotefile quotevianotice
set quotes ""
if { [file exists $quotefile] } { set file [open $quotefile r]
} else {
if { $quotevianotice == 0 } { putmsg $chan "$quotefile does not exist. You'll need to add quotes to the database first by typing \002!addquote \002" }
if { $quotevianotice == 1 } { putnotc $nick "$quotefile does not exist. You'll need to add quotes to the database first by typing \002!addquote \002" }
return 0
}
while { ![eof $file] } {
set quote [gets $file]
if { $quote != "" } {
set quotes [linsert $quotes end $quote]
}
}
close $file
if { $arg != "" } {
set pattern [string tolower $arg]
set aquotes ""
set quote ""
foreach quote $quotes {
set lowquote [string tolower $quote]
if { [string match $pattern $lowquote] } {
set aquotes [linsert $aquotes end $quote]
}
set quotes ""
set quotes $aquotes
}
}
set row [rand [llength $quotes]]
if { [expr $row >= 0] && [expr $row < [llength $quotes]] } {
set quote [lindex $quotes $row]
}
if { $quote != "" } {
if { $quotevianotice == 0 } {
putmsg $chan " Quote: $quote"
}
if { $quotevianotice == 1 } {
putnotc $nick "$quote"
}
}
return 1
}