BT.AutoBroadcast.tcl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ######################## AUTOBROADCAST 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 broadcast:process {nick host hand chan chan1 who message number type} {
  16. global botnick black username
  17. set cmd_status [btcmd:status $chan $hand "bt" 0]
  18. if {$cmd_status == "1"} {
  19. return
  20. }
  21. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  22. return
  23. }
  24. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  25. return
  26. }
  27. set show_message $message
  28. set btnum 0
  29. set lin 0
  30. set temp_num 0
  31. set sdir $black(status_file)
  32. if {$who == ""} {
  33. switch $type {
  34. 0 {
  35. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "bt"
  36. }
  37. 1 {
  38. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "bt"
  39. }
  40. 2 {
  41. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "bt"
  42. }
  43. }
  44. return
  45. }
  46. switch [string tolower $who] {
  47. on {
  48. set type1 "broadcastpublic:show ON"
  49. foreach tmr [timers] {
  50. if {[string match "*broadcastpublic:show*" [join [lindex $tmr 1]]]} {
  51. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.3 none
  52. return
  53. }
  54. }
  55. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.4 none
  56. set file [open $sdir "r"]
  57. set database [read -nonewline $file]
  58. close $file
  59. set data [split $database "\n"]
  60. foreach line $data {
  61. set lin [expr $lin +1]
  62. set who [lindex [split $line] 0]
  63. set stats [lindex [split $line] 1]
  64. if {[string match -nocase "broadcastpublic:show" $who]} {
  65. if {$line != ""} {
  66. set num [expr $lin - 1]
  67. set delete [lreplace $data $num $num]
  68. set files [open $sdir "w"]
  69. puts $files [join $delete "\n"]
  70. close $files
  71. }
  72. }
  73. }
  74. set file [open $sdir "r"]
  75. set data [read -nonewline $file]
  76. close $file
  77. if {$data == ""} {
  78. set files [open $sdir "w"]
  79. close $files
  80. }
  81. set file [open $sdir "a"]
  82. puts $file "$type1"
  83. close $file
  84. timer $black(bttime) broadcastpublic:show
  85. set broadcastpublic:show_running 1
  86. }
  87. off {
  88. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.5 none
  89. set type1 "broadcastpublic:show OFF"
  90. foreach tmr [timers] {
  91. if {[string match -nocase "*broadcastpublic:show*" [join [lindex $tmr 1]]]} {
  92. killtimer [lindex $tmr 2]
  93. }
  94. }
  95. set file [open $sdir "r"]
  96. set database [read -nonewline $file]
  97. close $file
  98. set data [split $database "\n"]
  99. foreach line $data {
  100. set lin [expr $lin +1]
  101. set who [lindex [split $line] 0]
  102. set stats [lindex [split $line] 1]
  103. if {[string match -nocase "broadcastpublic:show" $who]} {
  104. if {$line != ""} {
  105. set num [expr $lin - 1]
  106. set delete [lreplace $data $num $num]
  107. set files [open $sdir "w"]
  108. puts $files [join $delete "\n"]
  109. close $files
  110. }
  111. }
  112. }
  113. set file [open $sdir "r"]
  114. set data [read -nonewline $file]
  115. close $file
  116. if {$data == ""} {
  117. set files [open $sdir "w"]
  118. close $files
  119. }
  120. set file [open $sdir "a"]
  121. puts $file "$type1"
  122. close $file
  123. if {[info exists broadcastpublic:show_running]} {
  124. unset broadcastpublic:show_running
  125. }
  126. }
  127. add {
  128. if {$message == ""} {
  129. switch $type {
  130. 0 {
  131. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "bt"
  132. }
  133. 1 {
  134. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "bt"
  135. }
  136. 2 {
  137. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "bt"
  138. }
  139. }
  140. return
  141. }
  142. while {$temp_num == 0} {
  143. set get [find:num $btnum "-" "AUTOBROADCAST"]
  144. if {$get == "$btnum"} {
  145. set btnum [expr $btnum + 1]
  146. } else { set temp_num 1 }
  147. }
  148. set file [open $black(add_file) a]
  149. set encoded [encoding convertto utf-8 $message]
  150. puts $file "- AUTOBROADCAST $btnum $encoded"
  151. close $file
  152. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.6 $btnum
  153. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.1 $show_message
  154. }
  155. list {
  156. array set btlist [list]
  157. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  158. set temp "$black(tempdir)/bt_temp.$timestamp"
  159. set file [open $black(add_file) "r"]
  160. set w [read -nonewline $file]
  161. close $file
  162. set data [split $w "\n"]
  163. if {$data == ""} { blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.8 none
  164. return
  165. }
  166. foreach line $data {
  167. set read_type [lindex [split $line] 1]
  168. if {[string equal -nocase $read_type "AUTOBROADCAST"]} {
  169. set msg_num [lindex [split $line] 2]
  170. set message [join [lrange [split $line] 3 end]]
  171. lappend btlist($msg_num) $message
  172. }
  173. }
  174. set tempwrite [open $temp "w"]
  175. foreach msg [lsort -integer -increasing [array names btlist]] {
  176. puts $tempwrite "$msg [join $btlist($msg)]"
  177. }
  178. close $tempwrite
  179. set file [open $temp "r"]
  180. set w [read -nonewline $file]
  181. close $file
  182. set data [split $w "\n"]
  183. file delete $temp
  184. module:getinfo $nick $host $hand $chan $chan1 $type $data "autobroadcast" "0" $number
  185. }
  186. del {
  187. if {![regexp {^[0-9]} $number]} {
  188. switch $type {
  189. 0 {
  190. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "bt"
  191. }
  192. 1 {
  193. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "bt"
  194. }
  195. 2 {
  196. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "bt"
  197. }
  198. }
  199. return
  200. }
  201. set ret [find:num $number "-" "AUTOBROADCAST"]
  202. if {$ret == 0} {
  203. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.2 $number
  204. return
  205. }
  206. set file [open $black(add_file) "r"]
  207. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  208. set temp "$black(tempdir)/bt_temp.$timestamp"
  209. set tempwrite [open $temp w]
  210. while {[gets $file line] != -1} {
  211. set read_num [lindex [split $line] 2]
  212. set read_type [lindex [split $line] 1]
  213. if {[string equal $number $read_num] && [string equal $read_type "AUTOBROADCAST"]} {
  214. continue
  215. } else {
  216. puts $tempwrite $line
  217. }
  218. }
  219. close $tempwrite
  220. close $file
  221. file rename -force $temp $black(add_file)
  222. blacktools:tell $nick $host $hand $chan $chan1 autobroadcast.11 $number
  223. }
  224. }
  225. }
  226. proc broadcastpublic:show {} {
  227. global black
  228. if {![info exists black(broadcast:count)]} {
  229. set black(broadcast:count) 0
  230. }
  231. set channels ""
  232. set line ""
  233. set file [open $black(add_file) "r"]
  234. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  235. set temp "$black(tempdir)/bt_temp.$timestamp"
  236. set tempwrite [open $temp w]
  237. while {[gets $file line] != -1} {
  238. set read_type [lindex [split $line] 1]
  239. if {[string equal $read_type "AUTOBROADCAST"]} {
  240. set read_message [lrange [split $line] 3 end]
  241. puts $tempwrite $read_message
  242. }
  243. }
  244. close $tempwrite
  245. close $file
  246. set file [open $temp "r"]
  247. set w [read -nonewline $file]
  248. close $file
  249. set data [split $w "\n"]
  250. if {$data != ""} {
  251. set line [lindex $data $black(broadcast:count)]
  252. if {$line == ""} {
  253. set black(broadcast:count) 0
  254. set line [lindex $data $black(broadcast:count)]
  255. }
  256. set black(broadcast:count) [expr $black(broadcast:count) +1]
  257. foreach chan [channels] {
  258. if {[validchan $chan] && [isdynamic $chan] && (![setting:get $chan silent])} {
  259. lappend channels $chan
  260. }
  261. }
  262. } else { file delete $temp }
  263. file delete $temp
  264. if {$channels != "" && $line != ""} {
  265. broadcast:act $channels 0 $line
  266. }
  267. timer $black(bttime) broadcastpublic:show
  268. }
  269. proc broadcast:act {channels counter line} {
  270. global black
  271. set split_line [split $line "~"]
  272. set chan [lindex $channels $counter]
  273. set cc [expr $counter + 1]
  274. set notshow 0
  275. if {$chan != ""} {
  276. if {[info exists black(lastaction:$chan)]} {
  277. set unixtime [unixtime]
  278. set return_time [time_return_minute $black(bttime)]
  279. set time [expr [expr [expr $return_time * $black(entry:shown)] * 60] + $unixtime]
  280. if {[expr $unixtime - $black(lastaction:$chan)] > [expr $time - $unixtime]} {
  281. set notshow 1
  282. }
  283. }
  284. if {$notshow == "0"} {
  285. foreach mes $split_line {
  286. set message [join [lrange [split $mes] 0 end]]
  287. set encoded [encoding convertfrom utf-8 $message]
  288. if {$black(bthow) == "1"} {
  289. puthelp "PRIVMSG $chan :\001ACTION [join $encoded]\001"
  290. } else {
  291. puthelp "PRIVMSG $chan :[join $encoded]"
  292. }
  293. }
  294. }
  295. }
  296. if {[lindex $channels $cc] == ""} {
  297. return
  298. } else {
  299. utimer 5 [list broadcast:act $channels $cc $line]
  300. }
  301. }
  302. ##############
  303. #########################################################################
  304. ## END ##
  305. #########################################################################