BT.AutoUpdate.tcl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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 ::update_hand $hand
  201. set ::update_version $new_version
  202. set ::update_last_modify $last_modify
  203. set ::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 $::update_hand
  219. set new_version $::update_version
  220. set last_modify $::update_last_modify
  221. set chan $::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_topwords_files) 1
  227. set black(update_file_saved) [expr [llength [glob -nocomplain -directory "$black(dirname)/BlackTools/FILES/TOPWORDS" "*.txt"]] + $black(update_file_saved)]
  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
  234. utimer 5 [list blacktools:update_start_download $hand $chan $new_version $last_modify]
  235. unset ::update_version
  236. unset ::update_last_modify
  237. unset ::update_hand
  238. unset ::update_chan
  239. }
  240. ###
  241. proc blacktools:backup_run {} {
  242. global black config
  243. set black(update_old_data) [blacktools:update_data 0 ""]
  244. set bt_file "$black(dirname)/BlackTools.tcl"
  245. set file [open $bt_file r]
  246. set data [read -nonewline $file]
  247. close $file
  248. set regexp_var2 "set black\\(dirname\\) \"(.*?)\""
  249. regexp -nocase $regexp_var2 $data found_line
  250. regexp -nocase $regexp_var2 $data -> found
  251. set found_line [string map [list $black(dirname) $black(backup_dir)] $found_line]
  252. regsub $regexp_var2 $data $found_line data
  253. blacktools:update_data 1 $data
  254. set file [open $config r]
  255. set data [read -nonewline $file]
  256. close $file
  257. set reg "source $black(dirname)/BlackTools.tcl"
  258. regsub $reg $data "source $black(dirname)/BlackTools.old.tcl" data
  259. set file [open $config w]
  260. puts $file $data
  261. close $file
  262. file rename -force "$black(dirname)/BlackTools.tcl" "$black(dirname)/BlackTools.old.tcl"
  263. }
  264. ###
  265. proc blacktools:update_start_download {hand chan new_version last_modify} {
  266. global black
  267. rehash
  268. set ::update_hand $hand
  269. set ::update_chan $chan
  270. file delete -force "$black(actdir)/BlackTools"
  271. ::github::github update tclscripts BlackTools-TCL $black(actdir)
  272. 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 $::update_hand
  303. set chan $::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. set ::update_hand $::update_hand
  334. set ::update_chan $::update_chan
  335. every 1000 {
  336. set info_files_num [llength [glob -nocomplain -directory "$black(actdir)/BlackTools/FILES" "*.txt"]]
  337. if {[file isdirectory "$black(actdir)/BlackTools/FILES/TOPWORDS"]} {
  338. set info_files_num [expr [llength [glob -nocomplain -directory "$black(actdir)/BlackTools/FILES/TOPWORDS" "*.txt"]] + $info_files_num]
  339. }
  340. if {$info_files_num == $black(update_file_saved)} {
  341. blacktools:update_end $info_files_num
  342. break
  343. }
  344. }
  345. }
  346. ###
  347. proc blacktools:update_end {num} {
  348. global black config
  349. set hand $::update_hand
  350. set chan $::update_chan
  351. set userlang [blacktools:update_userlang $hand]
  352. set end_update [unixtime]
  353. set dif [expr $end_update - $black(start_update)]
  354. unset black(start_update)
  355. if {$num == 0} {
  356. blacktools:update_put "" "" 22 ""
  357. } else {
  358. blacktools:update_put $hand $chan 23 [list $num]
  359. }
  360. set file [open $config r]
  361. set data [read -nonewline $file]
  362. close $file
  363. set reg "source $black(actdir)/BlackTools.old.tcl"
  364. regsub $reg $data "source $black(actdir)/BlackTools.tcl" data
  365. set file [open $config w]
  366. puts $file $data
  367. close $file
  368. rehash
  369. if {[info exists ::update_hand]} {
  370. unset ::update_hand
  371. }
  372. if {[info exists ::update_chan]} {
  373. unset ::update_chan
  374. }
  375. blacktools:update_unsetflag
  376. blacktools:update_put $hand $chan 24 [list [return_time $userlang $dif]]
  377. blacktools:update_put $hand $chan 25 [list $black(backup_dir) $black(log_file)]
  378. blacktools:update_put $hand $chan 26 ""
  379. unset black(update_file_saved)
  380. if {[info exists black(update_topwords_files)]} {
  381. unset black(update_topwords_files)
  382. }
  383. file delete -force "$black(actdir)/BlackTools.old.tcl"
  384. }
  385. ###
  386. proc blacktools:update_restore_files {} {
  387. global black
  388. set files ""
  389. set files [glob -nocomplain -directory "$black(backup_dir)/BlackTools/FILES" "*.txt"]
  390. set counter 0
  391. if {![file isdirectory "$black(actdir)/BlackTools/FILES"]} {
  392. file mkdir "$black(actdir)/BlackTools/FILES"
  393. }
  394. if {[info exists black(update_topwords_files)]} {
  395. if {![file isdirectory "$black(actdir)/BlackTools/FILES/TOPWORDS"]} {
  396. file mkdir "$black(actdir)/BlackTools/FILES/TOPWORDS"
  397. }
  398. set top_files [glob -nocomplain -directory "$black(backup_dir)/BlackTools/FILES/TOPWORDS" "*.txt"]
  399. foreach f $top_files {
  400. incr counter
  401. set filename [file tail $f]
  402. file copy -force $f "$black(actdir)/BlackTools/FILES/TOPWORDS/$filename"
  403. }
  404. }
  405. foreach f $files {
  406. incr counter
  407. set filename [file tail $f]
  408. file copy -force $f "$black(actdir)/BlackTools/FILES/$filename"
  409. }
  410. return $counter
  411. }
  412. ###
  413. proc blacktools:update_set_time {num type} {
  414. global black
  415. set bt_file "$black(dirname)/BlackTools.tcl"
  416. set file [open $bt_file r]
  417. set data [read -nonewline $file]
  418. close $file
  419. set regexp_var2 "set black\\(update_time_check\\) \"(.*?)\""
  420. regexp -nocase $regexp_var2 $data -> found
  421. if {$type == 0} {
  422. return $found
  423. } else {
  424. regexp -nocase $regexp_var2 $data found_line
  425. set found_line [string map [list $found $num] $found_line]
  426. regsub $regexp_var2 $data $found_line data
  427. blacktools:update_data 1 $data
  428. }
  429. }
  430. ###
  431. proc blacktools:update_on_off {type} {
  432. global black
  433. set regexp_var2 "set black\\(update_type\\) \"(.*?)\""
  434. set bt_file "$black(dirname)/BlackTools.tcl"
  435. set file [open $bt_file r]
  436. set data [read -nonewline $file]
  437. close $file
  438. regexp -nocase $regexp_var2 $data found_line
  439. regexp -nocase $regexp_var2 $data -> found
  440. if {$type == 0 && $found == 0} {
  441. return 0
  442. }
  443. if {$type == 1 && $found == 1} {
  444. return 1
  445. }
  446. switch $type {
  447. 0 {
  448. set found_line [string map {"1" "0"} $found_line]
  449. regsub $regexp_var2 $data $found_line data
  450. blacktools:update_data 1 $data
  451. return 2
  452. }
  453. 1 {
  454. set found_line [string map {"0" "1"} $found_line]
  455. regsub $regexp_var2 $data $found_line data
  456. blacktools:update_data 1 $data
  457. return 3
  458. }
  459. }
  460. }
  461. ###
  462. proc blacktools:update_restore {data newdata} {
  463. global black
  464. set current_data $newdata
  465. set variables [regexp -all -inline {set black\((.+?)\)} $data]
  466. regsub -all {set black\((.+?)\)} $variables "" variables
  467. set var_nomodif "name author vers site current_modif"
  468. set var_counter 0
  469. foreach var $variables {
  470. if {$var == ""} {continue}
  471. if {[lsearch -nocase $var_nomodif $var] > -1} {continue}
  472. set regexp_var "set black\\($var\\) \\{(.*?)\\}"
  473. set regexp_var2 "set black\\($var\\) \"(.*?)\""
  474. regexp -nocase $regexp_var $data found_old
  475. regexp -nocase $regexp_var2 $data found_old_2
  476. if {[info exists found_old]} {
  477. set found_old [concat $found_old]
  478. regexp -nocase $regexp_var $newdata found_new
  479. if {[info exists found_new]} {
  480. if {[string equal -nocase $found_old $found_new]} {continue}
  481. incr var_counter
  482. regsub $regexp_var $current_data $found_old current_data
  483. unset found_new
  484. }
  485. unset found_old
  486. }
  487. }
  488. foreach var $variables {
  489. if {$var == ""} {continue}
  490. if {[lsearch -nocase $var_nomodif $var] > -1} {continue}
  491. set regexp_var2 "set black\\($var\\) \"(.*?)\""
  492. regexp -nocase $regexp_var2 $data found_old_2
  493. if {[info exists found_old_2]} {
  494. set found_old_2 [concat $found_old_2]
  495. regexp -nocase $regexp_var2 $newdata found_new_2
  496. if {[info exists found_new_2]} {
  497. if {[string equal -nocase $found_old_2 $found_new_2]} {continue}
  498. incr var_counter
  499. regsub $regexp_var2 $current_data $found_old_2 current_data
  500. unset found_new_2
  501. }
  502. unset found_old_2
  503. }
  504. }
  505. return [list $current_data $var_counter]
  506. }
  507. ###
  508. proc blacktools:update_data {type data} {
  509. global black
  510. set bt_file "$black(dirname)/BlackTools.tcl"
  511. if {![file exists $bt_file]} {
  512. return 0
  513. }
  514. if {$type == 0} {
  515. set file [open $bt_file r]
  516. set data [read -nonewline $file]
  517. close $file
  518. return $data
  519. } else {
  520. set file [open $bt_file w]
  521. puts $file $data
  522. close $file
  523. }
  524. }
  525. ###
  526. proc blacktools:update_verify {} {
  527. global black
  528. set link "https://raw.githubusercontent.com/tclscripts/BlackTools-TCL/master/VERSION"
  529. set ipq [http::config -useragent "lynx"]
  530. set error [catch {set ipq [::http::geturl $link -timeout 10000]} eror]
  531. set status [::http::status $ipq]
  532. if {$status != "ok"} {
  533. ::http::cleanup $ipq
  534. return -1
  535. }
  536. set getipq [::http::data $ipq]
  537. ::http::cleanup $ipq
  538. return $getipq
  539. }
  540. ###
  541. proc blacktools:update_userlang {nick} {
  542. global black
  543. if {$nick == ""} {return [string tolower $black(default_lang)]}
  544. set hand [nick2hand $nick]
  545. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  546. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  547. return $userlang
  548. }
  549. ###
  550. proc blacktools:update_put {nick chan num var} {
  551. global black
  552. set counter 0
  553. foreach v $var {
  554. incr counter
  555. set replace(%msg.${counter}%) $v
  556. }
  557. if {$nick != "" && $chan != ""} {
  558. set hand [nick2hand $nick]
  559. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  560. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  561. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  562. if {$getmethod == ""} { set getmethod "0" }
  563. set text [black:color:set "" $black(say.${userlang}.autoupdate.${num})]
  564. set reply [join $text]
  565. set reply [string map [array get replace] $reply]
  566. switch $getmethod {
  567. 0 {
  568. putserv "NOTICE $nick :$reply"
  569. }
  570. 1 {
  571. putserv "PRIVMSG $chan :$reply"
  572. }
  573. 2 {
  574. putserv "PRIVMSG $nick :$reply"
  575. }
  576. }
  577. } else {
  578. set lang [string tolower $black(default_lang)]
  579. set text [black:color:set "" $black(say.${lang}.autoupdate.${num})]
  580. set reply [join $text]
  581. set reply [string map [array get replace] $reply]
  582. }
  583. putlog "\[BT\] $reply"
  584. set file [open $black(log_file) a]
  585. puts $file $reply
  586. close $file
  587. }
  588. ###
  589. #https://wiki.tcl-lang.org/page/every
  590. proc blacktools:every {interval script} {
  591. global everyIds
  592. if {$interval eq {cancel}} {
  593. after cancel $everyIds($script)
  594. return
  595. }
  596. set everyIds($script) [after $interval [namespace code [info level 0]]]
  597. set rc [catch {uplevel #0 $script} result]
  598. if {$rc == [catch break]} {
  599. after cancel $everyIds($script)
  600. set rc 0
  601. } elseif {$rc == [catch continue]} {
  602. # Ignore - just consume the return code
  603. set rc 0
  604. }
  605. # TODO: Need better handling of errorInfo etc...
  606. return -code $rc $result
  607. }