BT.Idle.tcl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ############################# IDLE 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 ##
  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 antidle:process {why type user host nick hand chan chan1} {
  17. global botnick black
  18. set show_user $user
  19. set flag "-|+f"
  20. set handle [nick2hand $user]
  21. if {[matchattr $hand q]} {
  22. blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  23. return
  24. }
  25. if {[matchattr $hand -|q $chan]} {
  26. blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  27. return
  28. }
  29. if {($why == "") && ($type == "0")} {
  30. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "idle"
  31. return
  32. }
  33. if {($why == "") && ($type == "1")} {
  34. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "idle"
  35. return
  36. }
  37. if {($why == "") && ($type == "2")} {
  38. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "idle"
  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. switch [string tolower $why] {
  50. +o {
  51. antidle:set $chan
  52. setting:set $chan +idleop ""
  53. blacktools:tell $nick $host $hand $chan $chan1 idle.11 none
  54. }
  55. -o {
  56. setting:set $chan -idleop ""
  57. blacktools:tell $nick $host $hand $chan $chan1 idle.12 none
  58. antidle:unset $chan
  59. }
  60. -ho {
  61. setting:set $chan -idlehalfop ""
  62. blacktools:tell $nick $host $hand $chan $chan1 idle.26 none
  63. antidle:unset $chan
  64. }
  65. +v {
  66. antidle:set $chan
  67. setting:set $chan +idlevoice ""
  68. blacktools:tell $nick $host $hand $chan $chan1 idle.14 none
  69. }
  70. +ho {
  71. antidle:set $chan
  72. setting:set $chan +idlehalfop ""
  73. blacktools:tell $nick $host $hand $chan $chan1 idle.25 none
  74. }
  75. -v {
  76. setting:set $chan -idlevoice ""
  77. blacktools:tell $nick $host $hand $chan $chan1 idle.15 none
  78. antidle:unset $chan
  79. }
  80. add {
  81. if {$user == ""} {
  82. if {$type == "0"} {
  83. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "idle"
  84. return
  85. }
  86. if {$type == "1"} {
  87. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "idle"
  88. }
  89. return
  90. }
  91. if {[onchan $user $chan]} {
  92. set getuser [nick2hand $user]
  93. if {$getuser != "*"} {
  94. set user $getuser
  95. }
  96. }
  97. if {[validuser $user]} {
  98. chattr $user $flag $chan
  99. blacktools:tell $nick $host $hand $chan $chan1 idle.18 $show_user
  100. } else {
  101. set hosts [getchanhost $user $chan]
  102. set uhost "*!*@[lindex [split $hosts @] 1]"
  103. adduser $user $uhost
  104. chattr $user $flag $chan
  105. blacktools:tell $nick $host $hand $chan $chan1 idle.19 "$show_user $uhost"
  106. }
  107. }
  108. list {
  109. set list [userlist "-|f" $chan]
  110. blacktools:tell $nick $host $hand $chan $chan1 idle.20 "none"
  111. if {$list == ""} {set list "NONE"}
  112. blacktools:tell $nick $host $hand $chan $chan1 idle.21 "$list"
  113. }
  114. del {
  115. if {$user == ""} {
  116. if {$type == "0"} {
  117. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "idle"
  118. return
  119. }
  120. if {$type == "1"} {
  121. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "idle"
  122. }
  123. return
  124. }
  125. if {[onchan $user $chan]} {
  126. set getuser [nick2hand $user]
  127. if {$getuser != "*"} {
  128. set user $getuser
  129. }
  130. }
  131. if {![validuser $user]} {
  132. blacktools:tell $nick $host $hand $chan $chan1 idle.22 "$show_user"
  133. return
  134. }
  135. if {![matchattr $user "-|f" $chan]} {
  136. blacktools:tell $nick $host $hand $chan $chan1 idle.23 "$show_user"
  137. return
  138. }
  139. chattr $user -|-f $chan
  140. blacktools:tell $nick $host $hand $chan $chan1 idle.24 "$show_user"
  141. }
  142. default {
  143. if {$type == "0"} {
  144. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "idle"
  145. return
  146. }
  147. if {$type == "1"} {
  148. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "idle"
  149. }
  150. }
  151. }
  152. }
  153. proc antidle:unset {chan} {
  154. global black
  155. set idle_activ 0
  156. set options {idleop idlevoice idlehalfop}
  157. foreach option $options {
  158. if {[setting:get $chan $option]} {
  159. set idle_activ 1
  160. }
  161. }
  162. if {$idle_activ == "0"} {
  163. if {[info exists black(idle:$chan:timer_start)]} {
  164. unset black(idle:$chan:timer_start)
  165. }
  166. if {[info exists black(idle:counter:$chan)]} {
  167. unset black(idle:counter:$chan)
  168. }
  169. }
  170. }
  171. proc antidle:set {chan} {
  172. global black
  173. set idle_activ 0
  174. set options {idleop idlevoice idlehalfop}
  175. foreach option $options {
  176. if {[setting:get $chan $option]} {
  177. set idle_activ 1
  178. }
  179. }
  180. if {$idle_activ == "0"} {
  181. if {[setting:get $chan idle-scantime] != ""} {
  182. set time [setting:get $chan idle-scantime]
  183. } else {
  184. set time $black(idleinterval)
  185. }
  186. set scan_time [time_return_minute $time]
  187. set black(idle:$chan:timer_start) $scan_time
  188. }
  189. }
  190. proc antidle:module {chans} {
  191. global black
  192. set channels ""
  193. foreach chan $chans {
  194. if {[validchan $chan]} {
  195. if {[info exists black(secure_mode:$chan)]} {continue}
  196. lappend channels $chan
  197. }
  198. }
  199. if {$channels != ""} {
  200. idlewhois $channels 0
  201. }
  202. }
  203. proc idlewhois {channels counter} {
  204. global black botnick
  205. set chan [lindex $channels $counter]
  206. set cc [expr $counter + 1]
  207. if {$chan != ""} {
  208. black:check:idle $chan
  209. utimer 30 [list idlewhois $channels $cc]
  210. } else {
  211. return
  212. }
  213. }
  214. proc black:check:idle {chan} {
  215. global black
  216. set ::idle_chan $chan
  217. foreach user [chanlist $chan] {
  218. set handle [nick2hand $user]
  219. if {[isop $user $chan] || [isvoice $user $chan] || [ishalfop $user $chan]} {
  220. if {![isbotnick $user]} {
  221. putserv "WHOIS $user $user"
  222. }
  223. }
  224. }
  225. bind raw - 317 idleprocespublic
  226. }
  227. proc idleprocespublic {nick int arg} {
  228. global black
  229. set nick [string tolower [lindex [split $arg] 1]]
  230. set handle [nick2hand $nick]
  231. set idler [string tolower [lindex [split $arg] 2]]
  232. set minutesidle [expr $idler / 60]
  233. set chan $::idle_chan
  234. if {[onchan $nick $chan]} {
  235. set idlevoicetime [setting:get $chan idlevoicemax]
  236. if {$idlevoicetime == ""} { set idlevoicetime "$black(idlevoicemax)" }
  237. set idleoptime [setting:get $chan idleopmax]
  238. if {$idleoptime == ""} { set idleoptime "$black(idleopmax)" }
  239. set idlehalfoptime [setting:get $chan idlehalfopmax]
  240. if {$idlehalfoptime == ""} { set idlehalfoptime "$black(idlehalfopmax)" }
  241. set idlevoicetime [time_return_minute $idlevoicetime]
  242. set idleoptime [time_return_minute $idleoptime]
  243. set idlehalfoptime [time_return_minute $idlehalfoptime]
  244. if {![info exists black(voiceonmsg:$nick:$chan)]} {
  245. if {[setting:get $chan idlevoice]} {
  246. if {(![matchattr $handle "-|gf" $chan]) && [isvoice $nick $chan]} {
  247. if {$minutesidle > $idlevoicetime} {
  248. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  249. putserv "PRIVMSG $black(chanserv) :devoice $chan $nick"
  250. } else {
  251. pushmode $chan -v $nick
  252. }
  253. }
  254. }
  255. }
  256. if {[setting:get $chan idleop]} {
  257. if {(![matchattr $handle "-|af" $chan]) && [isop $nick $chan]} {
  258. if {$minutesidle > $idleoptime} {
  259. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  260. putserv "PRIVMSG $black(chanserv) :deop $chan $nick"
  261. } else {
  262. pushmode $chan -o $nick
  263. }
  264. }
  265. }
  266. }
  267. if {[setting:get $chan idlehalfop]} {
  268. if {(![matchattr $handle "-|f" $chan]) && [ishalfop $nick $chan]} {
  269. if {$minutesidle > $idlehalfoptime} {
  270. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  271. return
  272. } else {
  273. pushmode $chan -h $nick
  274. }
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. ##############
  282. #########################################################################
  283. ## END ##
  284. #########################################################################