################################################### QUOTE TCL V3.52 BY STIGMATA ####### # # Quote TCL version 3.52, by stigmata # Email: stigmata@hvc.rr.com # IRC: EFNet, [stig] OR [st1gg0r] # Read the README for more information # This script contains the flood protection procedures from the BSeen script. # This script requires alltools.tcl v1.3 (loaded by default) # ################################################### QUOTE TCL V3.52 BY STIGMATA ####### # # ################################################### DEFAULT COMMANDS AND INFO ######### # # Note: The following commands are all public commands, they are available via message # and DCC chat also. With or without the command designation, they will work in # private message. File request commands are not available in DCC chat. # # !quote(s) # ### Displays a random quote or the number specified. # ### Default access: Everyone # # !addquote # ### This adds quotes to the storage file, quotes can contain any type of character. # ### Default access: global/channel +o OR +Q globally. # # !delquote # ### Deletes the quote number specified. # ### Default access: global/channel +o OR +Q globally. # # !selquote # ### Prints out the specified quote number. # ### Default access: Everyone # # !findquote # ### Searches for the word in the storage file, parses the results to a # ### text file, and sends the user the results. # ### Default access: Everyone # # !lastquote # ### Displays the last quote added. # ### Default access: Everyone # # !quotehelp # ### Sends the user the quote help file. # ### Default access: Everyone # # !getquotes # ### Sends the user the quote storage file. # ### Default access: Everyone # # !getscript # ### Sends the user the quote script. # ### Default access: Everyone # # !quotestats # ### Shows how many quotes there are and how big the quote storage file is. # ### Default access: Everyone. # # !quoteversion # ### Displays the quote version and author name. :) # ### Default access: Everyone # ################################################### DEFAULT COMMANDS AND INFO ######### ################################################### SETTINGS ########################## # # Select this to your perferred command prefix, "" is acceptable. set qot(cmd) "!" # # File name of the storage file for added quotes. set qot(file) "quote.txt" # # File name of the backup store file for added quotes. set qot(backup) "quote.txt.bak" # # Access required to read quotes & access help. (Probably don't need # to change this.) set qot(readflag) "-" # # Access required to add quotes, "-" is everyone. Note: If a user has any # of these flags, he/she can add quotes. set qot(addflag) "Qo|o" # # Access required to delete quotes. Note: If a user has any of these flags, # he/she can delete quotes. set qot(delflag) "Qo|m" # # This settings is used for flood protection, in the form x:y. Any queries # beyond x in y seconds is considered a flood and the user is ignored. set qot(flood) 4:15 # # Switch for ignoring flooders if they violate qot(flood) (1=On, 0=Off) set qot(ignore) 1 # # This is used to set the amount of time a flooder is ignored (minutes). This # value is useless if qot(ignore) is set to 0. set qot(ignore_time) 5 # # Access needed to send/recieve quote file. set qot(dccflag) "-|-" # # Access needed to restore the backed up quote file. set qot(mergflag) "Qm|-" # ################################################### SETTINGS ########################## #### BINDINGS ### PUBLIC COMMANDS BINDINGS ## Random quote bindings bind pub $qot(readflag) [string trim $qot(cmd)]quotes qot_random bind pub $qot(readflag) [string trim $qot(cmd)]quote qot_random ## Add quote bindings bind pub $qot(addflag) [string trim $qot(cmd)]addquote qot_addquote ## Delete quote bindings bind pub $qot(delflag) [string trim $qot(cmd)]delquote qot_del ## Select quote bindings bind pub $qot(readflag) [string trim $qot(cmd)]selquote qot_sel ## Search quote bindings bind pub $qot(readflag) [string trim $qot(cmd)]quotefind qot_src bind pub $qot(readflag) [string trim $qot(cmd)]findquote qot_src ## DCC Send (Quote file & Script package) bindings bind pub $qot(dccflag) [string trim $qot(cmd)]getquotes qot_get bind pub $qot(dccflag) [string trim $qot(cmd)]getscript qot_script ## Help bindings bind pub $qot(readflag) [string trim $qot(cmd)]quotehelp qot_help bind pub $qot(readflag) [string trim $qot(cmd)]quotecommands qot_help ## Miscellaneous bindings bind pub $qot(readflag) [string trim $qot(cmd)]quoteversion qot_ver bind pub $qot(readflag) [string trim $qot(cmd)]totalquotes qot_total bind pub $qot(readflag) [string trim $qot(cmd)]quotestats qot_total bind pub $qot(readflag) [string trim $qot(cmd)]lastquote qot_last ### MESSAGE COMMANDS BINDINGS ## Random quote bindings bind msg $qot(readflag) [string trim $qot(cmd)]quote qot_msgrandom bind msg $qot(readflag) [string trim $qot(cmd)]quotes qot_msgrandom bind msg $qot(readflag) quote qot_msgrandom bind msg $qot(readflag) quotes qot_msgrandom ## Add quote bindings bind msg $qot(addflag) [string trim $qot(cmd)]addquote qot_msgadd bind msg $qot(addflag) addquote qot_msgadd ## Delete quote bindings bind msg $qot(delflag) [string trim $qot(cmd)]delquote qot_msgdel bind msg $qot(delflag) delquote qot_msgdel ## Select quote bindings bind msg $qot(readflag) [string trim $qot(cmd)]selquote qot_msgsel bind msg $qot(readflag) selquote qot_msgsel ## Search quote bindings bind msg $qot(readflag) [string trim $qot(cmd)]quotefind qot_msgsrc bind msg $qot(readflag) [string trim $qot(cmd)]findquote qot_msgsrc bind msg $qot(readflag) quotefind qot_msgsrc bind msg $qot(readflag) findquote qot_msgsrc ## DCC Send (Quote file & Script package) bindings bind msg $qot(dccflag) [string trim $qot(cmd)]getquotes qot_msgget bind msg $qot(dccflag) [string trim $qot(cmd)]getscript qot_msgscript bind msg $qot(dccflag) getquotes qot_msgget bind msg $qot(dccflag) getscript qot_msgscript ## Help bindings bind msg $qot(readflag) [string trim $qot(cmd)]quotehelp qot_msghelp bind msg $qot(readflag) [string trim $qot(cmd)]quotecommands qot_msghelp bind msg $qot(readflag) quotehelp qot_msghelp bind msg $qot(readflag) quotecommands qot_msghelp ## Miscellaneous bindings bind msg $qot(readflag) [string trim $qot(cmd)]quoteversion qot_msgver bind msg $qot(readflag) [string trim $qot(cmd)]totalquotes qot_msgtotal bind msg $qot(readflag) [string trim $qot(cmd)]quotestats qot_msgtotal bind msg $qot(readflag) [string trim $qot(cmd)]lastquote qot_msglast bind msg $qot(readflag) quoteversion qot_msgver bind msg $qot(readflag) totalquotes qot_msgtotal bind msg $qot(readflag) quotestats qot_msgtotal bind msg $qot(readflag) lastquote qot_msglast ### DCC COMMANDS BINDINGS ## Random quote bindings bind dcc $qot(readflag) quote qot_dccrandom bind dcc $qot(readflag) quotes qot_dccrandom ## Add quote bindings bind dcc $qot(addflag) addquote qot_dccadd ## Delete quote bindings bind dcc $qot(delflag) delquote qot_dccdel ## Select quote bindings bind dcc $qot(readflag) selquote qot_dccsel ## Miscellaneous bindings bind dcc $qot(readflag) quoteversion qot_dccver bind dcc $qot(readflag) totalquotes qot_dcctotal bind dcc $qot(readflag) quotestats qot_dcctotal bind dcc $qot(readflag) lastquote qot_dcclast bind dcc $qot(mergflag) mergequotes qot_dccmerge ##################################################################### ##### TCL PROCEDURES ################################################ ##### MISC TCL SHIT ################################################# set qot(vershort) "3.52" set qot(script) "scripts/quote_tcl-$qot(vershort).tcl" set qot(package) "scripts/quote_tcl-$qot(vershort).tar.gz" putlog "Quote TCL version $qot(vershort) by stigmata loaded. " proc check_string {text} { regsub -all ">" $text "" text regsub -all "<" $text "" text regsub -all "|" $text "" text regsub -all "&" $text "" text return $text } proc qot_flood_init {} { global qot qot_flood_array ; if {![string match *:* $qot(flood)]} {putcmdlog "Quote TCL: var qot(flood) not set correctly." ; return} set qot(flood_num) [lindex [split $qot(flood) :] 0] ; set qot(flood_time) [lindex [split $qot(flood) :] 1] ; set i [expr $qot(flood_num) - 1] while {$i >= 0} {set qot_flood_array($i) 0 ; incr i -1 ; } } ; qot_flood_init proc qot_flood {nick uhost} { global qot qot_flood_array ; if {$qot(flood_num) == 0} {return 0} ; set i [expr $qot(flood_num) - 1] while {$i >= 1} {set qot_flood_array($i) $qot_flood_array([expr $i - 1]) ; incr i -1} ; set qot_flood_array(0) [unixtime] if {[expr [unixtime] - $qot_flood_array([expr $qot(flood_num) - 1])] <= $qot(flood_time)} {putcmdlog "Quote TCL: Flood detected from $nick. Ignoring for $qot(ignore_time) minutes." ; if {$qot(ignore)} {newignore [maskhost [getchanhost $nick]] Quote-TCL "$nick flooded the quote script." $qot(ignore_time)} ; return 1 } {return 0} } # moretools stuff... reason why they're here is to make the script easier for people to load. from mc.moretools1.2.tcl by MC_8 proc strip:color {ar} { set argument "" if {![string match *\003* $ar]} {return $ar} ; set i -1 ; set length [string length $ar] while {$i < $length} { if {[string index $ar $i] == "\003"} { set wind 1 ; set pos [expr $i+1] while {$wind < 3} { if {[string index $ar $pos] <= 9 && [string index $ar $pos] >= 0} { incr wind 1 ; incr pos 1} {set wind 3 } } if {[string index $ar $pos] == "," && [string index $ar [expr $pos + 1]] <= 9 && [string index $ar [expr $pos + 1]] >= 0} { set wind 1 ; incr pos 1 while {$wind < 3} { if {[string index $ar $pos] <= 9 && [string index $ar $pos] >= 0} { incr wind 1 ; incr pos 1} {set wind 3 } } } if {$i == 0} { set ar [string range $ar $pos end] set length [string length $ar] } { set ar "[string range $ar 0 [expr $i - 1]][string range $ar $pos end]" set length [string length $ar] } set argument "$argument[string index $ar $i]" } {incr i 1} } set argument $ar return $argument } proc strip:bold {ar} { set argument "" if {[string match *\002* $ar]} { set i 0 while {$i <= [string length $ar]} { if {![string match \002 [string index $ar $i]]} { set argument "$argument[string index $ar $i]" } ; incr i 1 } } {set argument $ar} return $argument } proc strip:uline {ar} { set argument "" if {[string match *\037* $ar]} { set i 0 while {$i <= [string length $ar]} { if {![string match \037 [string index $ar $i]]} { set argument "$argument[string index $ar $i]" } ; incr i 1 } } {set argument $ar} return $argument } proc strip:reverse {ar} { set argument "" if {[string match *\026* $ar]} { set i 0 while {$i <= [string length $ar]} { if {![string match \026 [string index $ar $i]]} { set argument "$argument[string index $ar $i]" } ; incr i 1 } } {set argument $ar} return $argument } proc strip:all {ar} { return [strip:reverse [strip:uline [strip:bold [strip:color $ar]]]] } proc bold {} {return \002} proc reverse {} {return \026} proc color {} {return \003} proc underline {} {return \037} #### PUBLIC COMMANDS PROCEDURESS ###################################### proc qot_random {nick uhost hand chan rest} { global qot if {[qot_flood $nick $uhost]} {return 0} if {![file exists $qot(file)]} { putquick "PRIVMSG $chan :Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd if {$rest==""} { set qot_cnt [expr $qot_cnt - 2] set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]]) putquick "PRIVMSG $chan :Quote [bold][expr $qot_cur + 1][bold] of [bold][expr $qot_cnt + 1]:[bold] $qot_sel" } else { if {[string is integer $rest]} { set qot_cnt [expr $qot_cnt - 2] unset qot_list([expr $qot_cnt + 1]) if {![info exists qot_list([expr {$rest} - 1])]} { putquick "PRIVMSG $chan :Error: that quote does not exist" return } else { set qot_sel $qot_list([expr {$rest} - 1]) putquick "PRIVMSG $chan :Quote [bold]$rest[bold] of [bold][expr $qot_cnt + 1]:[bold] $qot_sel" return }}} } proc qot_sel {nick uhost hand chan rest} { global qot if {[qot_flood $nick $uhost]} {return 0} if {![file exists $qot(file)]} { putquick "PRIVMSG $chan :Error: No quotes found--file does not exist" return } set qot_fd [open $qot(file) r] for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] unset qot_list([expr $qot_cnt + 1]) if {![info exists qot_list([expr {$rest} - 1])]} { putquick "PRIVMSG $chan :Error: that quote does not exist" return } else { set qot_sel $qot_list([expr {$rest} - 1]) putquick "PRIVMSG $chan :Quote [bold]$rest[bold] of [bold][expr $qot_cnt + 1][bold]: $qot_sel" return } return } proc qot_src {nick uhost hand chan rest} { global qot set checked [check_string $rest] if {[qot_flood $nick $uhost]} {return 0} set qot_src(file) "results-$nick-$rest.txt" exec grep -i -n "$checked" $qot(file) > $qot_src(file) dccsend $qot_src(file) $nick exec rm -f $qot_src(file) putquick "PRIVMSG $nick :Search performed, writing to a text file and sending it to you." putcmdlog "<<$nick>> !$hand! Searched for a quote in $chan." return } proc qot_addquote {nick uhost hand chan rest} { global qot set stripped [strip:all $rest] set qot_fd [open $qot(file) a+] puts $qot_fd $stripped close $qot_fd putquick "PRIVMSG $chan :Quote has been added to storage file." putcmdlog "<<$nick>> !$hand! Added a quote in $chan." exec cp "$qot(file)" "$qot(backup)" return } proc qot_del {nick uhost hand chan rest} { global qot set delnum $rest set type [lindex $rest 0] set rest [lrange $rest 1 end] if {![file exists $qot(file)]} { putquick "PRIVMSG $chan :Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] if {[string is integer $delnum]} { set qot_fd [open $qot(file) w] for { set i 0 } { $i <= $qot_cnt } { incr i 1 } { if {($qot_list($i) == "") || ($i == [expr $delnum - 1])} { putquick "PRIVMSG $chan :Quote [expr $i + 1] deleted" putcmdlog "<<$nick>> !$hand! Deleted a quote in $chan." continue } else { puts $qot_fd $qot_list($i) } } close $qot_fd } else { if {$type == "num"} { set qot_fd [open $qot(file) w] for { set i 0 } { $i <= $qot_cnt } { incr i 1 } { if {($qot_list($i) == "") || ($i == [expr $rest - 1])} { putquick "PRIVMSG $chan :Quote [expr $i + 1] deleted" putcmdlog "<<$nick>> !$hand! Deleted a quote in $chan." continue } else { puts $qot_fd $qot_list($i) } } close $qot_fd } return }} proc qot_get {nick uhost hand chan args} { global qot if {[qot_flood $nick $uhost]} {return 0} putcmdlog "<<$nick>> !$hand! Requested the quote storage file in $chan" putquick "NOTICE $nick :Sending the quote storage file." dccsend $qot(file) $nick return } proc qot_script {nick uhost hand chan args} { global qot if {[qot_flood $nick $uhost]} {return 0} putcmdlog "<<$nick>> !$hand! Requested the quote script package in $chan" putquick "NOTICE $nick :Sending the quote_tcl-$qot(vershort).tar.gz package." dccsend $qot(package) $nick return } proc qot_help {nick uhost hand chan rest} { global qot set qot(helpfile) "quote_help.txt" if {[qot_flood $nick $uhost]} {return 0} putquick "NOTICE $nick :Sending the Quote TCL Help file." dccsend $qot(helpfile) $nick return } proc qot_total {nick uhost hand chan rest} { global qot if {[qot_flood $nick $uhost]} {return 0} set qot(byte_size) [file size $qot(file)] set qot(kb_size) [expr $qot(byte_size) / 1024] if {![file exists $qot(file)]} { putchan $chan "Error: No quotes found--file does not exist" return } else { set qot(cnt) [exec grep -c "" $qot(file)] putquick "PRIVMSG $chan :[bold]$qot(cnt)[bold] quotes total using [bold]$qot(kb_size)kb[bold]." }} proc qot_ver {nick uhost hand chan rest} { global qot if {[qot_flood $nick $uhost]} {return 0} putquick "PRIVMSG $chan :Quote TCL[bold] v$qot(vershort)[bold] by stigmata.[bold]" } proc qot_last {nick uhost hand chan arg} { global qot if {[qot_flood $nick $uhost]} {return 0} if {![file exists $qot(file)]} { putchan $chan "Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] set qot(last) $qot_list([expr $qot_cnt]) putquick "PRIVMSG $chan :[bold]Last Quote ([expr $qot_cnt + 1]):[bold] $qot(last)" return } #### MESSAGE COMMANDS PROCEDURES ##### proc qot_msgrandom {nick uhost hand rest} { global qot if {[qot_flood $nick $uhost]} {return 0} if {![file exists $qot(file)]} { putquick "PRIVMSG $nick :Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd if {$rest==""} { set qot_cnt [expr $qot_cnt - 2] set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]]) putquick "PRIVMSG $nick :Quote [bold][expr $qot_cur + 1][bold] of [bold][expr $qot_cnt + 1]:[bold] $qot_sel" } else { if {[string is integer $rest]} { set qot_cnt [expr $qot_cnt - 2] unset qot_list([expr $qot_cnt + 1]) if {![info exists qot_list([expr {$rest} - 1])]} { putquick "PRIVMSG $nick :Error: that quote does not exist" return } else { set qot_sel $qot_list([expr {$rest} - 1]) putquick "PRIVMSG $nick :Quote [bold]$rest[bold] of [bold][expr $qot_cnt + 1]:[bold] $qot_sel" return }}} } proc qot_msgsel {nick uhost hand rest} { global qot if {[qot_flood $nick $uhost]} {return 0} if {![file exists $qot(file)]} { putquick "PRIVMSG $nick :Error: No quotes found--file does not exist" return } set qot_fd [open $qot(file) r] for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] unset qot_list([expr $qot_cnt + 1]) if {![info exists qot_list([expr {$rest} - 1])]} { putquick "PRIVMSG $nick :Error: that quote does not exist" return } else { set qot_sel $qot_list([expr {$rest} - 1]) putquick "PRIVMSG $nick :Quote [bold]$rest[bold of [bold][expr $qot_cnt + 1][bold]: $qot_sel" return } return } proc qot_msgsrc {nick uhost hand arg} { global qot set checked [check_string $arg] if {[qot_flood $nick $uhost]} {return 0} set qot_src(file) "results-$nick-$arg.txt" exec grep -i -n "$checked" $qot(file) > $qot_src(file) if {![file exists $qot_src(file)]} { putquick "PRIVMSG $nick :Error, no quotes found. Please try again." } dccsend $qot_src(file) $nick exec rm -f $qot_src(file) putquick "PRIVMSG $nick :Search performed, writing to a text file and sending it to you." putcmdlog "<<$nick>> !$hand! Searched for a quote via message." return } proc qot_msgadd {nick uhost hand arg} { global qot set stripped [strip:all $arg] set qot_fd [open $qot(file) a+] puts $qot_fd $stripped close $qot_fd putquick "PRIVMSG $nick :Quote has been added to storage file." putcmdlog "<<$nick>> !$hand! Added a quote via message." exec cp $qot(file) $qot(backup) return } proc qot_msgdel {nick uhost hand rest} { global qot set delnum $rest set type [lindex $rest 0] set rest [lrange $rest 1 end] if {![file exists $qot(file)]} { putquick "PRIVMSG $nick :Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] if {[string is integer $delnum]} { set qot_fd [open $qot(file) w] for { set i 0 } { $i <= $qot_cnt } { incr i 1 } { if {($qot_list($i) == "") || ($i == [expr $delnum - 1])} { putquick "PRIVMSG $nick :Quote [expr $i + 1] deleted" putcmdlog "<<$nick>> !$hand! Deleted a quote via essage." continue } else { puts $qot_fd $qot_list($i) } } close $qot_fd } else { if {$type == "num"} { set qot_fd [open $qot(file) w] for { set i 0 } { $i <= $qot_cnt } { incr i 1 } { if {($qot_list($i) == "") || ($i == [expr $rest - 1])} { putcmdlog "<<$nick>> !$hand! Deleted a quote via message." putquick "PRIVMSG $nick :Quote [expr $i + 1] deleted" continue } else { puts $qot_fd $qot_list($i) } } close $qot_fd } return }} proc qot_msgget {nick uhost hand arg} { global qot if {[qot_flood $nick $uhost]} {return 0} putcmdlog "<<$nick>> !$hand! Requested the quote storage file via message." putquick "PRIVMSG $nick :Sending the quotes storage file." dccsend $qot(file) $nick return } proc qot_msgscript {nick uhost hand arg} { global qot if {[qot_flood $nick $uhost]} {return 0} putcmdlog "<<$nick>> !$hand! Requested the quote script package via message." putquick "PRIVMSG $nick :Sending the quote_tcl-$qot(vershort).tar.gz package." dccsend $qot(package) $nick return } proc qot_msghelp {nick uhost hand chan rest} { global qot set qot(helpfile) "quote_help.txt" if {[qot_flood $nick $uhost]} {return 0} putcmdlog "<<$nick>> !$hand! Requested the quote help file via message." putquick "PRIVMSG $nick :Sending the Quote TCL Help file." dccsend $qot(helpfile) $nick return } proc qot_msgtotal {nick uhost hand arg} { global qot if {[qot_flood $nick $uhost]} {return 0} set qot(byte_size) [file size $qot(file)] set qot(kb_size) [expr $qot(byte_size) / 1024] if {![file exists $qot(file)]} { putquick "PRIVMSG $nick :Error: No quotes found--file does not exist" return } else { set qot(cnt) [exec grep -c "" $qot(file)] putquick "PRIVMSG $nick :[bold]$qot(cnt)[bold quotes total using [bold]$qot(kb_size)kb[bold]." }} proc qot_msgver {nick uhost hand arg} { global qot if {[qot_flood $nick $uhost]} {return 0} putquick "PRIVMSG $nick :Quote TCL[bold] v$qot(vershort)[bold] by stigmata.[bold]" } proc qot_msglast {nick uhost hand arg} { global qot if {[qot_flood $nick $uhost]} {return 0} if {![file exists $qot(file)]} { putquick "PRIVMSG $nick :Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] set qot(last) $qot_list([expr $qot_cnt]) putquick "PRIVMSG $nick :[bold]Last Quote ([expr $qot_cnt + 1]):[bold] $qot(last)" return } #### DCC COMMANDS PROCEDURES #### proc qot_dccrandom {hand idx rest} { global qot if {![file exists $qot(file)]} { putidx $idx "Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd if {$rest==""} { set qot_cnt [expr $qot_cnt -2] set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]]) putcmdlog "#$hand# quotes" putidx $idx "Quote [bold][expr $qot_cur + 1][bold] of [bold][expr $qot_cnt + 1]:[bold] $qot_sel" } else { if {[string is integer $rest]} { set qot_cnt [expr $qot_cnt - 2] unset qot_list([expr $qot_cnt + 1]) if {![info exists qot_list([expr {$rest} - 1])]} { putidx $idx "Error: that quote does not exist" return } else { set qot_sel $qot_list([expr {$rest} - 1]) putcmdlog "#$hand# quote $rest" putidx $idx "Quote [bold]$rest[bold] of [bold][expr $qot_cnt + 1]:[bold] $qot_sel" return}}} } proc qot_dccadd {hand idx rest} { global qot set stripped [strip:all $rest] putcmdlog "#$hand# addquote $rest" set qot_fd [open $qot(file) a+] puts $qot_fd $stripped close $qot_fd putidx $idx "Quote added to storage file." exec cp $qot(file) $qot(backup) return } proc qot_dccdel {hand idx rest} { global qot set delnum $rest set type [lindex $rest 0] set rest [lrange $rest 1 end] if {![file exists $qot(file)]} { putidx $idx "Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] if {[string is integer $delnum]} { set qot_fd [open $qot(file) w] for { set i 0 } { $i <= $qot_cnt } { incr i 1 } { if {($qot_list($i) == "") || ($i == [expr $delnum - 1])} { putidx $idx "Quote [expr $i + 1] deleted" putcmdlog "#$hand# delquote $rest" continue } else { puts $qot_fd $qot_list($i) } } close $qot_fd } else { if {$type == "num"} { set qot_fd [open $qot(file) w] for { set i 0 } { $i <= $qot_cnt } { incr i 1 } { if {($qot_list($i) == "") || ($i == [expr $rest - 1])} { putcmdlog "#$hand# delquote $rest" putidx $idx "Quote [expr $i + 1] deleted" continue } else { puts $qot_fd $qot_list($i) } } close $qot_fd } return }} proc qot_dccsel {hand idx rest} { global qot if {![file exists $qot(file)]} { putidx $idx "Error: No quotes found--file does not exist" return } set qot_fd [open $qot(file) r] for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] unset qot_list([expr $qot_cnt + 1]) if {![info exists qot_list([expr {$rest} - 1])]} { putidx $idx "Error: that quote does not exist" return } else { set qot_sel $qot_list([expr {$rest} - 1]) putcmdlog "#$hand# selquote $rest" putidx $idx "Quote [bold]$rest[bold] of [bold][expr $qot_cnt + 1][bold]: $qot_sel" return } return } proc qot_dcctotal {hand idx arg} { global qot set qot(byte_size) [file size $qot(file)] set qot(kb_size) [expr $qot(byte_size) / 1024] putcmdlog "#$hand# totalquotes" if {![file exists $qot(file)]} { putidx $idx "Error: No quotes found--file does not exist" return } else { set qot(cnt) [exec grep -c "" $qot(file)] putidx $idx "[bold]$qot(cnt)[bold quotes total using [bold]$qot(kb_size)kb[bold]." }} proc qot_dccver {hand idx arg} { global qot putcmdlog "#$hand# quoteversion" putidx $idx "Quote TCL[bold] v$qot(vershort)[bold] by stigmata.[bold]" } proc qot_dcclast {hand idx arg} { global qot putcmdlog "#$hand# lastquote" if {![file exists $qot(file)]} { putidx $idx "Error: No quotes found--file does not exist" return } else { set qot_fd [open $qot(file) r] } for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } { gets $qot_fd qot_list($qot_cnt) } close $qot_fd set qot_cnt [expr $qot_cnt - 2] set qot(last) $qot_list([expr $qot_cnt]) putidx $idx "[bold]Last Quote ([expr $qot_cnt + 1]):[bold] $qot(last)" return } proc qot_dccmerge {hand idx arg} { global qot putcmdlog "#$hand# mergequotes" exec cp "$qot(backup)" "$qot(file)" putidx $idx "Backup quotes storage file restored successfully." return }