BT.Anunt.tcl 8.1 KB

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