Advertisement
Guest User

Untitled

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