BT.TCL.tcl 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ############################### TCL #################################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. #########################################################################
  16. proc tcl:process {nick host hand chan chan1 type the_script who} {
  17. global black config
  18. set cmd_status [btcmd:status $chan $hand "tcl" 0]
  19. if {$cmd_status == "1"} {
  20. return
  21. }
  22. set current_tcl ""
  23. set tcl_exists 0
  24. if {$who == ""} {
  25. if {$type == "0"} {
  26. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  27. }
  28. if {$type == "1"} {
  29. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  30. }
  31. if {$type == "2"} {
  32. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  33. }
  34. return
  35. }
  36. switch $who {
  37. wget {
  38. if {$the_script == ""} {
  39. if {$type == "0"} {
  40. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  41. }
  42. if {$type == "1"} {
  43. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  44. }
  45. if {$type == "2"} {
  46. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  47. }
  48. return
  49. }
  50. if {![string match -nocase "*.tcl" $the_script]} {
  51. if {$type == "0"} {
  52. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  53. }
  54. if {$type == "1"} {
  55. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  56. }
  57. if {$type == "2"} {
  58. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  59. }
  60. return
  61. }
  62. set split_thescript [split $the_script "/"]
  63. foreach s $split_thescript {
  64. if {[string match -nocase "*.tcl" $s]} {
  65. if {[check:if:valid $s] == "1"} {
  66. set current_tcl $s
  67. set tcl_exists 1
  68. } else {
  69. set current_tcl $s
  70. }
  71. }
  72. }
  73. if {$tcl_exists == "1"} {
  74. blacktools:tell $nick $host $hand $chan $chan1 tcl.21 $s
  75. return
  76. }
  77. set wget [catch {exec wget $the_script -P $black(dirname)/ 2>/dev/null} wget_stat]
  78. if {[string match -nocase "*exited abnormally*" $wget_stat]} {
  79. blacktools:tell $nick $host $hand $chan $chan1 tcl.19 $current_tcl
  80. return
  81. }
  82. putserv "PRIVMSG $chan :$wget_stat"
  83. blacktools:tell $nick $host $hand $chan $chan1 tcl.20 $current_tcl
  84. }
  85. load {
  86. if {$the_script == ""} {
  87. if {$type == "0"} {
  88. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  89. }
  90. if {$type == "1"} {
  91. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  92. }
  93. if {$type == "2"} {
  94. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  95. }
  96. return
  97. }
  98. set black(tcl_load) [catch {source "$black(dirname)/$the_script"} black(tcl_load_error)]
  99. if {$black(tcl_load) == "1"} {
  100. blacktools:tell $nick $host $hand $chan $chan1 tcl.3 "$the_script [split $black(tcl_load_error)]"
  101. return
  102. }
  103. set file [open "$config" r]
  104. set w [read -nonewline $file]
  105. close $file
  106. set counter -1
  107. set data [split $w "\n"]
  108. set tcl_position -1
  109. set found_it 0
  110. foreach line $data {
  111. if {[string match -nocase "source $black(dirname)/*" $line]} {
  112. set the_split [split $line "/"]
  113. set script [lindex $the_split 1]
  114. if {[string equal -nocase $script $the_script]} {
  115. set found_it 1
  116. }
  117. }
  118. }
  119. if {$found_it == 1} {
  120. blacktools:tell $nick $host $hand $chan $chan1 tcl.4 $the_script
  121. return
  122. }
  123. set file [open "$config" a]
  124. puts $file "source $black(dirname)/$the_script"
  125. close $file
  126. rehash
  127. blacktools:tell $nick $host $hand $chan $chan1 tcl.5 $the_script
  128. }
  129. unload {
  130. if {$the_script == ""} {
  131. if {$type == "0"} {
  132. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  133. }
  134. if {$type == "1"} {
  135. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  136. }
  137. if {$type == "2"} {
  138. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  139. }
  140. return
  141. }
  142. if {[string match -nocase "*BlackTools*" $the_script]} {
  143. blacktools:tell $nick $host $hand $chan $chan1 tcl.18 none
  144. return
  145. }
  146. set file [open "$config" r]
  147. set w [read -nonewline $file]
  148. close $file
  149. set counter -1
  150. set data [split $w "\n"]
  151. set tcl_position -1
  152. set found_it 0
  153. foreach line $data {
  154. set counter [expr $counter + 1]
  155. if {[string match -nocase "*source $black(dirname)/*" $line]} {
  156. set the_split [split $line "/"]
  157. set script [lindex $the_split 1]
  158. if {[string equal -nocase $script $the_script]} {
  159. set found_it 1
  160. set tcl_position $counter
  161. }
  162. }
  163. }
  164. if {$found_it == 0} {
  165. blacktools:tell $nick $host $hand $chan $chan1 tcl.7 $the_script
  166. return
  167. }
  168. set delete [lreplace $data $tcl_position $tcl_position]
  169. set file [open "$config" "w"]
  170. puts $file [join $delete "\n"]
  171. close $file
  172. rehash
  173. blacktools:tell $nick $host $hand $chan $chan1 tcl.8 [split $the_script]
  174. }
  175. list {
  176. set the_files [glob -directory $black(dirname) "*.tcl"]
  177. set current_tcl ""
  178. set counter 0
  179. set found_tcl 0
  180. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  181. set temp "$black(tempdir)/tcl_temp.$timestamp"
  182. array set tcllist [list]
  183. set num_l 1
  184. set num 0
  185. foreach file $the_files {
  186. set split_file [split $file "/"]
  187. set the_file [lindex $split_file 1]
  188. if {[string match -nocase "*.tcl" $the_file]} {
  189. set found_tcl 1
  190. }
  191. set status [check:if:load $the_file]
  192. if {$status == "1"} {
  193. lappend tcllist(1) $the_file
  194. } else {
  195. lappend tcllist(2) $the_file
  196. }
  197. unset status
  198. }
  199. if {$found_tcl == "0"} {
  200. blacktools:tell $nick $host $hand $chan $chan1 tcl.2 "tcl"
  201. return
  202. }
  203. set tempwrite [open $temp w]
  204. foreach n [lsort -integer -increasing [array names tcllist]] {
  205. foreach tcl $tcllist($n) {
  206. set counter [expr $counter + 1]
  207. if {$n == "1"} {
  208. puts $tempwrite "$counter \002$tcl\002"
  209. } elseif {$n == "2"} {
  210. puts $tempwrite "$counter $tcl"
  211. }
  212. }
  213. }
  214. close $tempwrite
  215. set file [open $temp "r"]
  216. set w [read -nonewline $file]
  217. close $file
  218. set data [split $w "\n"]
  219. file delete $temp
  220. module:getinfo $nick $host $hand $chan $chan1 $type $data "tcl" "0" $the_script
  221. }
  222. info {
  223. if {$the_script == ""} {
  224. if {$type == "0"} {
  225. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  226. }
  227. if {$type == "1"} {
  228. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  229. }
  230. if {$type == "2"} {
  231. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  232. }
  233. return
  234. }
  235. set status_valid [check:if:valid $the_script]
  236. set status [check:if:load $the_script]
  237. if {$status_valid == "0"} {
  238. blacktools:tell $nick $host $hand $chan $chan1 tcl.12 $the_script
  239. return
  240. }
  241. if {$status == "0"} {
  242. blacktools:tell $nick $host $hand $chan $chan1 tcl.13 $the_script
  243. } else {
  244. blacktools:tell $nick $host $hand $chan $chan1 tcl.14 $the_script
  245. }
  246. }
  247. default {
  248. if {$type == "0"} {
  249. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "tcl"
  250. }
  251. if {$type == "1"} {
  252. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "tcl"
  253. }
  254. if {$type == "2"} {
  255. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "tcl"
  256. }
  257. return
  258. }
  259. }
  260. }
  261. proc check:if:valid {tcl} {
  262. global black
  263. set the_files [glob -directory $black(dirname) "*.tcl"]
  264. foreach file $the_files {
  265. set split_file [split $file "/"]
  266. set the_file [lindex $split_file 1]
  267. if {[string equal -nocase $tcl $the_file]} {
  268. return 1
  269. }
  270. }
  271. return 0
  272. }
  273. proc check:if:load {tcl} {
  274. global black config
  275. set file [open "$config" r]
  276. set w [read -nonewline $file]
  277. close $file
  278. set data [split $w "\n"]
  279. set return [lsearch -all -inline $data "source scripts/$tcl"]
  280. if {$return != ""} {
  281. return 1
  282. } else {
  283. return 0
  284. }
  285. }
  286. ##############
  287. #########################################################################
  288. ## END ##
  289. #########################################################################