Advertisement
Guest User

Quotes.tcl

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