BT.Limit.tcl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 limitpublic {nick host hand chan arg} {
  16. global black lastbind
  17. set why [lindex [split $arg] 0]
  18. set lm [lindex [split $arg] 1]
  19. set type 0
  20. set chan1 "$chan"
  21. if {[regexp {^[&#]} $why] && [matchattr $hand nmo|M $why]} {
  22. set chan "$why"
  23. set why [lindex [split $arg] 1]
  24. set lm [lindex [split $arg] 2]
  25. }
  26. set return [blacktools:mychar $lastbind $hand]
  27. if {$return == "0"} {
  28. return
  29. }
  30. limit:process $nick $host $hand $chan $chan1 $why $lm $type
  31. }
  32. proc limit:process {nick host hand chan chan1 why lm type} {
  33. global botnick black
  34. set cmd_status [btcmd:status $chan $hand "limit" 0]
  35. if {$cmd_status == "1"} {
  36. return
  37. }
  38. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  39. return
  40. }
  41. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  42. return
  43. }
  44. if {$why == ""} {
  45. switch $type {
  46. 0 {
  47. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "limit"
  48. }
  49. 1 {
  50. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "limit"
  51. }
  52. 2 {
  53. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "limit"
  54. }
  55. }
  56. return
  57. }
  58. if {![validchan $chan]} {
  59. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  60. return
  61. }
  62. if {![onchan $botnick $chan]} {
  63. blacktools:tell $nick $host $hand $chan $chan1 gl.notonchan none
  64. return
  65. }
  66. set usersnum [llength [chanlist $chan]]
  67. set setnum [setting:get $chan blacklimit]
  68. switch $why {
  69. on {
  70. set limt [setting:get $chan limit-default]
  71. setting:set $chan +limit ""
  72. blacktools:tell $nick $host $hand $chan $chan1 limit.5 none
  73. if {[regexp {^[0-9]} $limt] && ($limt != "0")} {
  74. putserv "MODE $chan +l [expr $usersnum + $limt]"
  75. } else {
  76. putserv "MODE $chan +l [expr $usersnum + $black(limit:default)]"
  77. setting:set $chan limit-default $black(limit:default)
  78. blacktools:tell $nick $host $hand $chan $chan1 limit.6 none
  79. }
  80. foreach tmr [timers] {
  81. if {[string match "*limit:timer*" [join [lindex $tmr 1]]]} {
  82. return
  83. }
  84. }
  85. timer 1 limit:timer
  86. }
  87. off {
  88. setting:set $chan -limit ""
  89. blacktools:tell $nick $host $hand $chan $chan1 limit.7 none
  90. putquick "MODE $chan -l"
  91. }
  92. set {
  93. if {![regexp {^[0-9]} $lm]} {
  94. if {$type == "0"} {
  95. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "limit"
  96. }
  97. if {$type == "1"} {
  98. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "limit"
  99. }
  100. return
  101. }
  102. if {$lm < 2} { blacktools:tell $nick $host $hand $chan $chan1 limit.9 none
  103. set lm [expr $lm + 1]
  104. setting:set $chan limit-default 2
  105. putserv "MODE $chan +l [expr $usersnum + $lm]"
  106. blacktools:tell $nick $host $hand $chan $chan1 limit.10 none
  107. return
  108. }
  109. if {$lm > 500} { blacktools:tell $nick $host $hand $chan $chan1 limit.11 none
  110. return
  111. }
  112. setting:set $chan limit-default $lm
  113. blacktools:tell $nick $host $hand $chan $chan1 limit.12 $lm
  114. putserv "MODE $chan +l [expr $usersnum + $lm]"
  115. }
  116. }
  117. }
  118. proc limit:timer {} {
  119. global black
  120. set channels ""
  121. foreach chan [channels] {
  122. if {[setting:get $chan limit]} {
  123. lappend channels $chan
  124. }
  125. }
  126. if {$channels != ""} {
  127. limit:act $channels 0
  128. timer 1 limit:timer
  129. }
  130. }
  131. proc limit:act {channels counter} {
  132. global black
  133. set chan [lindex $channels $counter]
  134. set cc [expr $counter + 1]
  135. if {$chan != ""} {
  136. set usersnum [llength [chanlist $chan]]
  137. set setnum [setting:get $chan limit-default]
  138. if {$setnum == "0" || $setnum == ""} { set setnum $black(limit:default) }
  139. if {![botisop $chan]} { return }
  140. set chanmode [getchanmode $chan]
  141. if {[string match "*l*" "$chanmode"]} {
  142. set lim [lindex $chanmode 1]
  143. } else { set lim "0" }
  144. if {$usersnum > $lim} { set dif [expr $usersnum - $lim] } else { set dif [expr $lim - $usersnum] }
  145. if {($dif >= $setnum) || ($dif <= $setnum)} {
  146. puthelp "MODE $chan +l [expr $usersnum + $setnum]"
  147. }
  148. }
  149. if {[lindex $channels $cc] == ""} {
  150. return
  151. } else {
  152. utimer 5 [list limit:act $channels $cc]
  153. }
  154. }
  155. ##############
  156. #########################################################################
  157. ## END ##
  158. #########################################################################