Advertisement
Guest User

Untitled

a guest
May 26th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. # substitute.tcl -- 1.0
  2. #
  3. # This script provides sed style text subsitution, with full regular
  4. # expression support. Use ".chanset #chan +substitute" to enable the
  5. # script in a channel.
  6. #
  7. # Copyright (c) 2010, Rickard Utgren <rutgren@gmail.com>
  8. #
  9. # Permission to use, copy, modify, and/or distribute this software for any
  10. # purpose with or without fee is hereby granted, provided that the above
  11. # copyright notice and this permission notice appear in all copies.
  12. #
  13. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. #
  21. ###Tags
  22. # Name: substitute
  23. # Author: Pixelz <rutgren@gmail.com>
  24. # License: http://www.opensource.org/licenses/ISC ISC license
  25. # Labels: substitute, substitution, text, sed, regex
  26. # Updated: 02-May-2010
  27. # RCS: $Id: substitute.tcl 22 2011-07-08 18:07:27Z rutgren@gmail.com $
  28. #
  29. ###Usage
  30. # Basic usage
  31. # <nick> Hello, World!
  32. # <nick> s/World/Everyone
  33. # <bot> Nick meant: "Hello, Everyone!"
  34. #
  35. # With : instead of /
  36. # <nick> Hello, World!
  37. # <nick> s:World:Everyone
  38. # <bot> Nick meant: "Hello, Everyone!"
  39. #
  40. # <nick> Hello, World!
  41. # <nick> s/,/
  42. # <bot> Nick meant: "Hello World!"
  43. #
  44. # Substitutions can be stacked indefinately
  45. # <nick> Hello, World!
  46. # <nick> s/l/w/s/o/u
  47. # <bot> Nick meant: "Hewwu, Wurwd!"
  48. #
  49. # You can keep stacking over multiple messages
  50. # <nick> Hello, World!
  51. # <nick> s/World/Everyone
  52. # <bot> Nick meant: "Hello, Everyone!"
  53. # <nick> s/Everyone/Friday
  54. # <bot> Nick meant: "Hello, Friday!"
  55. #
  56. # Regular expression
  57. # <nick> Hello, World!
  58. # <nick> s/[A-Z]/Y
  59. # <bot> Nick meant: "Yello, Yorld!"
  60. #
  61. # More regular expression
  62. # <nick> Hello, World!
  63. # <nick> s/\S/x
  64. # <bot> Nick meant: "xxxxxx xxxxxx"
  65. #
  66. # Metasyntax in action, turning on case insensitive matching:
  67. # <nick> Aaa Bbb
  68. # <nick> s/(?i)a/x/s/(?i)b/y
  69. # <bot> Nick meant: "xxx yyy"
  70. #
  71. # Substitution guru:
  72. # <nick> :p
  73. # <nick> s/:/abc/s/p/defg/s/[ce]/^/s/d/o/s/a/\/s:g:/:s/b/(/s/f/)
  74. # <bot> Nick meant: "\(^o^)/"
  75. #
  76. ###Notes
  77. # Flags (i.e. global, case-insensitive) aren't supported directly in the syntax,
  78. # however Tcl metasyntax can still be used. Expressions default to global/all,
  79. # case-sensitive. Note that it's not possible to turn on or off global matching
  80. # via metasyntax, this is because of a limitation in Tcl.
  81.  
  82. package require Tcl 8.4
  83. package require eggdrop 1.6
  84.  
  85. namespace eval ::substitute {
  86. # minimum time in seconds before spoken lines are allowed to expire
  87. variable dbExpire 600 ;# 10 minutes
  88. setudef flag {substitute}
  89. variable lastLine
  90. }
  91.  
  92. proc ::substitute::pubm_substitute {nick uhost hand chan text} {
  93. variable lastLine
  94. if {![channel get $chan {substitute}]} {
  95. return
  96. } elseif {[string match {s[/:]*[/:]*} $text]} {
  97. if {[info exists lastLine([set lnick [string tolower $nick]],$chan)]} {
  98. set newLine [set last [lindex $lastLine($lnick,$chan) 1]]
  99. foreach {- a b c d} [regexp -all -inline -- {s(?:/([^/]+)/([^/]*)|:([^:]+):([^:]*))} $text] {
  100. if {$a ne {}} {
  101. catch {set newLine [regsub -all -- $a $newLine $b]}
  102. } else {
  103. catch {set newLine [regsub -all -- $c $newLine $d]}
  104. }
  105. }
  106. if {($newLine ne $last) && ([string length $newLine] <= 400)} {
  107. putserv "PRIVMSG $chan :Correction, <$nick> \"$newLine\""
  108. set lastLine($lnick,$chan) [list [clock seconds] $newLine]
  109. return
  110. }
  111. }
  112. } else {
  113. set lastLine([string tolower $nick],$chan) [list [clock seconds] $text]
  114. return
  115. }
  116. return
  117. }
  118.  
  119. proc ::substitute::dbCleanup {args} {
  120. variable lastLine; variable dbExpire
  121. foreach item [array names lastLine] {
  122. if {([clock seconds] - [lindex $lastLine($item) 0]) > $dbExpire} {
  123. unset lastLine($item)
  124. }
  125. }
  126. return
  127. }
  128.  
  129. namespace eval ::substitute {
  130. bind pubm - "*" ::substitute::pubm_substitute
  131. bind time - "?0 * * * *" ::substitute::dbCleanup
  132. putlog "Loaded substitute.tcl v1.0 by Pixelz"
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement