BT.Limit.tcl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ############################# LIMIT TCL #############################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. #########################################################################
  15. proc limit:process {nick host hand chan chan1 why lm type} {
  16. global botnick black
  17. set cmd_status [btcmd:status $chan $hand "limit" 0]
  18. if {$cmd_status == "1"} {
  19. return
  20. }
  21. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  22. return
  23. }
  24. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  25. return
  26. }
  27. if {$why == ""} {
  28. switch $type {
  29. 0 {
  30. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "limit"
  31. }
  32. 1 {
  33. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "limit"
  34. }
  35. 2 {
  36. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "limit"
  37. }
  38. }
  39. return
  40. }
  41. if {![validchan $chan]} {
  42. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  43. return
  44. }
  45. if {![onchan $botnick $chan]} {
  46. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  47. return
  48. }
  49. set usersnum [llength [chanlist $chan]]
  50. switch $why {
  51. on {
  52. set limt [setting:get $chan limit-default]
  53. setting:set $chan +limit ""
  54. blacktools:tell $nick $host $hand $chan $chan1 limit.5 none
  55. if {[regexp {^[0-9]} $limt] && ($limt != "0")} {
  56. putserv "MODE $chan +l [expr $usersnum + $limt]"
  57. } else {
  58. putserv "MODE $chan +l [expr $usersnum + $black(limit:default)]"
  59. setting:set $chan limit-default $black(limit:default)
  60. blacktools:tell $nick $host $hand $chan $chan1 limit.6 $black(limit:default)
  61. }
  62. foreach tmr [timers] {
  63. if {[string match "*limit:timer*" [join [lindex $tmr 1]]]} {
  64. return
  65. }
  66. }
  67. timer 1 limit:timer
  68. }
  69. off {
  70. setting:set $chan -limit ""
  71. blacktools:tell $nick $host $hand $chan $chan1 limit.7 none
  72. putquick "MODE $chan -l"
  73. }
  74. set {
  75. if {![regexp {^[0-9]} $lm]} {
  76. if {$type == "0"} {
  77. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "limit"
  78. }
  79. if {$type == "1"} {
  80. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "limit"
  81. }
  82. return
  83. }
  84. if {$lm < 2} { blacktools:tell $nick $host $hand $chan $chan1 limit.9 none
  85. set lm [expr $lm + 1]
  86. setting:set $chan limit-default 2
  87. putserv "MODE $chan +l [expr $usersnum + $lm]"
  88. blacktools:tell $nick $host $hand $chan $chan1 limit.10 none
  89. return
  90. }
  91. if {$lm > 500} { blacktools:tell $nick $host $hand $chan $chan1 limit.11 none
  92. return
  93. }
  94. setting:set $chan limit-default $lm
  95. blacktools:tell $nick $host $hand $chan $chan1 limit.12 $lm
  96. putserv "MODE $chan +l [expr $usersnum + $lm]"
  97. }
  98. }
  99. }
  100. proc limit:timer {} {
  101. global black
  102. set channels ""
  103. foreach chan [channels] {
  104. if {[setting:get $chan limit]} {
  105. lappend channels $chan
  106. }
  107. }
  108. if {$channels != ""} {
  109. limit:act $channels 0
  110. timer 1 limit:timer
  111. }
  112. }
  113. proc limit:act {channels counter} {
  114. global black
  115. set chan [lindex $channels $counter]
  116. set cc [expr $counter + 1]
  117. if {$chan != ""} {
  118. set usersnum [llength [chanlist $chan]]
  119. set setnum [setting:get $chan limit-default]
  120. set limitcount [expr $usersnum + $setnum]
  121. if {$setnum == "0" || $setnum == ""} { set setnum $black(limit:default) }
  122. if {![botisop $chan]} { return }
  123. set chanmode [getchanmode $chan]
  124. if {[string match "*l*" "$chanmode"]} {
  125. set lim [lindex $chanmode 1]
  126. if {$lim == $limitcount} {
  127. if {[lindex $channels $cc] == ""} {
  128. return
  129. } else {
  130. utimer 5 [list limit:act $channels $cc]
  131. return
  132. }
  133. }
  134. } else { set lim "0" }
  135. if {$usersnum > $lim} { set dif [expr $usersnum - $lim] } else { set dif [expr $lim - $usersnum] }
  136. if {($dif >= $setnum) || ($dif <= $setnum)} {
  137. puthelp "MODE $chan +l $limitcount"
  138. }
  139. }
  140. if {[lindex $channels $cc] == ""} {
  141. return
  142. } else {
  143. utimer 5 [list limit:act $channels $cc]
  144. }
  145. }
  146. ##############
  147. #########################################################################
  148. ## END ##
  149. #########################################################################