BT.SecureMode.tcl 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################### SECUREMODE 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 securemode:findexcept {chan host} {
  17. global black
  18. set found_it 0
  19. set file [open $black(add_file) "r"]
  20. set w [read -nonewline $file]
  21. close $file
  22. set data [split $w "\n"]
  23. foreach line $data {
  24. set read_chan [lindex [split $line] 0]
  25. set enc_chan [encoding convertfrom utf-8 $read_chan]
  26. if {[string equal -nocase $enc_chan $chan]} {
  27. set read_type [lindex [split $line] 1]
  28. if {[string equal -nocase $read_type "SECUREMODE-EXCEPT"]} {
  29. set read_host [lindex [split $line] 3]
  30. set real_read_host [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $read_host]
  31. if {[string match -nocase $host $real_read_host] || [string match -nocase $real_read_host $host]} {
  32. set found_it 1
  33. }
  34. }
  35. }
  36. }
  37. return $found_it
  38. }
  39. proc securemode:kickremove {nick host hand chan kicked reason} {
  40. global black
  41. set host [getchanhost $kicked $chan]
  42. if {[setting:get $chan securemode]} {
  43. set chanmode [getchanmode $chan]
  44. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  45. if {[info exists black(secure:$chan:allowlist)]} {
  46. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $host]] > -1} {
  47. set position [lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $host]]
  48. set black(secure:$chan:allowlist) [lreplace $black(secure:$chan:allowlist) $position $position]
  49. }
  50. if {[info exists black(secure:$chan:list)]} {
  51. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $kicked]] > -1} {
  52. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $kicked]]
  53. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. proc secured:allowlist:reset {minute hour day month year} {
  61. global black
  62. foreach chan [channels] {
  63. if {[validchan $chan]} {
  64. if {[info exists black(secure:$chan:allowlist)]} {
  65. unset black(secure:$chan:allowlist)
  66. }
  67. }
  68. }
  69. }
  70. proc securemode:timer {} {
  71. global black botnick
  72. set channels ""
  73. set secure_act 0
  74. foreach chan [channels] {
  75. if {[setting:get $chan securemode]} {
  76. lappend channels $chan
  77. if {[onchan $botnick $chan]} {
  78. set chanmode [getchanmode $chan]
  79. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  80. set secure_act 1
  81. }
  82. }
  83. }
  84. }
  85. if {$channels == ""} {
  86. return
  87. }
  88. if {$secure_act == "1"} {
  89. securemode:act $channels 0
  90. }
  91. utimer 30 [list securemode:timer]
  92. }
  93. proc securemode:reply {nick host hand chan mod who} {
  94. global black
  95. if {[setting:get $chan securemode]} {
  96. set getlang [string tolower [setting:get $chan lang]]
  97. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  98. if {[string match "*+D*" $mod]} {
  99. set replace(%chan%) $chan
  100. set text [black:color:set "" $black(say.$getlang.securemode.10)]
  101. set reply [join $text]
  102. putserv "PRIVMSG $chan :[string map [array get replace] $reply]"
  103. }
  104. if {[string match "*-D*" $mod]} {
  105. set replace(%chan%) $chan
  106. set text2 [black:color:set "" $black(say.$getlang.securemode.11)]
  107. set reply2 [join $text2]
  108. putserv "PRIVMSG $chan :[string map [array get replace] $reply2]"
  109. }
  110. }
  111. }
  112. proc securemode:act {channels counter} {
  113. global black
  114. if {$channels == ""} {
  115. return
  116. }
  117. set chan [lindex $channels $counter]
  118. set cc [expr $counter + 1]
  119. if {$chan != ""} {
  120. securemode:raw $chan
  121. } else {
  122. return
  123. }
  124. utimer 5 [list securemode:act $channels $cc]
  125. }
  126. proc securemode:raw {chan} {
  127. global black
  128. putquick "NAMES -d $chan"
  129. set ::securechan $chan
  130. bind RAW - 355 get:nameslist
  131. bind RAW - 366 end:nameslist
  132. }
  133. proc get:nameslist {from keyword arguments} {
  134. global black
  135. set found_it 0
  136. set chan $::securechan
  137. set split_arg [split $arguments ":"]
  138. set names [lindex $split_arg 1]
  139. if {[info exists black(secure:$chan:list)]} {
  140. foreach entry $black(secure:$chan:list) {
  141. if {[lsearch -exact [string tolower [split $names]] [string tolower $entry]] < 0} {
  142. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $entry]]
  143. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  144. if {[info exists black(securecode:$entry:$chan)]} {
  145. unset black(securecode:$entry:$chan)
  146. }
  147. }
  148. }
  149. }
  150. if {[info exists black(secure:$chan:list)]} {
  151. if {[llength $black(secure:$chan:list)] == "0"} {
  152. unset black(secure:$chan:list)
  153. }
  154. }
  155. secure:gethost $names $chan 0
  156. }
  157. proc end:nameslist {from keyword arguments} {
  158. global black
  159. check:if:bind "get:nameslist" "355"
  160. check:if:bind "end:nameslist" "366"
  161. }
  162. proc secure:gethost {names chan counter} {
  163. global black
  164. set name [lindex [split $names] $counter]
  165. set cc [expr $counter + 1]
  166. if {$name != ""} {
  167. securemode:gethost:raw $name $chan
  168. } else {
  169. return
  170. }
  171. utimer 3 [list secure:gethost $names $chan $cc]
  172. }
  173. proc securemode:gethost:raw {name chan} {
  174. global black
  175. putserv "USERHOST :$name"
  176. set ::shchan $chan
  177. set ::shnick $name
  178. bind RAW - 302 get:securemode:host
  179. }
  180. proc get:securemode:host {from keyword arguments} {
  181. global black botnick
  182. set is_allowed 0
  183. set has_access 0
  184. set securemode_activ 0
  185. set hosts [lindex [split $arguments] 1]
  186. set hostname [lindex [split $hosts "="] 1]
  187. regsub {^[-+]} $hostname "" mask
  188. set nick $::shnick
  189. set except_mask "$nick!$mask"
  190. set chan $::shchan
  191. if {[setting:get $chan securemode]} {
  192. set chanmode [getchanmode $chan]
  193. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  194. set securemode_activ 1
  195. }
  196. }
  197. if {$securemode_activ == "0"} {
  198. return
  199. }
  200. set replace(%botnick%) $botnick
  201. set replace(%chan%) $chan
  202. set lang [setting:get $chan lang]
  203. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  204. set getaccess [finduser $except_mask]
  205. if {[matchattr $getaccess $black(exceptflags) $chan]} {
  206. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  207. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  208. } else {
  209. putserv "MODE $chan +v $nick"
  210. }
  211. return
  212. }
  213. if {[securemode:findexcept $chan $except_mask] == "1"} {
  214. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  215. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  216. } else {
  217. putserv "MODE $chan +v $nick"
  218. }
  219. return
  220. }
  221. if {[info exists black(secure:$chan:allowlist)]} {
  222. if {[setting:get $chan strictsecured] == "" || [setting:get $chan strictsecured] == "0"} {
  223. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $mask]] > -1} {
  224. set is_allowed 1
  225. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  226. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  227. } else {
  228. putserv "MODE $chan +v $nick"
  229. }
  230. }
  231. if {$is_allowed == "1"} {
  232. return
  233. }
  234. }
  235. }
  236. if {[info exists black(secure:$chan:list)]} {
  237. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $nick]] < 0} {
  238. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  239. set replace(%msg.1%) $black(securecode:$nick:$chan)
  240. set message "$black(say.$lang.securemode.1)"
  241. set len [llength $message]
  242. set random [expr int(rand()*$len)]
  243. set message [lindex $message $random]
  244. set text [black:color:set "" $message]
  245. set reply [join $text]
  246. set message [string map [array get replace] $reply]
  247. putserv "PRIVMSG $nick :$message"
  248. lappend black(secure:$chan:list) $nick
  249. }
  250. } else {
  251. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  252. set replace(%msg.1%) $black(securecode:$nick:$chan)
  253. set message "$black(say.$lang.securemode.1)"
  254. set len [llength $message]
  255. set random [expr int(rand()*$len)]
  256. set message [lindex $message $random]
  257. set text [black:color:set "" $message]
  258. set reply [join $text]
  259. set message [string map [array get replace] $reply]
  260. putserv "PRIVMSG $nick :$message"
  261. lappend black(secure:$chan:list) $nick
  262. }
  263. check:if:bind "get:securemode:host" "302"
  264. }
  265. ##############
  266. #########################################################################
  267. ## END ##
  268. #########################################################################