BT.TCL.tcl 8.4 KB

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