BT.AutoUpdate.tcl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ######################### AutoUpdate 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. package require tls
  17. set black(backup_dir) "$black(dirname)/BT.backup"
  18. set black(log_file) "$black(dirname)/BT.update.log"
  19. set black(actdir) "scripts"
  20. ###
  21. proc blacktools:check_addons {hand chan} {
  22. global black
  23. if {[catch {package require http} no_http] != 0} {
  24. source $black(dirname)/BlackTools/Addons/http.tcl
  25. package require http
  26. }
  27. if {[catch {package require json} no_json] != 0} {
  28. source $black(dirname)/BlackTools/Addons/json.tcl
  29. package require json
  30. }
  31. if {[catch {package require github} no_github] != 0} {
  32. source $black(dirname)/BlackTools/Addons/github.tcl
  33. package require github
  34. }
  35. return 1
  36. }
  37. ###
  38. proc blacktools:update_check {nick hand host chan type} {
  39. global black
  40. set check_addons [blacktools:check_addons $hand $chan]
  41. set status [blacktools:update_verify]
  42. if {$status == -1} {
  43. blacktools:update_put $hand $chan 31 ""
  44. blacktools:tell $nick $host $hand $chan $chan autoupdate.31 ""
  45. return 0
  46. }
  47. set data [split $status "\n"]
  48. set new_version [lindex [lindex $data 0] 1]
  49. set last_modify [lindex [lindex $data 1] 2]
  50. set status [lindex [lindex $data 2] 1]
  51. if {$black(vers) != $new_version} {
  52. if {$type == 0} {
  53. blacktools:tell $nick $host $hand $chan $chan autoupdate.32 "$new_version"
  54. } else {
  55. return [list $new_version $last_modify]
  56. }
  57. } elseif {$last_modify != $black(current_modif)} {
  58. if {$type == 0} {
  59. blacktools:tell $nick $host $hand $chan $chan autoupdate.33 [ctime $last_modify]
  60. }
  61. return [list $new_version $last_modify]
  62. } else {
  63. if {$type == 0} {
  64. blacktools:tell $nick $host $hand $chan $chan autoupdate.5 ""
  65. }
  66. return 0
  67. }
  68. }
  69. ###
  70. proc blacktools:update:timer {} {
  71. global black
  72. if {$black(update_type) == 0} {
  73. if {![info exists black(update_disabled)]} {
  74. if {![info exists black(backup_update)]} {
  75. set update [catch {blacktools:update "" "" ""} error]
  76. } else {
  77. blacktools:update_put "" "" 40 ""
  78. }
  79. } else {
  80. blacktools:update_put "" "" 27 [list [ctime [unixtime]]]
  81. blacktools:update_put "" "" 30 [list $black(update_disabled)]
  82. }
  83. } else {
  84. if {$black(update_note) == 1} {
  85. if {![info exists black(update_disabled)]} {
  86. set check [blacktools:update_check "" "" "" "" 1]
  87. if {$check != 0} {
  88. set found_version [lindex $check 0]
  89. set last_modif [lindex $check 1]
  90. blacktools:update:note $last_modif $found_version
  91. }
  92. }
  93. }
  94. }
  95. timer [time_return_minute $black(update_time_check)] blacktools:update:timer
  96. }
  97. ###
  98. proc blacktools:update:note {num version} {
  99. global black botnick
  100. set time [unixtime]
  101. foreach user [userlist n] {
  102. set nonotes [getuser $user XTRA NO_NOTES]
  103. if {$nonotes == ""} {
  104. set check_note [blacktools:update_note_check $user $num]
  105. if {$check_note == 1} {continue}
  106. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  107. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  108. set black(notes:announce:$user) 1
  109. set replace(%msg.1%) $version
  110. set replace(%msg.2%) [ctime $num]
  111. set text [black:color:set $botnick $black(say.$getlang.autoupdate.43)]
  112. set text [string map [array get replace] $text]
  113. notes:add $botnick "" $user "DB" "INBOX" $text "AUTOUPDATE:$num" 0
  114. }
  115. }
  116. }
  117. ###
  118. proc blacktools:update_note_check {hand num} {
  119. global black
  120. set found_it 0
  121. set file [open $black(notes_file) "r"]
  122. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  123. set temp "$black(tempdir)/notes_temp.$timestamp"
  124. set tempwrite [open $temp w]
  125. while {[gets $file line] != -1} {
  126. set handle [lindex [split $line] 4]
  127. if {[string equal -nocase $handle $hand]} {
  128. set sender [lindex [split $line] 6]
  129. set split_send [split $sender ":"]
  130. set last_update [lindex $split_send 1]
  131. set sender [lindex $split_send 0]
  132. if {[string equal -nocase $sender "AUTOUPDATE"] && [string equal -nocase $num $last_update]} {
  133. set found_it 1
  134. break
  135. }
  136. }
  137. }
  138. close $file
  139. return $found_it
  140. }
  141. ###
  142. proc blacktools:update {hand host chan} {
  143. global black
  144. if {[info exists black(backup_update)]} {
  145. blacktools:update_put $hand $chan 29 ""
  146. return 0
  147. }
  148. set error_b ""
  149. set file [open $black(log_file) w]
  150. close $file
  151. blacktools:update_put $hand $chan 27 [list [ctime [unixtime]]]
  152. blacktools:update_put $hand $chan 28 ""
  153. set check_addons [blacktools:check_addons $hand $chan]
  154. if {$check_addons == 0} {
  155. blacktools:update_put $hand $chan 1 ""
  156. return
  157. }
  158. set status [blacktools:update_verify]
  159. if {$status == -1} {
  160. blacktools:update_put $hand $chan 2 ""
  161. return 0
  162. }
  163. set data [split $status "\n"]
  164. set new_version [lindex [lindex $data 0] 1]
  165. set last_modify [lindex [lindex $data 1] 2]
  166. set status [lindex [lindex $data 2] 1]
  167. if {$black(vers) != $new_version} {
  168. blacktools:update_put $hand $chan 3 [list $new_version]
  169. } elseif {$last_modify != $black(current_modif)} {
  170. blacktools:update_put $hand $chan 4 [list $black(vers)]
  171. } else {
  172. blacktools:update_put $hand $chan 5 ""
  173. return 0
  174. }
  175. if {![file isdirectory $black(backup_dir)]} {
  176. if {[catch {file mkdir $black(backup_dir)} error] != 0} {
  177. blacktools:update_put $hand $chan 6 [list $error]
  178. return 0
  179. }
  180. }
  181. if {[file exists $black(backup_dir)/BlackTools.tcl]} {
  182. blacktools:update_put "" "" 7 ""
  183. file delete -force $black(backup_dir)/BlackTools
  184. file delete -force $black(backup_dir)/BlackTools.tcl
  185. }
  186. if {[catch {file copy -force "$black(dirname)/BlackTools" $black(backup_dir)} error_b] == 0} {
  187. blacktools:update_put "" "" 8 ""
  188. } else {
  189. blacktools:update_put $hand $chan 9 [list $error_b]
  190. file delete -force $black(backup_dir)
  191. return 0
  192. }
  193. if {[catch {file copy -force $black(tclconfig) $black(backup_dir)} error_b] != 0} {
  194. blacktools:update_put $hand $chan 10 ""
  195. file delete -force $black(backup_dir)
  196. return 0
  197. } else {
  198. blacktools:update_put "" "" 11 ""
  199. }
  200. set black(update_hand) $hand
  201. set black(update_version) $new_version
  202. set black(update_last_modify) $last_modify
  203. set black(update_chan) $chan
  204. blacktools:every 1000 {
  205. if {[file isdirectory "$black(backup_dir)/BlackTools"]} {
  206. set after_file_num [llength [glob-r "$black(backup_dir)/BlackTools"]]
  207. set current_file_num [llength [glob-r "$black(actdir)/BlackTools"]]
  208. if {$current_file_num == $after_file_num} {
  209. blacktools:update_backup
  210. break
  211. }
  212. }
  213. }
  214. }
  215. ###
  216. proc blacktools:update_backup {} {
  217. global black
  218. set hand $black(update_hand)
  219. set new_version $black(update_version)
  220. set last_modify $black(update_last_modify)
  221. set chan $black(update_chan)
  222. set black(backup_update) 1
  223. set black(start_update) [unixtime]
  224. set black(update_file_saved) [llength [glob -nocomplain -directory "$black(dirname)/BlackTools/FILES" "*.txt"]]
  225. if {[file isdirectory "$black(dirname)/BlackTools/FILES/TOPWORDS"]} {
  226. set black(update_file_topwords) 1
  227. set black(update_file_saved) [expr $black(update_file_saved) + [llength [glob -nocomplain -directory "$black(dirname)/BlackTools/FILES/TOPWORDS" "*.txt"]]]
  228. }
  229. blacktools:update_put "" "" 12 ""
  230. blacktools:update_put "" "" 13 ""
  231. blacktools:update_put "" "" 14 ""
  232. blacktools:update_put $hand $chan 15 [list $new_version [ctime $last_modify]]
  233. blacktools:backup_run $hand $chan $new_version $last_modify
  234. unset black(update_version)
  235. unset black(update_last_modify)
  236. unset black(update_hand)
  237. unset black(update_chan)
  238. }
  239. ###
  240. proc blacktools:backup_run {hand chan new_version last_modify} {
  241. global black config
  242. set black(update_old_data) [blacktools:update_data 0 ""]
  243. set bt_file "$black(dirname)/BlackTools.tcl"
  244. set file [open $bt_file r]
  245. set data [read -nonewline $file]
  246. close $file
  247. set regexp_var2 "set black\\(dirname\\) \"(.*?)\""
  248. regexp -nocase $regexp_var2 $data found_line
  249. regexp -nocase $regexp_var2 $data -> found
  250. set found_line [string map [list $black(dirname) $black(backup_dir)] $found_line]
  251. regsub $regexp_var2 $data $found_line data
  252. blacktools:update_data 1 $data
  253. set file [open $config r]
  254. set data [read -nonewline $file]
  255. close $file
  256. set reg "source $black(dirname)/BlackTools.tcl"
  257. regsub $reg $data "source $black(dirname)/BlackTools.old.tcl" data
  258. set file [open $config w]
  259. puts $file $data
  260. close $file
  261. file rename -force "$black(dirname)/BlackTools.tcl" "$black(dirname)/BlackTools.old.tcl"
  262. utimer 5 [list blacktools:update_start_download $hand $chan $new_version $last_modify]
  263. }
  264. ###
  265. proc blacktools:update_start_download {hand chan new_version last_modify} {
  266. global black
  267. rehash
  268. set black(update_hand) $hand
  269. set black(update_chan) $chan
  270. file delete -force "$black(actdir)/BlackTools"
  271. ::github::github update tclscripts BlackTools-TCL $black(actdir)
  272. blacktools:every 1000 {
  273. if {[file isdirectory $black(actdir)/BlackTools]} {
  274. blacktools:update_start_restore
  275. break
  276. }
  277. }
  278. }
  279. ###
  280. #https://wiki.tcl-lang.org/page/glob
  281. proc glob-r {{dir .}} {
  282. set res {}
  283. foreach i [lsort [glob -nocomplain -dir $dir *]] {
  284. if {[file type $i] eq {directory}} {
  285. eval lappend res [glob-r $i]
  286. } else {
  287. lappend res $i
  288. }
  289. }
  290. set res
  291. } ;# RS
  292. ###
  293. proc blacktools:update_unsetflag {} {
  294. global black
  295. if {[info exists black(backup_update)]} {
  296. unset black(backup_update)
  297. }
  298. }
  299. ###
  300. proc blacktools:update_start_restore {} {
  301. global black
  302. set hand $black(update_hand)
  303. set chan $black(update_chan)
  304. set userlang [blacktools:update_userlang $hand]
  305. if {![file isdirectory "$black(actdir)/BlackTools"]} {
  306. blacktools:update_put $hand $chan 16 ""
  307. file delete -force $black(backup_dir)
  308. blacktools:update_unsetflag
  309. return
  310. } elseif {![file exists "$black(actdir)/BlackTools.tcl"]} {
  311. blacktools:update_put $hand $chan 16 ""
  312. file delete -force $black(backup_dir)
  313. blacktools:update_unsetflag
  314. return
  315. }
  316. set end_download [unixtime]
  317. set dif [expr $end_download - $black(start_update)]
  318. blacktools:update_put "" "" 17 [list [return_time $userlang $dif]]
  319. set newdata [blacktools:update_data 0 ""]
  320. blacktools:update_put $hand $chan 18 ""
  321. set restore_config [blacktools:update_restore $black(update_old_data) $newdata]
  322. unset black(update_old_data)
  323. set newdata [lindex $restore_config 0]
  324. set num_var [lindex $restore_config 1]
  325. if {$num_var > 0} {
  326. set newdata [blacktools:update_data 1 $newdata]
  327. blacktools:update_put $hand $chan 19 [list $num_var]
  328. } else {
  329. blacktools:update_put "" "" 20 ""
  330. }
  331. blacktools:update_put $hand $chan 21 ""
  332. blacktools:update_restore_files
  333. blacktools:every 1000 {
  334. set info_files_num [llength [glob -nocomplain -directory "$black(actdir)/BlackTools/FILES" "*.txt"]]
  335. if {[file isdirectory "$black(actdir)/BlackTools/FILES/TOPWORDS"]} {
  336. set info_files_topwords [llength [glob -nocomplain -directory "$black(actdir)/BlackTools/FILES/TOPWORDS" "*.txt"]]
  337. set info_files_num [expr $info_files_num + $info_files_topwords]
  338. }
  339. if {$info_files_num == $black(update_file_saved)} {
  340. blacktools:update_end $info_files_num
  341. break
  342. }
  343. }
  344. }
  345. ###
  346. proc blacktools:update_end {num} {
  347. global black config
  348. set hand $black(update_hand)
  349. set chan $black(update_chan)
  350. set userlang [blacktools:update_userlang $hand]
  351. set end_update [unixtime]
  352. set dif [expr $end_update - $black(start_update)]
  353. unset black(start_update)
  354. if {$num == 0} {
  355. blacktools:update_put "" "" 22 ""
  356. } else {
  357. blacktools:update_put $hand $chan 23 [list $num]
  358. }
  359. set file [open $config r]
  360. set data [read -nonewline $file]
  361. close $file
  362. set reg "source $black(actdir)/BlackTools.old.tcl"
  363. regsub $reg $data "source $black(actdir)/BlackTools.tcl" data
  364. set file [open $config w]
  365. puts $file $data
  366. close $file
  367. rehash
  368. unset black(update_hand)
  369. unset black(update_chan)
  370. blacktools:update_unsetflag
  371. blacktools:update_put $hand $chan 24 [list [return_time $userlang $dif]]
  372. blacktools:update_put $hand $chan 25 [list $black(backup_dir) $black(log_file)]
  373. blacktools:update_put $hand $chan 26 ""
  374. unset black(update_file_saved)
  375. file delete -force "$black(actdir)/BlackTools.old.tcl"
  376. }
  377. ###
  378. proc blacktools:update_restore_files {} {
  379. global black
  380. set files ""
  381. set counter 0
  382. set files [glob -nocomplain -directory "$black(backup_dir)/BlackTools/FILES" "*.txt"]
  383. if {![file isdirectory "$black(actdir)/BlackTools/FILES"]} {
  384. file mkdir "$black(actdir)/BlackTools/FILES"
  385. }
  386. foreach f $files {
  387. incr counter
  388. set filename [file tail $f]
  389. file copy -force $f "$black(actdir)/BlackTools/FILES/$filename"
  390. }
  391. if {[info exists black(update_file_topwords)]} {
  392. if {![file isdirectory "$black(actdir)/BlackTools/FILES/TOPWORDS"]} {
  393. file mkdir "$black(actdir)/BlackTools/FILES/TOPWORDS"
  394. }
  395. set topwords_files [glob -nocomplain -directory "$black(backup_dir)/BlackTools/FILES/TOPWORDS" "*.txt"]
  396. foreach f $topwords_files {
  397. incr counter
  398. set filename [file tail $f]
  399. file copy -force $f "$black(actdir)/BlackTools/FILES/TOPWORDS/$filename"
  400. }
  401. }
  402. unset black(update_file_topwords)
  403. return $counter
  404. }
  405. ###
  406. proc blacktools:update_set_time {num type} {
  407. global black
  408. set bt_file "$black(dirname)/BlackTools.tcl"
  409. set file [open $bt_file r]
  410. set data [read -nonewline $file]
  411. close $file
  412. set regexp_var2 "set black\\(update_time_check\\) \"(.*?)\""
  413. regexp -nocase $regexp_var2 $data -> found
  414. if {$type == 0} {
  415. return $found
  416. } else {
  417. regexp -nocase $regexp_var2 $data found_line
  418. set found_line [string map [list $found $num] $found_line]
  419. regsub $regexp_var2 $data $found_line data
  420. blacktools:update_data 1 $data
  421. }
  422. }
  423. ###
  424. proc blacktools:update_on_off {type} {
  425. global black
  426. set regexp_var2 "set black\\(update_type\\) \"(.*?)\""
  427. set bt_file "$black(dirname)/BlackTools.tcl"
  428. set file [open $bt_file r]
  429. set data [read -nonewline $file]
  430. close $file
  431. regexp -nocase $regexp_var2 $data found_line
  432. regexp -nocase $regexp_var2 $data -> found
  433. if {$type == 0 && $found == 0} {
  434. return 0
  435. }
  436. if {$type == 1 && $found == 1} {
  437. return 1
  438. }
  439. switch $type {
  440. 0 {
  441. set found_line [string map {"1" "0"} $found_line]
  442. regsub $regexp_var2 $data $found_line data
  443. blacktools:update_data 1 $data
  444. return 2
  445. }
  446. 1 {
  447. set found_line [string map {"0" "1"} $found_line]
  448. regsub $regexp_var2 $data $found_line data
  449. blacktools:update_data 1 $data
  450. return 3
  451. }
  452. }
  453. }
  454. ###
  455. proc blacktools:update_restore {data newdata} {
  456. global black
  457. set current_data $newdata
  458. set variables [regexp -all -inline {set black\((.+?)\)} $data]
  459. regsub -all {set black\((.+?)\)} $variables "" variables
  460. set var_nomodif "name author vers site current_modif"
  461. set var_counter 0
  462. foreach var $variables {
  463. if {$var == ""} {continue}
  464. if {[lsearch -nocase $var_nomodif $var] > -1} {continue}
  465. set regexp_var "set black\\($var\\) \\{(.*?)\\}"
  466. set regexp_var2 "set black\\($var\\) \"(.*?)\""
  467. regexp -nocase $regexp_var $data found_old
  468. regexp -nocase $regexp_var2 $data found_old_2
  469. if {[info exists found_old]} {
  470. set found_old [concat $found_old]
  471. regexp -nocase $regexp_var $newdata found_new
  472. if {[info exists found_new]} {
  473. if {[string equal -nocase $found_old $found_new]} {continue}
  474. incr var_counter
  475. regsub $regexp_var $current_data $found_old current_data
  476. unset found_new
  477. }
  478. unset found_old
  479. }
  480. }
  481. foreach var $variables {
  482. if {$var == ""} {continue}
  483. if {[lsearch -nocase $var_nomodif $var] > -1} {continue}
  484. set regexp_var2 "set black\\($var\\) \"(.*?)\""
  485. regexp -nocase $regexp_var2 $data found_old_2
  486. if {[info exists found_old_2]} {
  487. set found_old_2 [concat $found_old_2]
  488. regexp -nocase $regexp_var2 $newdata found_new_2
  489. if {[info exists found_new_2]} {
  490. if {[string equal -nocase $found_old_2 $found_new_2]} {continue}
  491. incr var_counter
  492. regsub $regexp_var2 $current_data $found_old_2 current_data
  493. unset found_new_2
  494. }
  495. unset found_old_2
  496. }
  497. }
  498. return [list $current_data $var_counter]
  499. }
  500. ###
  501. proc blacktools:update_data {type data} {
  502. global black
  503. set bt_file "$black(dirname)/BlackTools.tcl"
  504. if {![file exists $bt_file]} {
  505. return 0
  506. }
  507. if {$type == 0} {
  508. set file [open $bt_file r]
  509. set data [read -nonewline $file]
  510. close $file
  511. return $data
  512. } else {
  513. set file [open $bt_file w]
  514. puts $file $data
  515. close $file
  516. }
  517. }
  518. ###
  519. proc blacktools:update_verify {} {
  520. global black
  521. set link "https://raw.githubusercontent.com/tclscripts/BlackTools-TCL/master/VERSION"
  522. http::register https 443 [list ::tls::socket -autoservername true]
  523. set ipq [http::config -useragent "lynx"]
  524. set error [catch {set ipq [::http::geturl $link -timeout 10000]} eror]
  525. set status [::http::status $ipq]
  526. if {$status != "ok"} {
  527. ::http::cleanup $ipq
  528. return -1
  529. }
  530. set getipq [::http::data $ipq]
  531. ::http::cleanup $ipq
  532. return $getipq
  533. }
  534. ###
  535. proc blacktools:update_userlang {nick} {
  536. global black
  537. if {$nick == ""} {return [string tolower $black(default_lang)]}
  538. set hand [nick2hand $nick]
  539. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  540. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  541. return $userlang
  542. }
  543. ###
  544. proc blacktools:update_put {nick chan num var} {
  545. global black
  546. set counter 0
  547. foreach v $var {
  548. incr counter
  549. set replace(%msg.${counter}%) $v
  550. }
  551. if {$nick != "" && $chan != ""} {
  552. set hand [nick2hand $nick]
  553. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  554. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  555. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  556. if {$getmethod == ""} { set getmethod "0" }
  557. set text [black:color:set "" $black(say.${userlang}.autoupdate.${num})]
  558. set reply [join $text]
  559. set reply [string map [array get replace] $reply]
  560. switch $getmethod {
  561. 0 {
  562. putserv "NOTICE $nick :$reply"
  563. }
  564. 1 {
  565. putserv "PRIVMSG $chan :$reply"
  566. }
  567. 2 {
  568. putserv "PRIVMSG $nick :$reply"
  569. }
  570. }
  571. } else {
  572. set lang [string tolower $black(default_lang)]
  573. set text [black:color:set "" $black(say.${lang}.autoupdate.${num})]
  574. set reply [join $text]
  575. set reply [string map [array get replace] $reply]
  576. }
  577. putlog "\[BT\] $reply"
  578. set file [open $black(log_file) a]
  579. puts $file $reply
  580. close $file
  581. }
  582. ###
  583. #https://wiki.tcl-lang.org/page/every
  584. proc blacktools:every {interval script} {
  585. global everyIds
  586. if {$interval eq {cancel}} {
  587. after cancel $everyIds($script)
  588. return
  589. }
  590. set everyIds($script) [after $interval [namespace code [info level 0]]]
  591. set rc [catch {uplevel #0 $script} result]
  592. if {$rc == [catch break]} {
  593. after cancel $everyIds($script)
  594. set rc 0
  595. } elseif {$rc == [catch continue]} {
  596. # Ignore - just consume the return code
  597. set rc 0
  598. }
  599. # TODO: Need better handling of errorInfo etc...
  600. return -code $rc $result
  601. }