BT.Anunt.tcl 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ######################## ANUNT/ADVERT 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 anunt:process {nick host hand chan chan1 who message number type} {
  16. global botnick black username
  17. set cmd_status [btcmd:status $chan $hand "anunt" 0]
  18. if {$cmd_status == "1"} {
  19. return
  20. }
  21. set show_message $message
  22. set num 0
  23. set temp_num 0
  24. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  25. return
  26. }
  27. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  28. return
  29. }
  30. if {$who == ""} {
  31. if {$type == "0"} {
  32. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "anunt"
  33. }
  34. if {$type == "1"} {
  35. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "anunt"
  36. }
  37. if {$type == "2"} {
  38. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "anunt"
  39. }
  40. return
  41. }
  42. if {![validchan $chan]} {
  43. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  44. return
  45. }
  46. switch $who {
  47. on {
  48. setting:set $chan +anunt ""
  49. blacktools:tell $nick $host $hand $chan $chan1 anunt.3 none
  50. foreach tmr [timers] {
  51. if {[string match "*anuntpublic:show*" [join [lindex $tmr 1]]]} {
  52. return
  53. }
  54. }
  55. set return_time [time_return_minute $black(anunttime)]
  56. timer $return_time anuntpublic:show
  57. }
  58. off {
  59. setting:set $chan -anunt ""
  60. blacktools:tell $nick $host $hand $chan $chan1 anunt.4 none
  61. }
  62. add {
  63. if {$message == ""} {
  64. if {$type == "0"} {
  65. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "anunt"
  66. }
  67. if {$type == "1"} {
  68. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "anunt"
  69. }
  70. if {$type == "2"} {
  71. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "anunt"
  72. }
  73. return
  74. }
  75. while {$temp_num == 0} {
  76. set get [find:num $num $chan "ANUNT"]
  77. if {$get == "$num"} {
  78. set num [expr $num + 1]
  79. } else { set temp_num 1 }
  80. }
  81. set file [open $black(add_file) a]
  82. set encoded [encoding convertto utf-8 $message]
  83. set enc_chan [encoding convertto utf-8 $chan]
  84. puts $file "$enc_chan ANUNT $num $encoded"
  85. close $file
  86. blacktools:tell $nick $host $hand $chan $chan1 anunt.5 $num
  87. blacktools:tell $nick $host $hand $chan $chan1 anunt.1 $show_message
  88. }
  89. list {
  90. array set anuntlist [list]
  91. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  92. set temp "$black(tempdir)/anunt_temp.$timestamp"
  93. set file [open $black(add_file) "r"]
  94. set w [read -nonewline $file]
  95. close $file
  96. set data [split $w "\n"]
  97. foreach line $data {
  98. set read_chan [lindex [split $line] 0]
  99. set enc_chan [encoding convertfrom utf-8 $read_chan]
  100. set read_type [lindex [split $line] 1]
  101. if {[string match -nocase $enc_chan $chan] && [string match -nocase $read_type "ANUNT"]} {
  102. set msg_num [lindex [split $line] 2]
  103. set message [join [lrange [split $line] 3 end]]
  104. lappend anuntlist($msg_num) $message
  105. }
  106. }
  107. set tempwrite [open $temp w]
  108. foreach msg [lsort -integer -increasing [array names anuntlist]] {
  109. puts $tempwrite "$msg [join $anuntlist($msg)]"
  110. }
  111. close $tempwrite
  112. set file [open $temp "r"]
  113. set w [read -nonewline $file]
  114. close $file
  115. set data [split $w "\n"]
  116. file delete $temp
  117. module:getinfo $nick $host $hand $chan $chan1 $type $data "anunt" "0" $number
  118. }
  119. del {
  120. if {![regexp {^[0-9]} $number]} {
  121. if {$type == "0"} {
  122. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "anunt"
  123. }
  124. if {$type == "1"} {
  125. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "anunt"
  126. }
  127. if {$type == "2"} {
  128. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "anunt"
  129. }
  130. return
  131. }
  132. set ret [find:num $number $chan "ANUNT"]
  133. if {$ret == 0} {
  134. blacktools:tell $nick $host $hand $chan $chan1 anunt.13 $number
  135. return
  136. }
  137. set file [open $black(add_file) "r"]
  138. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  139. set temp "$black(tempdir)/anunt_temp.$timestamp"
  140. set tempwrite [open $temp w]
  141. while {[gets $file line] != -1} {
  142. set read_num [lindex [split $line] 2]
  143. set read_chan [lindex [split $line] 0]
  144. set enc_chan [encoding convertfrom utf-8 $read_chan]
  145. set read_type [lindex [split $line] 1]
  146. if {[string equal $number $read_num] && [string equal -nocase $enc_chan $chan] && [string equal -nocase $read_type "ANUNT"]} {
  147. continue
  148. } else {
  149. puts $tempwrite $line
  150. }
  151. }
  152. close $tempwrite
  153. close $file
  154. file rename -force $temp $black(add_file)
  155. blacktools:tell $nick $host $hand $chan $chan1 anunt.10 $number
  156. }
  157. }
  158. }
  159. proc anuntpublic:show {} {
  160. global black
  161. set return_time [time_return_minute $black(anunttime)]
  162. set channels ""
  163. foreach chan [channels] {
  164. if {[validchan $chan]} {
  165. if {[setting:get $chan anunt]} {
  166. lappend channels $chan
  167. }
  168. }
  169. }
  170. if {$channels != ""} {
  171. anunt:time $channels 0
  172. timer $return_time anuntpublic:show
  173. }
  174. }
  175. proc anunt:time {channels counter} {
  176. global black
  177. set chan [lindex $channels $counter]
  178. set cc [expr $counter + 1]
  179. if {$chan != ""} {
  180. anunt:show $chan
  181. }
  182. if {[lindex $channels $cc] == ""} {
  183. return
  184. } else {
  185. anunt:time $channels $cc
  186. }
  187. }
  188. proc anunt:show {chan} {
  189. global black
  190. if {[info exists black(lastaction:$chan)]} {
  191. set total_anunt 0
  192. set unixtime [unixtime]
  193. set return_time [time_return_minute $black(anunttime)]
  194. set time [expr [expr [expr $return_time * $black(entry:shown)] * 60] + $unixtime]
  195. if {[expr $unixtime - $black(lastaction:$chan)] > [expr $time - $unixtime]} {
  196. return
  197. }
  198. } else { return }
  199. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  200. set temp_dir "$black(tempdir)/anunt_temp.$timestamp"
  201. if {![file exists $temp_dir]} {
  202. set file [open $temp_dir w]
  203. close $file
  204. }
  205. set file [open $black(add_file) "r"]
  206. set data [read -nonewline $file]
  207. close $file
  208. if {$data != ""} {
  209. set lines [split $data "\n"]
  210. set file [open $temp_dir "a"]
  211. foreach line $lines {
  212. set read_chan [lindex [split $line] 0]
  213. set enc_chan [encoding convertfrom utf-8 $read_chan]
  214. set read_type [lindex [split $line] 1]
  215. if {[string match -nocase $enc_chan $chan] && [string match -nocase $read_type "ANUNT"]} {
  216. puts $file [lrange [split $line] 3 end]
  217. set total_anunt [expr $total_anunt + 1]
  218. }
  219. }
  220. close $file
  221. }
  222. set file [open $temp_dir "r"]
  223. set data [read -nonewline $file]
  224. close $file
  225. if {$data != ""} {
  226. if {![info exists black(anuntshow:$chan)]} {
  227. set black(anuntshow:$chan) 0
  228. }
  229. set lines [split $data "\n"]
  230. set line [lindex $lines $black(anuntshow:$chan)]
  231. if {$line == ""} {
  232. set black(anuntshow:$chan) 0
  233. set line [lindex $lines $black(anuntshow:$chan)]
  234. }
  235. set split_line [split $line "~"]
  236. set black(anuntshow:$chan) [expr $black(anuntshow:$chan) + 1]
  237. foreach mes $split_line {
  238. set encoded [encoding convertto utf-8 $mes]
  239. if {$black(anunthow) == "1"} {
  240. puthelp "PRIVMSG $chan :\001ACTION \[$black(anuntshow:$chan)/$total_anunt\] [join $encoded]\001"
  241. } else {
  242. puthelp "PRIVMSG $chan :\[$black(anuntshow:$chan)/$total_anunt\] [join $encoded]"
  243. }
  244. }
  245. }
  246. file delete $temp_dir
  247. }
  248. ##############
  249. #########################################################################
  250. ## END ##
  251. #########################################################################