BT.SecureMode.tcl 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. if {![info exists black(secure_mode:$chan)]} {
  82. set black(secure_mode:$chan) 1
  83. }
  84. } else {
  85. if {[info exists black(secure_mode:$chan)]} {
  86. unset black(secure_mode:$chan)
  87. }
  88. }
  89. }
  90. }
  91. }
  92. if {$channels == ""} {
  93. return
  94. }
  95. if {$secure_act == "1"} {
  96. securemode:act $channels 0
  97. }
  98. utimer 30 [list securemode:timer]
  99. }
  100. proc securemode:reply {nick host hand chan mod who} {
  101. global black
  102. if {[setting:get $chan securemode]} {
  103. set getlang [string tolower [setting:get $chan lang]]
  104. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  105. if {[string match "*+D*" $mod]} {
  106. set replace(%chan%) $chan
  107. set text [black:color:set "" $black(say.$getlang.securemode.10)]
  108. set reply [join $text]
  109. putserv "PRIVMSG $chan :[string map [array get replace] $reply]"
  110. }
  111. if {[string match "*-D*" $mod]} {
  112. set replace(%chan%) $chan
  113. set text2 [black:color:set "" $black(say.$getlang.securemode.11)]
  114. set reply2 [join $text2]
  115. putserv "PRIVMSG $chan :[string map [array get replace] $reply2]"
  116. }
  117. }
  118. }
  119. proc securemode:act {channels counter} {
  120. global black
  121. if {$channels == ""} {
  122. return
  123. }
  124. set chan [lindex $channels $counter]
  125. set cc [expr $counter + 1]
  126. if {$chan != ""} {
  127. securemode:raw $chan
  128. } else {
  129. return
  130. }
  131. utimer 5 [list securemode:act $channels $cc]
  132. }
  133. proc securemode:raw {chan} {
  134. global black
  135. putquick "NAMES -d $chan"
  136. set ::securechan $chan
  137. bind RAW - 355 get:nameslist
  138. bind RAW - 366 end:nameslist
  139. }
  140. proc get:nameslist {from keyword arguments} {
  141. global black
  142. set found_it 0
  143. set chan $::securechan
  144. set split_arg [split $arguments ":"]
  145. set names [lindex $split_arg 1]
  146. if {[info exists black(secure:$chan:list)]} {
  147. foreach entry $black(secure:$chan:list) {
  148. if {[lsearch -exact [string tolower [split $names]] [string tolower $entry]] < 0} {
  149. set position [lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $entry]]
  150. set black(secure:$chan:list) [lreplace $black(secure:$chan:list) $position $position]
  151. if {[info exists black(securecode:$entry:$chan)]} {
  152. unset black(securecode:$entry:$chan)
  153. }
  154. }
  155. }
  156. }
  157. if {[info exists black(secure:$chan:list)]} {
  158. if {[llength $black(secure:$chan:list)] == "0"} {
  159. unset black(secure:$chan:list)
  160. }
  161. }
  162. secure:gethost $names $chan 0
  163. }
  164. proc end:nameslist {from keyword arguments} {
  165. global black
  166. check:if:bind "get:nameslist" "355"
  167. check:if:bind "end:nameslist" "366"
  168. }
  169. proc secure:gethost {names chan counter} {
  170. global black
  171. set name [lindex [split $names] $counter]
  172. set cc [expr $counter + 1]
  173. if {$name != ""} {
  174. securemode:gethost:raw $name $chan
  175. } else {
  176. return
  177. }
  178. utimer 3 [list secure:gethost $names $chan $cc]
  179. }
  180. proc securemode:gethost:raw {name chan} {
  181. global black
  182. putserv "USERHOST :$name"
  183. set ::shchan $chan
  184. set ::shnick $name
  185. bind RAW - 302 get:securemode:host
  186. }
  187. proc get:securemode:host {from keyword arguments} {
  188. global black botnick
  189. set is_allowed 0
  190. set has_access 0
  191. set securemode_activ 0
  192. set hosts [lindex [split $arguments] 1]
  193. set hostname [lindex [split $hosts "="] 1]
  194. regsub {^[-+]} $hostname "" mask
  195. set ident [lindex [split $mask "@"] 0]
  196. set nick $::shnick
  197. set except_mask "$nick!$mask"
  198. set chan $::shchan
  199. if {[setting:get $chan securemode]} {
  200. set chanmode [getchanmode $chan]
  201. if {[string match -nocase "*D*" $chanmode] && [string match -nocase "*m*" $chanmode]} {
  202. set securemode_activ 1
  203. }
  204. }
  205. if {$securemode_activ == "0"} {
  206. return
  207. }
  208. set replace(%botnick%) $botnick
  209. set replace(%chan%) $chan
  210. set lang [setting:get $chan lang]
  211. if {$lang == ""} { set lang [string tolower $black(default_lang)] }
  212. set getaccess [finduser $except_mask]
  213. if {[matchattr $getaccess $black(exceptflags) $chan]} {
  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 {[securemode:findexcept $chan $except_mask] == "1" || ![regexp {~} $ident]} {
  222. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  223. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  224. } else {
  225. putserv "MODE $chan +v $nick"
  226. }
  227. return
  228. }
  229. if {[info exists black(secure:$chan:allowlist)]} {
  230. if {[setting:get $chan strictsecured] == "" || [setting:get $chan strictsecured] == "0"} {
  231. if {[lsearch -exact [string tolower $black(secure:$chan:allowlist)] [string tolower $mask]] > -1} {
  232. set is_allowed 1
  233. if {[setting:get $chan xonly] && [onchan $black(chanserv) $chan]} {
  234. putserv "PRIVMSG $black(chanserv) :voice $chan $nick"
  235. } else {
  236. putserv "MODE $chan +v $nick"
  237. }
  238. }
  239. if {$is_allowed == "1"} {
  240. return
  241. }
  242. }
  243. }
  244. if {[info exists black(secure:$chan:list)]} {
  245. if {[lsearch -exact [string tolower $black(secure:$chan:list)] [string tolower $nick]] < 0} {
  246. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  247. set replace(%msg.1%) $black(securecode:$nick:$chan)
  248. set message "$black(say.$lang.securemode.1)"
  249. set len [llength $message]
  250. set random [expr int(rand()*$len)]
  251. set message [lindex $message $random]
  252. set text [black:color:set "" $message]
  253. set reply [join $text]
  254. set message [string map [array get replace] $reply]
  255. putserv "PRIVMSG $nick :$message"
  256. lappend black(secure:$chan:list) $nick
  257. }
  258. } else {
  259. set black(securecode:$nick:$chan) [string toupper [bot:setcode]]
  260. set replace(%msg.1%) $black(securecode:$nick:$chan)
  261. set message "$black(say.$lang.securemode.1)"
  262. set len [llength $message]
  263. set random [expr int(rand()*$len)]
  264. set message [lindex $message $random]
  265. set text [black:color:set "" $message]
  266. set reply [join $text]
  267. set message [string map [array get replace] $reply]
  268. putserv "PRIVMSG $nick :$message"
  269. lappend black(secure:$chan:list) $nick
  270. }
  271. check:if:bind "get:securemode:host" "302"
  272. }
  273. ##############
  274. #########################################################################
  275. ## END ##
  276. #########################################################################