BT.AutoBroadcast.tcl 8.8 KB

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