BT.OwnerCmds.tcl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ######################### OWNER CMDS 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. ################################ Commands ###################################
  17. ################################## update ###################################
  18. proc update:process {nick host hand chan chan1 what type} {
  19. global black
  20. set cmd_status [btcmd:status $chan $hand "update" 0]
  21. set chan1 $chan
  22. set option [lindex $what 1]
  23. set what [lindex $what 0]
  24. if {$cmd_status == "1"} {
  25. return
  26. }
  27. switch $what {
  28. on {
  29. set out [blacktools:update_on_off 0]
  30. if {$out == 0} {
  31. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.35 ""
  32. } elseif {$out == 2} {
  33. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.36 ""
  34. rehash
  35. }
  36. }
  37. off {
  38. set out [blacktools:update_on_off 1]
  39. if {$out == 1} {
  40. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.37 ""
  41. } elseif {$out == 3} {
  42. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.38 ""
  43. rehash
  44. }
  45. }
  46. time {
  47. if {$option == ""} {
  48. set set_time [blacktools:update_set_time 0 0]
  49. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.41 $set_time
  50. return
  51. }
  52. set num [time_return_minute $option]
  53. if {$num == -1} {set num 60}
  54. blacktools:update_set_time $num 1
  55. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.42 "$option $num"
  56. rehash
  57. foreach tmr [timers] {
  58. if {[string match "*blacktools:update:timer*" [join [lindex $tmr 1]]]} {
  59. killtimer [lindex $tmr 2]
  60. }
  61. }
  62. timer $num blacktools:update:timer
  63. }
  64. start {
  65. if {[info exists black(update_disabled)]} {
  66. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.34 "$black(update_disabled)"
  67. return
  68. }
  69. if {[info exists black(backup_update)]} {
  70. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.39 ""
  71. return
  72. }
  73. blacktools:update $nick $host $chan 0
  74. }
  75. check {
  76. if {[info exists black(update_disabled)]} {
  77. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.34 "$black(update_disabled)"
  78. return
  79. }
  80. if {[info exists black(backup_update)]} {
  81. blacktools:tell $nick $host $hand $chan $chan1 autoupdate.39 ""
  82. return
  83. }
  84. blacktools:update_check $nick $hand $host $chan 0
  85. }
  86. default {
  87. switch $type {
  88. 0 {
  89. blacktools:tell $nick $host $hand $chan $chan gl.instr "update"
  90. }
  91. 1 {
  92. blacktools:tell $nick $host $hand $chan $chan gl.instr_nick "update"
  93. }
  94. 2 {
  95. blacktools:tell $nick $host $hand $chan $chan gl.instr_priv "update"
  96. }
  97. }
  98. return
  99. }
  100. }
  101. }
  102. ################################## login ####################################
  103. proc login:process {nick host hand chan chan1} {
  104. global black botnick
  105. set cmd_status [btcmd:status $chan $hand "login" 0]
  106. if {$cmd_status == "1"} {
  107. return
  108. }
  109. if {[info exists black(logged)]} {
  110. blacktools:tell $nick $host $hand $chan $chan1 login.2 "$black(chanserv)"
  111. return
  112. }
  113. putserv "PRIVMSG $black(hostchanserv) :login $black(username) $black(password)"
  114. putserv "MODE $botnick :$black(xmod)"
  115. if {[info exists black(notlogged)] || [info exists black(notlogged:failed)] || [info exists black(notlogged:invalid)]} {
  116. blacktools:tell $nick $host $hand $chan $chan1 login.3 "$black(chanserv)"
  117. }
  118. }
  119. ################################## cp #######################################
  120. proc cp:process {nick host hand chan chan1 type what from to} {
  121. global black
  122. set cmd_status [btcmd:status $chan $hand "cp" 0]
  123. if {$cmd_status == "1"} {
  124. return
  125. }
  126. set notvalid ""
  127. if {![regexp {^[&#]} $from] || (![regexp {^[&#]} $to] && ![string equal -nocase $to "all"])} {
  128. if {$type == "0"} {
  129. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "cp"
  130. }
  131. if {$type == "1"} {
  132. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "cp"
  133. }
  134. if {$type == "2"} {
  135. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "cp"
  136. }
  137. return
  138. }
  139. if {![validchan $from]} {
  140. lappend notvalid $from
  141. }
  142. if {![validchan $to]} {
  143. lappend notvalid $to
  144. }
  145. if {$notvalid != ""} {
  146. if {[llength $notvalid] > 1} {
  147. blacktools:tell $nick $host $hand $chan $chan1 cp.3 $notvalid
  148. } else {
  149. blacktools:tell $nick $host $hand $chan $chan1 cp.2 $notvalid
  150. }
  151. return
  152. }
  153. switch $what {
  154. banlist {
  155. set counter 0
  156. if {[llength [blacktools:banlist $from]] < 1} {
  157. blacktools:tell $nick $host $hand $chan $chan1 cp.1 $from
  158. return
  159. }
  160. foreach b [blacktools:banlist $from] {
  161. set file [open $black(bans_file) "a"]
  162. set num [blacktools:ban:find_id]
  163. set enc_chan [encoding convertto utf-8 $to]
  164. set read_type [lindex [split $b] 0]
  165. set read_host [lindex [split $b] 3]
  166. set read_hand [lindex [split $b] 4]
  167. set read_time1 [lindex [split $b] 5]
  168. set read_time2 [lindex [split $b] 6]
  169. set read_num1 [lindex [split $b] 7]
  170. set read_num2 [lindex [split $b] 8]
  171. set read_reason [join [lrange [split $b] 9 end]]
  172. set return [blacktools:ban:exists $read_host $enc_chan]
  173. if {$return == ""} {
  174. set counter [expr $counter + 1]
  175. puts $file "$read_type $num [string tolower $enc_chan] [string tolower $read_host] $read_hand $read_time1 $read_time2 $read_num1 $read_num2 $read_reason"
  176. }
  177. close $file
  178. }
  179. blacktools:tell $nick $host $hand $chan $chan1 cp.4 "$counter"
  180. }
  181. badchans {
  182. set total_counter 0
  183. set inc 0
  184. set file [open $black(add_file) r]
  185. set size [file size $black(add_file)]
  186. set data [split [read $file $size] \n]
  187. close $file
  188. foreach line $data {
  189. set num 0
  190. set temp_num 0
  191. set read_chan [lindex [split $line] 0]
  192. set enc_chan [encoding convertfrom utf-8 $read_chan]
  193. set read_type [lindex [split $line] 1]
  194. if {[string match -nocase $enc_chan $from] && [string match -nocase $read_type "BADCHAN"]} {
  195. set total_counter [expr $total_counter + 1]
  196. set bdchan [lindex [split $line] 3]
  197. set reason [join [lrange [split $line] 4 end]]
  198. set findchan [prot:findbadchan $to $bdchan]
  199. if {$findchan != "1"} {
  200. while {$temp_num == 0} {
  201. set get [find:num $num $to "BADCHAN"]
  202. if {$get == "$num"} {
  203. set num [expr $num + 1]
  204. } else { set temp_num 1 }
  205. }
  206. set inc [expr $inc + 1]
  207. set file [open $black(add_file) a]
  208. puts $file "$to BADCHAN $num $bdchan $reason"
  209. close $file
  210. }
  211. }
  212. }
  213. blacktools:tell $nick $host $hand $chan $chan1 cp.7 "$inc $total_counter"
  214. }
  215. userlist {
  216. set time [unixtime]
  217. set counter 0
  218. set total_counter 0
  219. foreach u [userlist] {
  220. if {[matchattr $u $black(exceptflags) $from]} {
  221. set total_counter [expr $total_counter + 1]
  222. set cflags [chattr $u | $from]
  223. if {![matchattr $cflags $to]} {
  224. set counter [expr $counter + 1]
  225. chattr $u $cflags $to
  226. setuser $u XTRA CHANMODIF($to) $time:cp_from_$from
  227. }
  228. }
  229. }
  230. blacktools:tell $nick $host $hand $chan $chan1 cp.5 "$counter $total_counter"
  231. }
  232. settings {
  233. set getflags [get:flags $from]
  234. set getstr [get:str $from]
  235. set counter 0
  236. set file [open $black(extra_file) a]
  237. foreach flag $getflags {
  238. if {[string equal -nocase $flag "+forward"]} {
  239. continue
  240. }
  241. set return [blacktools:flag:exists $to $flag]
  242. if {$return == "0"} {
  243. set counter [expr $counter + 1]
  244. puts $file "$to XTRA $flag"
  245. }
  246. }
  247. foreach str $getstr {
  248. set split_str [split $str "&&"]
  249. set s [lindex $split_str 0]
  250. if {[string equal -nocase $s "backchan"]} {
  251. continue
  252. }
  253. set why [join [lrange $split_str 1 end]]
  254. set return [blacktools:flag:exists $to $s]
  255. if {$return == "0"} {
  256. set counter [expr $counter + 1]
  257. puts $file "$to XTRA $s [concat $why]"
  258. }
  259. }
  260. set gettopic [topic:get $from]
  261. if {$gettopic != ""} {
  262. set counter [expr $counter + 1]
  263. msg:add $gettopic $to "TOPIC"
  264. }
  265. close $file
  266. blacktools:tell $nick $host $hand $chan $chan1 cp.6 "$counter"
  267. }
  268. default {
  269. if {$type == "0"} {
  270. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "cp"
  271. }
  272. if {$type == "1"} {
  273. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "cp"
  274. }
  275. }
  276. }
  277. }
  278. ############################## status #################################
  279. proc status:process {nick host hand chan} {
  280. global black botnick server uptime {server-online} countusers version getowner tcl_patchLevel
  281. set cmd_status [btcmd:status $chan $hand "status" 0]
  282. if {$cmd_status == "1"} {
  283. return
  284. }
  285. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  286. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  287. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  288. return
  289. }
  290. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  291. return
  292. }
  293. foreach c [channels] {
  294. if {![setting:get $c invisible]} {
  295. lappend channels $c
  296. } else {
  297. if {[matchattr $hand n]} {
  298. lappend channels \002$c\002
  299. }
  300. }
  301. }
  302. set chan1 "$chan"
  303. blacktools:tell $nick $host $hand $chan $chan1 status.1 "$black(name) $black(vers) $version $tcl_patchLevel"
  304. blacktools:tell $nick $host $hand $chan $chan1 status.4 [join $channels]
  305. blacktools:tell $nick $host $hand $chan $chan1 status.5 "[countusers] [userlist n]"
  306. }
  307. ############################## broadcast ##############################
  308. proc broadcast:cmd:process {nick host hand chan chan1 text type} {
  309. global botnick black
  310. set cmd_status [btcmd:status $chan $hand "broadcast" 0]
  311. if {$cmd_status == "1"} {
  312. return
  313. }
  314. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  315. return
  316. }
  317. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  318. return
  319. }
  320. if {$text == ""} {
  321. switch $type {
  322. 0 {
  323. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "broadcast"
  324. }
  325. 1 {
  326. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "broadcast"
  327. }
  328. 2 {
  329. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "broadcast"
  330. }
  331. }
  332. return 0
  333. }
  334. foreach c [channels] {
  335. if {![setting:get $c silent]} {
  336. putserv "PRIVMSG $c :\[\002BROADCAST\002\] $text"
  337. }
  338. }
  339. }
  340. ############################## msg ####################################
  341. proc msg:process {nick host hand chan chan1 who msg type} {
  342. global black
  343. set cmd_status [btcmd:status $chan $hand "msg" 0]
  344. if {$cmd_status == "1"} {
  345. return
  346. }
  347. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  348. return
  349. }
  350. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  351. return
  352. }
  353. if {$who == ""} {
  354. switch $type {
  355. 0 {
  356. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "msg"
  357. }
  358. 1 {
  359. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "msg"
  360. }
  361. 2 {
  362. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "msg"
  363. }
  364. }
  365. return
  366. }
  367. if {[isbotnick $who]} {
  368. return
  369. }
  370. putserv "USERHOST :$who"
  371. bind RAW - 302 msg:online:check
  372. set ::msgnick $nick
  373. set ::hand $hand
  374. set ::host $host
  375. set ::chan $chan
  376. set ::chan1 $chan1
  377. set ::type $type
  378. set ::msg $msg
  379. set ::who $who
  380. }
  381. proc msg:online:check {from keyword arguments } {
  382. global black
  383. set msgnick $::msgnick
  384. set hand $::hand
  385. set host $::host
  386. set chan $::chan
  387. set chan1 $::chan1
  388. set who $::who
  389. set msg $::msg
  390. set hostname [lindex [split $arguments] 1]
  391. if {[regexp {\+} $hostname]} {
  392. set split_host [split $hostname "+"]
  393. } else {
  394. set split_host [split $hostname "-"]
  395. }
  396. set mask [lindex $split_host 1]
  397. set getnick [string map {
  398. "=" ""
  399. ":" ""
  400. } [lindex $split_host 0]]
  401. if {$getnick != ""} {
  402. if {[matchattr $hand -|A $chan] && [string equal -nocase $who $black(chanserv)]} {
  403. check:if:bind "msg:online:check" "302"
  404. return
  405. }
  406. if {$host != ""} {
  407. if {[matchattr $hand -|AM $chan] && [onchan $who $chan]} {
  408. putserv "PRIVMSG $who :$msg"
  409. check:if:bind "msg:online:check" "302"
  410. return
  411. }
  412. }
  413. if {[matchattr $hand mno]} {
  414. putserv "PRIVMSG $who :$msg"
  415. }
  416. } else {
  417. blacktools:tell $msgnick $host $hand $chan $chan1 gl.notonline "$who"
  418. }
  419. check:if:bind "msg:online:check" "302"
  420. }
  421. proc msg:getmessage {nick host hand arg} {
  422. global black
  423. }
  424. ############################### channels ########################
  425. proc channels:process {nick host hand chan chan1} {
  426. global botnick black
  427. set cmd_status [btcmd:status $chan $hand "channels" 0]
  428. if {$cmd_status == "1"} {
  429. return
  430. }
  431. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  432. return
  433. }
  434. set num [llength [channels]]
  435. set minusers "5"
  436. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  437. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  438. foreach c [channels] {
  439. if {![setting:get $c invisible]} {
  440. set usersnumber [llength [chanlist $c]]
  441. if {[channel get $c inactive]} {
  442. if {[info exists black(abuse:$c)]} {
  443. lappend message_aschan "[join $c ", "]"
  444. } else {
  445. lappend message_schan "[join $c ", "]"
  446. }
  447. } elseif {![onchan $botnick $c]} {
  448. lappend message_nchan "[join $c ", "]"
  449. } elseif {[onchan $botnick $c] && (![botisop $c]) && ($usersnumber >= $minusers)} {
  450. lappend message_ok "[join $c ", "]"
  451. } elseif {[onchan $botnick $c] && ($usersnumber < $minusers)} {
  452. lappend message_nmin "[join $c ", "]"
  453. }
  454. if {[botisop $c] && ($usersnumber >= $minusers)} {
  455. lappend message_ok "[join @$c ", "]"
  456. }
  457. } else {
  458. if {[matchattr $hand n]} {
  459. lappend message_inv "[join $c ", "]"
  460. }
  461. }
  462. }
  463. blacktools:tell $nick $host $hand $chan $chan1 channels.1 $num
  464. if {[info exists message_ok]} {
  465. foreach word [wordwrap [join "\[$black(say.$getlang.channels.3)\]: $message_ok"] 350 ,] {
  466. blacktools:tell $nick $host $hand $chan $chan1 channels.2 $word
  467. }
  468. }
  469. if {[info exists message_nchan]} {
  470. foreach word [wordwrap [join "\[$black(say.$getlang.channels.4)\]: $message_nchan"] 350 ,] {
  471. blacktools:tell $nick $host $hand $chan $chan1 channels.2 $word
  472. }
  473. }
  474. if {[info exists message_nmin]} {
  475. foreach word [wordwrap [join "\[$black(say.$getlang.channels.7) < $minusers\]: $message_nmin"] 350 ,] {
  476. blacktools:tell $nick $host $hand $chan $chan1 channels.2 $word
  477. }
  478. }
  479. if {[info exists message_schan]} {
  480. foreach word [wordwrap [join "\[$black(say.$getlang.channels.5)\]: $message_schan"] 350 ,] {
  481. blacktools:tell $nick $host $hand $chan $chan1 channels.2 $word
  482. }
  483. }
  484. if {[info exists message_aschan]} {
  485. foreach word [wordwrap [join "\[$black(say.$getlang.channels.6)\]: $message_aschan"] 350 ,] {
  486. blacktools:tell $nick $host $hand $chan $chan1 channels.2 $word
  487. }
  488. }
  489. if {[info exists message_inv]} {
  490. foreach word [wordwrap [join "\[$black(say.$getlang.channels.8)\]: $message_inv"] 350 ,] {
  491. blacktools:tell $nick $host $hand $chan $chan1 channels.2 $word
  492. }
  493. }
  494. }
  495. ############################### nick ##################################
  496. proc tempnick:process {thenick tonick host hand chan chan1 type} {
  497. global nick lastbind black
  498. set cmd_status [btcmd:status $chan $hand "nick" 0]
  499. if {$cmd_status == "1"} {
  500. return
  501. }
  502. if {$thenick == ""} {
  503. switch $type {
  504. 0 {
  505. blacktools:tell $tonick $host $hand $chan $chan1 gl.instr "nick"
  506. }
  507. 1 {
  508. blacktools:tell $tonick $host $hand $chan $chan1 gl.instr_nick "nick"
  509. }
  510. 2 {
  511. blacktools:tell $tonick $host $hand $chan $chan1 gl.instr_priv "nick"
  512. }
  513. }
  514. return
  515. }
  516. if {$black(nickserv:identify) == "1"} {
  517. putserv "PRIVMSG $black(nickserv:host) :RELEASE $thenick $black(nickserv:pass)"
  518. }
  519. set nick $thenick
  520. blacktools:tell $tonick $host $hand $chan $chan1 nick.4 $thenick
  521. }
  522. proc nick:process {who newnick host hand chan} {
  523. global black nick config
  524. set chan1 "$chan"
  525. if {$newnick == ""} {
  526. blacktools:tell $who $host $hand $chan $chan1 nick.2 $newnick
  527. return
  528. }
  529. blacktools:tell $who $host $hand $chan $chan1 nick.1 $newnick
  530. set ::lastnick [config:getinfo $config "set nick \"*\""]
  531. if {$black(nickserv:identify) == "1"} {
  532. putserv "PRIVMSG $black(nickserv:host) :RELEASE $newnick $black(nickserv:pass)"
  533. }
  534. set nick [join $newnick]
  535. set error [config:save $config "set nick \"*\"" "set nick \"$newnick\""]
  536. if {$error == "0"} {
  537. blacktools:tell $who $host $hand $chan $chan1 nick.3 ""
  538. }
  539. bind RAW - 432 check:validnickname
  540. }
  541. ##############
  542. #########################################################################
  543. ## END ##
  544. #########################################################################