BT.TCL.tcl 8.0 KB

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