BT.Anunt.tcl 8.1 KB

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