BT.AutoBroadcast.tcl 9.0 KB

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