BT.Limit.tcl 4.5 KB

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