BT.AutoUpdate.tcl 20 KB

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