Guest User

Untitled

a guest
Oct 1st, 2017
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 16.62 KB | None | 0 0
  1. ################################################### QUOTE TCL V3.52-W2D01 BY Way2Death - Original Concept Stigma #######
  2. #
  3. # Quote TCL version 3.52-W2D01, by Way2Death
  4. # This script contains the flood protection procedures from the BSeen script.
  5. # This script requires alltools.tcl v1.3 (loaded by default)
  6. #
  7. ################################################### QUOTE TCL V3.52-W2D01 BY Way2Death - Original Concept Stigma #######
  8. #
  9. #
  10. ################################################### DEFAULT COMMANDS AND INFO #########
  11. #
  12. #
  13. # !quote(s) <num>
  14. # ### Displays a random quote or the number specified.
  15. # ### Default access: Everyone
  16. #
  17. # !addquote <quote>
  18. # ### This adds quotes to the storage file, quotes can contain any type of character.
  19. # ### Default access: global/channel +o OR +Q globally.
  20. #
  21. # !delquote <num>
  22. # ### Deletes the quote number specified.
  23. # ### Default access: global/channel +o OR +Q globally.
  24. #
  25. # !selquote <num>
  26. # ### Prints out the specified quote number.
  27. # ### Default access: Everyone
  28. #
  29. # !findquote <word>
  30. # ### Searches for the word in the storage file, parses the results to a
  31. # ### text file, and sends the user the results.
  32. # ### Default access: Everyone
  33. #
  34. # !lastquote
  35. # ### Displays the last quote added.
  36. # ### Default access: Everyone
  37. #
  38. # !quotehelp
  39. # ### Sends the user the quote help file.
  40. # ### Default access: Everyone
  41. #
  42. # !getquotes
  43. # ### Sends the user the quote storage file.
  44. # ### Default access: Everyone
  45. #
  46. # !getscript
  47. # ### Sends the user the quote script.
  48. # ### Default access: Everyone
  49. #
  50. # !quotestats
  51. # ### Shows how many quotes there are and how big the quote storage file is.
  52. # ### Default access: Everyone.
  53. #
  54. # !quoteversion
  55. # ### Displays the quote version and author name. :)
  56. # ### Default access: Everyone
  57. #
  58. ################################################### DEFAULT COMMANDS AND INFO #########
  59.  
  60.  
  61. ################################################### SETTINGS ##########################
  62. #
  63. # Select this to your perferred command prefix, "" is acceptable.
  64.     set qot(cmd) "!"
  65. #
  66. # File name of the storage file for added quotes.
  67.     set qot(file) "quote.txt"
  68. #
  69. # File name of the backup store file for added quotes.
  70.         set qot(backup) "quote.txt.bak"
  71. #
  72. # Access required to read quotes & access help. (Probably don't need
  73. # to change this.)
  74.     set qot(readflag) "-"
  75. #
  76. # Access required to add quotes, "-" is everyone. Note: If a user has any
  77. # of these flags, he/she can add quotes.
  78.     set qot(addflag) "-"
  79. #
  80. # Access required to delete quotes. Note: If a user has any of these flags,
  81. # he/she can delete quotes.
  82.     set qot(delflag) "-"
  83. #
  84. # This settings is used for flood protection, in the form x:y. Any queries
  85. # beyond x in y seconds is considered a flood and the user is ignored.
  86.     set qot(flood) 4:15
  87. #
  88. # Switch for ignoring flooders if they violate qot(flood) (1=On, 0=Off)
  89.     set qot(ignore) 1
  90. #
  91. # This is used to set the amount of time a flooder is  ignored (minutes). This
  92. # value is useless if qot(ignore) is set to 0.
  93.     set qot(ignore_time) 5
  94. #
  95. # Access needed to send/recieve quote file.
  96.     set qot(dccflag) "-|-"
  97. #
  98. # Access needed to restore the backed up quote file.
  99.     set qot(mergflag) "Qm|-"
  100. #
  101. # Number of quotes to show
  102.     set qot(quoteshow) "3"
  103.  
  104. ################################################### SETTINGS ##########################
  105.  
  106. #### BINDINGS
  107.  
  108. ### PUBLIC COMMANDS BINDINGS
  109. set quotefile quote.txt
  110.  
  111. # 0 = display quotes in channel
  112. # 1 = display quotes via private notice.
  113. set quotevianotice 0
  114.  
  115. bind pub - !quote quote:pub:quote
  116. ## Random quote bindings
  117. bind pub $qot(readflag) [string trim $qot(cmd)]quotes qot_random
  118. bind pub $qot(readflag) [string trim $qot(cmd)]quote qot_random
  119. ## Add quote bindings
  120. bind pub $qot(addflag) [string trim $qot(cmd)]addquote qot_addquote
  121. ## Delete quote bindings
  122. bind pub $qot(delflag) [string trim $qot(cmd)]delquote qot_del
  123. ## Select quote bindings
  124. bind pub $qot(readflag) [string trim $qot(cmd)]selquote qot_sel
  125. ## Search quote bindings
  126. bind pub $qot(readflag) [string trim $qot(cmd)]quotefind qot_src
  127. bind pub $qot(readflag) [string trim $qot(cmd)]findquote qot_src
  128. ## Help bindings
  129. bind pub $qot(readflag) [string trim $qot(cmd)]quotehelp qot_help
  130. bind pub $qot(readflag) [string trim $qot(cmd)]quotecommands qot_help
  131. ## Miscellaneous bindings
  132. bind pub $qot(readflag) [string trim $qot(cmd)]quoteversion qot_ver
  133. bind pub $qot(readflag) [string trim $qot(cmd)]totalquotes qot_total
  134. bind pub $qot(readflag) [string trim $qot(cmd)]quotestats qot_total
  135. bind pub $qot(readflag) [string trim $qot(cmd)]lastquote qot_last
  136.  
  137.  
  138.  
  139. #####################################################################
  140.  
  141. ##### TCL PROCEDURES ################################################
  142.  
  143. ##### MISC TCL SHIT #################################################
  144.  
  145. set qot(vershort) "3.52-W2D01"
  146. set qot(script) "scripts/quote_tcl-$qot(vershort).tcl"
  147. set qot(package) "scripts/quote_tcl-$qot(vershort).tar.gz"
  148. putlog "Quote TCL version $qot(vershort) by Way2Death - Original Concept Stigma loaded."
  149.  
  150. proc check_string {text} {
  151.   regsub -all ">" $text "" text
  152.   regsub -all "<" $text "" text
  153.   regsub -all "|" $text "" text
  154.   regsub -all "&" $text "" text
  155.  
  156.   return $text
  157. }
  158.  
  159. proc qot_flood_init {} {
  160.   global qot qot_flood_array ; if {![string match *:* $qot(flood)]} {putcmdlog "Quote TCL: var qot(flood) not set correctly." ; return}
  161.   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]
  162.   while {$i >= 0} {set qot_flood_array($i) 0 ; incr i -1 ; }
  163. } ; qot_flood_init
  164.  
  165. proc qot_flood {nick uhost} {
  166.   global qot qot_flood_array ; if {$qot(flood_num) == 0} {return 0} ; set i [expr $qot(flood_num) - 1]
  167.   while {$i >= 1} {set qot_flood_array($i) $qot_flood_array([expr $i - 1]) ; incr i -1} ; set qot_flood_array(0) [unixtime]
  168.   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
  169.   } {return 0}
  170. }
  171.  
  172. # 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
  173.  
  174. proc strip:color {ar} {
  175.  set argument ""
  176.  if {![string match *\003* $ar]} {return $ar} ; set i -1 ; set length [string length $ar]
  177.  while {$i < $length} {
  178.   if {[string index $ar $i] == "\003"} {
  179.    set wind 1 ; set pos [expr $i+1]
  180.    while {$wind < 3} {
  181.     if {[string index $ar $pos] <= 9 && [string index $ar $pos] >= 0} {
  182.      incr wind 1 ; incr pos 1} {set wind 3
  183.     }
  184.    }
  185.    if {[string index $ar $pos] == "," && [string index $ar [expr $pos + 1]] <= 9 &&
  186.        [string index $ar [expr $pos + 1]] >= 0} {
  187.     set wind 1 ; incr pos 1
  188.     while {$wind < 3} {
  189.      if {[string index $ar $pos] <= 9 && [string index $ar $pos] >= 0} {
  190.       incr wind 1 ; incr pos 1} {set wind 3
  191.      }
  192.     }
  193.    }
  194.    if {$i == 0} {
  195.     set ar [string range $ar $pos end]
  196.     set length [string length $ar]
  197.    } {
  198.     set ar "[string range $ar 0 [expr $i - 1]][string range $ar $pos end]"
  199.     set length [string length $ar]
  200.    }
  201.    set argument "$argument[string index $ar $i]"
  202.   } {incr i 1}
  203.  }
  204.  set argument $ar
  205.  return $argument
  206. }
  207.  
  208. proc strip:bold {ar} {
  209.  set argument ""
  210.  if {[string match *\002* $ar]} {
  211.   set i 0
  212.   while {$i <= [string length $ar]} {
  213.    if {![string match \002 [string index $ar $i]]} {
  214.     set argument "$argument[string index $ar $i]"
  215.    } ; incr i 1
  216.   }
  217.  } {set argument $ar}
  218.  return $argument
  219. }
  220.  
  221. proc strip:uline {ar} {
  222.  set argument ""
  223.  if {[string match *\037* $ar]} {
  224.   set i 0
  225.   while {$i <= [string length $ar]} {
  226.    if {![string match \037 [string index $ar $i]]} {
  227.     set argument "$argument[string index $ar $i]"
  228.    } ; incr i 1
  229.   }
  230.  } {set argument $ar}
  231.  return $argument
  232. }
  233.  
  234. proc strip:reverse {ar} {
  235.  set argument ""
  236.  if {[string match *\026* $ar]} {
  237.   set i 0
  238.   while {$i <= [string length $ar]} {
  239.    if {![string match \026 [string index $ar $i]]} {
  240.     set argument "$argument[string index $ar $i]"
  241.    } ; incr i 1
  242.   }
  243.  } {set argument $ar}
  244.  return $argument
  245. }
  246.  
  247. proc strip:all {ar} {
  248.  return [strip:reverse [strip:uline [strip:bold [strip:color $ar]]]]
  249. }
  250.  
  251. proc bold {} {return \002}
  252. proc reverse {} {return \026}
  253. proc color {} {return \003}
  254. proc underline {} {return \037}
  255.  
  256. #### PUBLIC COMMANDS PROCEDURESS ######################################
  257.  
  258. proc qot_random {nick uhost hand chan rest} {
  259.     global qot
  260.     if {[qot_flood $nick $uhost]} {return 0}
  261.     if {![file exists $qot(file)]} {
  262.     putquick "PRIVMSG $chan :Error: No quotes found--file does not exist"
  263.     return
  264.     } else {
  265.     set qot_fd [open $qot(file) r]
  266.     }
  267.     for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } {
  268.     gets $qot_fd qot_list($qot_cnt)
  269.     }
  270.     close $qot_fd
  271.     if {$rest==""} {
  272.     set qot_cnt [expr $qot_cnt - 2]
  273.     set qot_sel $qot_list([set qot_cur [rand [expr $qot_cnt + 1]]])
  274.     putquick "PRIVMSG $chan :Quote (4#[bold][expr $qot_cur + 1]/[expr $qot_cnt + 1][bold]1): $qot_sel"
  275.     } else {
  276.     if {[string is integer $rest]} {
  277.     set qot_cnt [expr $qot_cnt - 2]
  278.     unset qot_list([expr $qot_cnt + 1])
  279.     if {![info exists qot_list([expr {$rest} - 1])]} {
  280.         putquick "PRIVMSG $chan :Error: that quote does not exist"
  281.         return
  282.     } else {
  283.     set qot_sel $qot_list([expr {$rest} - 1])
  284.     putquick "PRIVMSG $chan :Quote (4#[bold]$rest/[expr $qot_cnt + 1][bold]1): $qot_sel"
  285.     return }}}
  286. }
  287.  
  288. proc qot_sel {nick uhost hand chan rest} {
  289.     global qot
  290.     if {[qot_flood $nick $uhost]} {return 0}
  291.     if {![file exists $qot(file)]} {
  292.     putquick "PRIVMSG $chan :Error: No quotes found--file does not exist"
  293.     return
  294.     }
  295.     set qot_fd [open $qot(file) r]
  296.     for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } {
  297.     gets $qot_fd qot_list($qot_cnt)
  298.     }
  299.     close $qot_fd
  300.     set qot_cnt [expr $qot_cnt - 2]
  301.     unset qot_list([expr $qot_cnt + 1])
  302.     if {![info exists qot_list([expr {$rest} - 1])]} {
  303.     putquick "PRIVMSG $chan :Error: that quote does not exist"
  304.     return
  305.     } else {
  306.     set qot_sel $qot_list([expr {$rest} - 1])
  307.     putquick "PRIVMSG $chan :Quote [bold]$rest[bold] of [bold][expr $qot_cnt + 1][bold]: $qot_sel"
  308.     return
  309.     }
  310.     return
  311. }
  312.  
  313. proc quote:pub:quotef {nick uhost hand chan arg} {
  314.  global quotefile quotevianotice
  315.  set quotes ""
  316.  if { [file exists $quotefile] } { set file [open $quotefile r]
  317.  } else {
  318.   if { $quotevianotice == 0 } { putmsg $chan "$quotefile does not exist. You'll need to add quotes to the database first by typing \002!addquote <a quote>\002" }
  319.   if { $quotevianotice == 1 } { putnotc $nick "$quotefile does not exist. You'll need to add quotes to the database first by typing \002!addquote <a quote>\002" }
  320.   return 0
  321.  }
  322.  while { ![eof $file] } {
  323.   set quote [gets $file]
  324.   if { $quote != "" } {
  325.    set quotes [linsert $quotes end $quote]
  326.   }
  327.  }
  328.  close $file
  329.  if { $arg != "" } {
  330.   set pattern [string tolower $arg]
  331.   set aquotes ""
  332.   set quote ""
  333.   foreach quote $quotes {
  334.    set lowquote [string tolower $quote]
  335.    if { [string match $pattern $lowquote] } {
  336.     set aquotes [linsert $aquotes end $quote]
  337.    }
  338.    set quotes ""
  339.    set quotes $aquotes
  340.   }
  341.  }
  342.  set row [rand [llength $quotes]]
  343.  if { [expr $row >= 0] && [expr $row < [llength $quotes]] } {
  344.   set quote [lindex $quotes $row]
  345.  }
  346.  if { $quote != "" } {
  347.   if { $quotevianotice == 0 } {
  348.    putmsg $chan "Quote: $quote"
  349.   }
  350.   if { $quotevianotice == 1 } {
  351.    putnotc $nick "$quote"
  352.   }
  353.  }
  354.  return 1
  355. }
  356.  
  357.  
  358. proc qot_src {nick uhost hand chan rest} {
  359. if {$rest == ""} {
  360.     putquick "PRIVMSG $chan :Searching for something does require a word to search for..."
  361.     break
  362. }
  363.     global qot
  364.     set checked [check_string $rest]
  365.     if {[qot_flood $nick $uhost]} {return 0}
  366.     set qot_src(file) "results-$nick-$rest.txt"
  367.     exec grep -i -n "$checked" $qot(file) > $qot_src(file)
  368.      set fp [open $qot_src(file) r]
  369.      set data [read $fp]
  370.      close $fp
  371.     set data [split $data "\n"]
  372.     set total 0
  373.  
  374. set number 0
  375. set totalkeys ""
  376.     foreach line $data {
  377. set i [string first ":" $line]
  378. set key [string range $line 0 [expr $i - 1]]
  379.     set totalkeys "$totalkeys $key"
  380.     }
  381.  
  382.      foreach line $data {
  383. set i [string first ":" $line]
  384. set key [string range $line 0 [expr $i - 1]]
  385. set value [string range $line [expr $i + 1] end]
  386. set numqdata($key) $value
  387.  
  388.  
  389.     if { $line=="" } {
  390.     break
  391.     } else {
  392.     putquick "PRIVMSG $chan :Quote (4#[bold]$key[bold]1): $numqdata($key)"
  393.     set number [expr $number + 1]
  394.  
  395.     if {$number == $qot(quoteshow)} {
  396.     putquick "PRIVMSG $chan :And again all of them: $totalkeys"
  397.     break
  398.     }
  399.  
  400.     }
  401.      }
  402.  
  403.     exec rm -f $qot_src(file)
  404.     putcmdlog "<<$nick>> !$hand! Searched for a quote in $chan."
  405.     return
  406. }
  407.  
  408. proc qot_addquote {nick uhost hand chan rest} {
  409.     global qot
  410.     set stripped [strip:all $rest]
  411.     set qot_fd [open $qot(file) a+]
  412.     puts $qot_fd $stripped
  413.     close $qot_fd
  414.     putquick "PRIVMSG $chan :Quote has been added to storage file."
  415.     putcmdlog "<<$nick>> !$hand! Added a quote in $chan."
  416.     exec cp "$qot(file)" "$qot(backup)"
  417.     return
  418. }
  419.  
  420. proc qot_del {nick uhost hand chan rest} {
  421.  
  422.     if {![isop $nick $chan]} { break }
  423.  
  424.     global qot
  425.     set delnum $rest
  426.     set type [lindex $rest 0]
  427.     set rest [lrange $rest 1 end]
  428.     if {![file exists $qot(file)]} {
  429.     putquick "PRIVMSG $chan :Error: No quotes found--file does not exist"
  430.     return
  431.     } else {
  432.     set qot_fd [open $qot(file) r]
  433.     }
  434.     for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt 1 } {
  435.     gets $qot_fd qot_list($qot_cnt)
  436.     }
  437.     close $qot_fd
  438.     set qot_cnt [expr $qot_cnt - 2]
  439.     if {[string is integer $delnum]} {
  440.         set qot_fd [open $qot(file) w]
  441.         for { set i 0 } { $i <= $qot_cnt } { incr i 1 } {
  442.         if {($qot_list($i) == "") || ($i == [expr $delnum - 1])} {
  443.         putquick "PRIVMSG $chan :Quote [expr $i + 1] deleted"
  444.                 putcmdlog "<<$nick>> !$hand! Deleted a quote in $chan."
  445.         continue                
  446.         } else {
  447.         puts $qot_fd $qot_list($i)
  448.         }
  449.     }
  450.     close $qot_fd
  451.     } else {
  452.     if {$type == "num"} {
  453.     set qot_fd [open $qot(file) w]
  454.     for { set i 0 } { $i <= $qot_cnt } { incr i 1 } {
  455.         if {($qot_list($i) == "") || ($i == [expr $rest - 1])} {
  456.         putquick "PRIVMSG $chan :Quote [expr $i + 1] deleted"
  457.                 putcmdlog "<<$nick>> !$hand! Deleted a quote in $chan."
  458.         continue
  459.         } else {
  460.         puts $qot_fd $qot_list($i)
  461.         }
  462.     }
  463.     close $qot_fd
  464.     }
  465.     return
  466. }}
  467.  
  468. proc qot_get {nick uhost hand chan args} {
  469.     global qot
  470.     if {[qot_flood $nick $uhost]} {return 0}
  471.     putcmdlog "<<$nick>> !$hand! Requested the quote storage file in $chan"
  472.     putquick "NOTICE $nick :Sending the quote storage file."
  473.     return
  474. }
  475.  
  476. proc qot_script {nick uhost hand chan args} {
  477.     global qot
  478.     if {[qot_flood $nick $uhost]} {return 0}
  479.     putcmdlog "<<$nick>> !$hand! Requested the quote script package in $chan"
  480.     putquick "NOTICE $nick :Sending the quote_tcl-$qot(vershort).tar.gz package."
  481.     return
  482. }
  483.  
  484. proc qot_help {nick uhost hand chan rest} {
  485.     global qot
  486.     set qot(helpfile) "quote_help.txt"
  487.     if {[qot_flood $nick $uhost]} {return 0}
  488.     putquick "NOTICE $nick :Sending the Quote TCL Help file."
  489.     return
  490. }
  491.  
  492. proc qot_total {nick uhost hand chan rest} {
  493.     global qot
  494.     if {[qot_flood $nick $uhost]} {return 0}
  495.     set qot(byte_size) [file size $qot(file)]
  496.     set qot(kb_size) [expr $qot(byte_size) / 1024]
  497.     if {![file exists $qot(file)]} {
  498.         putchan $chan "Error: No quotes found--file does not exist"
  499.         return
  500.     } else {
  501.     set qot(cnt) [exec grep -c "" $qot(file)]
  502.     putquick "PRIVMSG $chan :[bold]$qot(cnt)[bold] quotes total using [bold]$qot(kb_size)kb[bold]."
  503. }}
  504.  
  505. proc qot_ver {nick uhost hand chan rest} {
  506.     global qot
  507.     if {[qot_flood $nick $uhost]} {return 0}
  508.     putquick "PRIVMSG $chan :Quote TCL[bold] v$qot(vershort)[bold] by Way2Death.[bold]"
  509. }
  510.  
  511. proc qot_last {nick uhost hand chan arg} {
  512.     global qot
  513.     if {[qot_flood $nick $uhost]} {return 0}
  514.     if {![file exists $qot(file)]} {
  515.         putchan $chan "Error: No quotes found--file does not exist"
  516.         return
  517.     } else {
  518.     set qot_fd [open $qot(file) r]
  519.     }
  520.     for {set qot_cnt 0} { ![eof $qot_fd] } { incr qot_cnt } {
  521.         gets $qot_fd qot_list($qot_cnt)
  522.     }
  523.     close $qot_fd
  524.     set qot_cnt [expr $qot_cnt - 2]    
  525.     set qot(last) $qot_list([expr $qot_cnt])
  526.     putquick "PRIVMSG $chan :[bold]Last Quote ([expr $qot_cnt + 1]):[bold] $qot(last)"
  527.     return
  528. }
Advertisement
Add Comment
Please, Sign In to add comment