BT.TopWords.tcl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ########################### TOPWORDS 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-script ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. #########################################################################
  16. if {[info exists black(backup_update)]} {
  17. set black(backdir) $black(backup_dir)
  18. } else {
  19. set black(backdir) $black(dirname)
  20. }
  21. proc topwords:delexcept {user nick host hand chan chan1} {
  22. global black
  23. set user [join $user]
  24. set show_user [split $user]
  25. if {[onchan $user $chan]} {
  26. set getuser [nick2hand $user]
  27. if {$getuser != "*"} {
  28. set user $getuser
  29. }
  30. }
  31. if {![validuser $user]} {
  32. blacktools:tell $nick $host $hand $chan $chan1 gl.nomem none
  33. return
  34. }
  35. if {![matchattr $user "-|w" $chan]} {
  36. blacktools:tell $nick $host $hand $chan $chan1 topwords.20 "$show_user"
  37. return
  38. }
  39. chattr $user -|-w $chan
  40. blacktools:tell $nick $host $hand $chan $chan1 topwords.21 "$show_user"
  41. }
  42. proc topwords:addexcept {user nick host hand chan chan1} {
  43. global black
  44. set user [join $user]
  45. set show_user [split $user]
  46. if {![onchan $user $chan]} {
  47. blacktools:tell $nick $host $hand $chan $chan1 gl.usernotonchan $show_user
  48. return
  49. }
  50. set mask [return_mask [return_host_num "topwords" $chan [getchanhost $user $chan]] [getchanhost $user $chan] $user]
  51. if {[validuser $user]} {
  52. set user $user
  53. } else {
  54. if {[nick2hand $user] == "*"} {
  55. set user $user
  56. } else {
  57. set user [nick2hand $user]
  58. }
  59. }
  60. foreach usr [userlist] {
  61. set hst [getuser $usr hosts]
  62. foreach hhost $hst {
  63. if {[string match -nocase $hhost $mask] && (![string match -nocase $usr $user])} {
  64. blacktools:tell $nick $host $hand $chan $chan1 add.5 [split $usr]
  65. set user $usr
  66. set show_user [split $usr]
  67. }
  68. }
  69. }
  70. if {[validuser $user]} {
  71. if {[matchattr $user -|w $chan]} {
  72. blacktools:tell $nick $host $hand $chan $chan1 topwords.17 $show_user
  73. return
  74. }
  75. chattr $user -|+w $chan
  76. blacktools:tell $nick $host $hand $chan $chan1 topwords.15 $show_user
  77. } else {
  78. adduser $user $mask
  79. chattr $user -|+w $chan
  80. blacktools:tell $nick $host $hand $chan $chan1 topwords.16 "$show_user $mask"
  81. }
  82. }
  83. proc topwords:process {nick host hand chan chan1 cmd type next} {
  84. global botnick black username
  85. set topwords_file "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  86. set cmd_status [btcmd:status $chan $hand "topwords" 0]
  87. if {$cmd_status == "1"} {
  88. return
  89. }
  90. if {[matchattr $hand q]} { blacktools:tell $nick $host $hand $chan $chan1 gl.glsuspend none
  91. return
  92. }
  93. if {[matchattr $hand -|q $chan]} { blacktools:tell $nick $host $hand $chan $chan1 gl.suspend none
  94. return
  95. }
  96. if {![setting:get $chan topwords]} {
  97. return
  98. }
  99. if {![validchan $chan]} {
  100. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  101. return
  102. }
  103. if {![file isdirectory "$black(backdir)/BlackTools/FILES/TOPWORDS"]} {
  104. blacktools:tell $nick $host $hand $chan $chan1 topwords.7 none
  105. return
  106. }
  107. if {![file exists $topwords_file]} {
  108. blacktools:tell $nick $host $hand $chan $chan1 topwords.7 none
  109. return
  110. }
  111. if {[string equal -nocase $cmd "list"]} {
  112. set list [userlist "-|w" $chan]
  113. blacktools:tell $nick $host $hand $chan $chan1 topwords.18 "none"
  114. if {$list == ""} {set list "NONE"}
  115. blacktools:tell $nick $host $hand $chan $chan1 topwords.19 "$list"
  116. return
  117. }
  118. if {[regexp {:} $cmd]} {
  119. set split_cmd [split $cmd ":"]
  120. set theuser [lindex $split_cmd 1]
  121. if {[onchan $theuser $chan]} {
  122. set mask [return_mask [return_host_num "topwords" $chan [getchanhost $theuser $chan]] [getchanhost $theuser $chan] $theuser]
  123. } else {
  124. set mask ""
  125. }
  126. topwords:user $nick $host $hand $chan $chan1 $cmd $mask $type
  127. return
  128. }
  129. if {[string equal -nocase $cmd "del"]} {
  130. if {$next == ""} {
  131. switch $type {
  132. 0 {
  133. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "topwords"
  134. }
  135. 1 {
  136. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "topwords"
  137. }
  138. 2 {
  139. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "topwords"
  140. }
  141. }
  142. return
  143. }
  144. topwords:delexcept $next $nick $host $hand $chan $chan1
  145. return
  146. }
  147. if {[string equal -nocase $cmd "add"]} {
  148. if {$next == ""} {
  149. switch $type {
  150. 0 {
  151. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "topwords"
  152. }
  153. 1 {
  154. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "topwords"
  155. }
  156. 2 {
  157. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "topwords"
  158. }
  159. }
  160. return
  161. }
  162. topwords:addexcept $next $nick $host $hand $chan $chan1
  163. return
  164. }
  165. if {[string equal -nocase $cmd "reset"]} {
  166. set reset [topwords:reset $chan]
  167. if {$reset == "1"} {
  168. blacktools:tell $nick $host $hand $chan $chan1 topwords.8 none
  169. } else {
  170. blacktools:tell $nick $host $hand $chan $chan1 topwords.10 none
  171. }
  172. return
  173. }
  174. array set topwordslist [list]
  175. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  176. set temp "$black(tempdir)/topwords_temp.$timestamp"
  177. set counter 0
  178. set file [open $topwords_file r]
  179. while {[gets $file line] != -1} {
  180. set read_chan [lindex [split $line] 0]
  181. set enc_chan [encoding convertfrom utf-8 $read_chan]
  182. if {[string match -nocase $enc_chan $chan]} {
  183. if {[string equal -nocase $cmd "total"]} {
  184. set words_count [lindex [split $line] 6]
  185. } elseif {[string equal -nocase $cmd "week"]} {
  186. set words_count [lindex [split $line] 7]
  187. } else {
  188. set words_count [lindex [split $line] 8]
  189. }
  190. set read_nick [lindex [split $line] 1]
  191. if {$words_count > 0} {
  192. lappend topwordslist($words_count) $read_nick
  193. }
  194. }
  195. }
  196. close $file
  197. set tempwrite [open $temp w]
  198. set latestuser ""
  199. set latesttime 0
  200. foreach words [lsort -integer -decreasing [array names topwordslist]] {
  201. set counter [expr $counter + 1]
  202. foreach user $topwordslist($words) {
  203. puts $tempwrite "$user $words $counter"
  204. }
  205. }
  206. close $tempwrite
  207. set file [open $temp r]
  208. set w [read -nonewline $file]
  209. close $file
  210. set data [split $w "\n"]
  211. file delete $temp
  212. if {$data == ""} {
  213. if {[string equal -nocase $cmd "total"]} {
  214. blacktools:tell $nick $host $hand $chan $chan1 topwords.7 none
  215. } elseif {[string equal -nocase $cmd "week"]} {
  216. blacktools:tell $nick $host $hand $chan $chan1 topwords.23 none
  217. } else {
  218. blacktools:tell $nick $host $hand $chan $chan1 topwords.14 none
  219. }
  220. return
  221. }
  222. if {[string equal -nocase $cmd "total"]} {
  223. module:getinfo $nick $host $hand $chan $chan1 $type $data "topwords:total" "0" $next
  224. } elseif {[string equal -nocase $cmd "week"]} {
  225. module:getinfo $nick $host $hand $chan $chan1 $type $data "topwords:week" "0" $next
  226. } else {
  227. module:getinfo $nick $host $hand $chan $chan1 $type $data "topwords" "0" $next
  228. }
  229. }
  230. proc topwords:user {nick host hand chan chan1 user mask type1} {
  231. global black username
  232. set found_it 0
  233. set split_user [split $user ":"]
  234. set theuser [lindex $split_user 1]
  235. set type [lindex $split_user 0]
  236. set topwords_file "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  237. switch $type {
  238. reset {
  239. set reset [topwords:user:reset $theuser $chan]
  240. if {$reset == "1"} {
  241. blacktools:tell $nick $host $hand $chan $chan1 topwords.29 $theuser
  242. } else {
  243. blacktools:tell $nick $host $hand $chan $chan1 topwords.4 $theuser
  244. }
  245. }
  246. default {
  247. set file [open $topwords_file r]
  248. set size [file size $topwords_file]
  249. set data [split [read $file $size] \n]
  250. close $file
  251. foreach line $data {
  252. set read_chan [lindex [split $line] 0]
  253. set enc_chan [encoding convertfrom utf-8 $read_chan]
  254. set read_user [lindex [split $line] 1]
  255. set read_mask [lindex [split $line] 2]
  256. if {$mask != ""} {
  257. if {[string equal -nocase $enc_chan $chan] && [string match -nocase $read_mask $mask]} {
  258. set found_it 1
  259. set read_user [lindex [split $line] 1]
  260. set get_lines [lrange [split $line] 3 5]
  261. set get_words [lrange [split $line] 6 8]
  262. set get_chars [lrange [split $line] 9 11]
  263. set get_actions [lrange [split $line] 12 14]
  264. set get_smiles [lrange [split $line] 15 17]
  265. set get_ques [lrange [split $line] 18 20]
  266. show:topwords:user $nick $host $hand $chan $chan1 $read_user $read_mask $get_lines $get_words $get_chars $get_actions $get_smiles $get_ques $type
  267. continue
  268. }
  269. } elseif {[string equal -nocase $enc_chan $chan] && [string equal -nocase $read_user $theuser]} {
  270. set found_it 1
  271. set read_mask [lindex [split $line] 2]
  272. set get_lines [lrange [split $line] 3 5]
  273. set get_words [lrange [split $line] 6 8]
  274. set get_chars [lrange [split $line] 9 11]
  275. set get_actions [lrange [split $line] 12 14]
  276. set get_smiles [lrange [split $line] 15 17]
  277. set get_ques [lrange [split $line] 18 20]
  278. show:topwords:user $nick $host $hand $chan $chan1 $read_user $read_mask $get_lines $get_words $get_chars $get_actions $get_smiles $get_ques $type
  279. continue
  280. }
  281. }
  282. if {$found_it == "0"} {
  283. blacktools:tell $nick $host $hand $chan $chan1 topwords.27 $theuser
  284. }
  285. }
  286. }
  287. }
  288. proc topwords:user:reset {user chan} {
  289. global black username
  290. set topwords_file "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  291. set found_it 0
  292. set file [open $topwords_file r]
  293. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  294. set temp "$black(tempdir)/othermodule_temp.$timestamp"
  295. set tempwrite [open $temp w]
  296. while {[gets $file line] != -1} {
  297. set getuser [lindex [split $line] 1]
  298. if {[string equal -nocase $getuser $user]} {
  299. set found_it 1
  300. continue
  301. } else {
  302. puts $tempwrite $line
  303. }
  304. }
  305. close $tempwrite
  306. close $file
  307. file rename -force $temp $topwords_file
  308. return $found_it
  309. }
  310. proc show:topwords:user {nick host hand chan chan1 read_user read_mask get_lines get_words get_chars get_actions get_smiles get_ques type} {
  311. global black
  312. set place [getactivplace $read_mask $chan $type]
  313. set split_place [split $place ":"]
  314. set total [lindex $split_place 1]
  315. set theplace [lindex $split_place 0]
  316. switch $type {
  317. total {
  318. set lines [lindex $get_lines 0]
  319. set words [lindex $get_words 0]
  320. set chars [lindex $get_chars 0]
  321. set actions [lindex $get_actions 0]
  322. set smiles [lindex $get_smiles 0]
  323. set ques [lindex $get_ques 0]
  324. blacktools:tell $nick $host $hand $chan $chan1 topwords.22 "$read_user $read_mask $words $lines $chars $smiles $actions $ques $theplace $total"
  325. }
  326. week {
  327. set lines [lindex $get_lines 1]
  328. set words [lindex $get_words 1]
  329. set chars [lindex $get_chars 1]
  330. set actions [lindex $get_actions 1]
  331. set smiles [lindex $get_smiles 1]
  332. set ques [lindex $get_ques 1]
  333. blacktools:tell $nick $host $hand $chan $chan1 topwords.28 "$read_user $read_mask $words $lines $chars $smiles $actions $ques $theplace $total"
  334. }
  335. user {
  336. set lines [lindex $get_lines 2]
  337. set words [lindex $get_words 2]
  338. set chars [lindex $get_chars 2]
  339. set actions [lindex $get_actions 2]
  340. set smiles [lindex $get_smiles 2]
  341. set ques [lindex $get_ques 2]
  342. blacktools:tell $nick $host $hand $chan $chan1 topwords.3 "$read_user $read_mask $words $lines $chars $smiles $actions $ques $theplace $total"
  343. }
  344. }
  345. }
  346. proc getactivplace {host chan type} {
  347. global black username
  348. set topwords_file "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  349. array set activlist [list]
  350. set counter 0
  351. set all_count 0
  352. set place 0
  353. set file [open $topwords_file r]
  354. while {[gets $file line] != -1} {
  355. set read_chan [lindex [split $line] 0]
  356. set enc_chan [encoding convertfrom utf-8 $read_chan]
  357. if {[string equal -nocase $enc_chan $chan]} {
  358. set all_count [expr $all_count + 1]
  359. if {[string equal -nocase $type "user"]} {
  360. set nr_words [lindex [split $line] 8]
  361. } elseif {[string equal -nocase $type "week"]} {
  362. set nr_words [lindex [split $line] 7]
  363. } elseif {[string equal -nocase $type "total"]} {
  364. set nr_words [lindex [split $line] 6]
  365. }
  366. set read_host [lindex [split $line] 2]
  367. lappend activlist($nr_words) $read_host
  368. }
  369. }
  370. close $file
  371. foreach h [lsort -integer -decreasing [array names activlist]] {
  372. set counter [expr $counter + 1]
  373. if {[string equal -nocase $activlist($h) $host]} {
  374. set place $counter
  375. }
  376. }
  377. if {$place == "0"} { set place $counter }
  378. return $place:$all_count
  379. }
  380. proc topwords:module {nick host hand chan arg} {
  381. global black username
  382. set arg [split $arg]
  383. set topwords_file "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  384. set mask [return_mask [return_host_num "topwords" $chan $host] $host $nick]
  385. set handle [nick2hand $nick]
  386. set topwords_run 0
  387. if {[setting:get $chan topwords]} {
  388. if {![file isdirectory "$black(backdir)/BlackTools/FILES/TOPWORDS/"]} {
  389. file mkdir "$black(backdir)/BlackTools/FILES/TOPWORDS/"
  390. }
  391. if {![file exists $topwords_file]} {
  392. set file [open $topwords_file w]
  393. close $file
  394. }
  395. foreach tmr [timers] {
  396. if {[string match "*blacktools:timers:runtime*" [join [lindex $tmr 1]]]} {
  397. set topwords_run 1
  398. }
  399. }
  400. if {$topwords_run == "0"} {
  401. return
  402. }
  403. if {[isbotnick $nick]} {
  404. return
  405. }
  406. if {[validuser $handle]} {
  407. if {[matchattr $handle -|w $chan]} {
  408. return
  409. }
  410. }
  411. if {[setting:get $chan accessonly]} {
  412. if {![validuser $handle]} {
  413. return
  414. }
  415. if {![matchattr $handle $black(exceptflags) $chan]} {
  416. return
  417. }
  418. }
  419. if {![info exist black(topwords:$chan:list)]} {
  420. set black(topwords:$chan:list) $mask
  421. } else {
  422. if {[lsearch -exact -nocase $black(topwords:$chan:list) $mask] < 0} {
  423. lappend black(topwords:$chan:list) $mask
  424. }
  425. }
  426. set lines 1
  427. set last_message [unixtime]
  428. set smile_num 0
  429. set ques_num 0
  430. if {[string equal -nocase $hand "ACTION"]} {
  431. set actions 1
  432. } else { set actions 0 }
  433. set arg [regsub -all {\s+} $arg " "]
  434. set words [llength $arg]
  435. set chars [string length $arg]
  436. if {[regexp {[?]} $arg]} {
  437. set ques_num [expr $ques_num + 1]
  438. }
  439. foreach text $arg {
  440. set smile_stat [topwords:smile $text]
  441. if {$smile_stat != "-1"} {
  442. set smile_num [expr $smile_num + 1]
  443. }
  444. }
  445. if {![info exists black(topwords:$chan:$mask)]} {
  446. set black(topwords:$chan:$mask) "$nick $lines $words $chars $actions $smile_num $ques_num"
  447. } else {
  448. set get_lines [lindex [split $black(topwords:$chan:$mask)] 1]
  449. set get_words [lindex [split $black(topwords:$chan:$mask)] 2]
  450. set get_chars [lindex [split $black(topwords:$chan:$mask)] 3]
  451. set get_actions [lindex [split $black(topwords:$chan:$mask)] 4]
  452. set get_smiles [lindex [split $black(topwords:$chan:$mask)] 5]
  453. set get_ques [lindex [split $black(topwords:$chan:$mask)] 6]
  454. set black(topwords:$chan:$mask) "$nick [expr $get_lines + $lines] [expr $get_words + $words] [expr $get_chars + $chars] [expr $get_actions + $actions] [expr $get_smiles + $smile_num] [expr $get_ques + $ques_num]"
  455. }
  456. }
  457. }
  458. proc topwords:save:channels {chans} {
  459. global black
  460. foreach chan $chans {
  461. if {[validchan $chan]} {
  462. lappend channels $chan
  463. }
  464. }
  465. if {$channels != ""} {
  466. topwords:time $channels 0
  467. }
  468. }
  469. proc topwords:time {channels counter} {
  470. global black
  471. set chan [lindex $channels $counter]
  472. set cc [expr $counter + 1]
  473. if {$chan != ""} {
  474. topwords:module:save $chan
  475. }
  476. if {[lindex $channels $cc] == ""} {
  477. return
  478. } else {
  479. topwords:time $channels $cc
  480. }
  481. }
  482. proc topwords:module:save {chan} {
  483. global black username
  484. if {![info exists black(topwords:$chan:list)]} {
  485. return
  486. }
  487. if {$black(topwords:$chan:list) == ""} {
  488. return
  489. }
  490. set topwords_file "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  491. if {![file exists $topwords_file]} {
  492. return
  493. }
  494. if {$black(topwords:$chan:list) == ""} {
  495. return
  496. }
  497. topwords:remove_it $topwords_file $chan $black(topwords:$chan:list) 0
  498. }
  499. proc topwords:remove_it {files chan list position} {
  500. global black
  501. set mask [lindex $list $position]
  502. if {$mask != ""} {
  503. if {[info exists black(topwords:$chan:$mask)]} {
  504. set file [open $files r]
  505. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  506. set temp "$black(tempdir)/topwords_temp.$timestamp"
  507. set tempwrite [open $temp w]
  508. set found_mask 0
  509. set counter 0
  510. set get_nick [lindex [split $black(topwords:$chan:$mask)] 0]
  511. set curr_lines [lindex [split $black(topwords:$chan:$mask)] 1]
  512. set curr_words [lindex [split $black(topwords:$chan:$mask)] 2]
  513. set curr_chars [lindex [split $black(topwords:$chan:$mask)] 3]
  514. set curr_actions [lindex [split $black(topwords:$chan:$mask)] 4]
  515. set curr_smiles [lindex [split $black(topwords:$chan:$mask)] 5]
  516. set curr_ques [lindex [split $black(topwords:$chan:$mask)] 6]
  517. while {[gets $file line] != -1} {
  518. set read_chan [lindex [split $line] 0]
  519. set read_host [lindex [split $line] 2]
  520. set enc_chan [encoding convertfrom utf-8 $read_chan]
  521. if {[string equal -nocase $enc_chan $chan] && [string equal -nocase $mask $read_host]} {
  522. set found_mask 1
  523. set get_lines [lrange [split $line] 3 5]
  524. set get_words [lrange [split $line] 6 8]
  525. set get_chars [lrange [split $line] 9 11]
  526. set get_actions [lrange [split $line] 12 14]
  527. set get_smiles [lrange [split $line] 15 17]
  528. set get_ques [lrange [split $line] 18 20]
  529. continue
  530. } else {
  531. puts $tempwrite $line
  532. }
  533. }
  534. if {$found_mask == "0"} {
  535. puts $tempwrite "$chan $get_nick $mask $curr_lines $curr_lines $curr_lines $curr_words $curr_words $curr_words $curr_chars $curr_chars $curr_chars $curr_actions $curr_actions $curr_actions $curr_smiles $curr_smiles $curr_smiles $curr_ques $curr_ques $curr_ques"
  536. } else {
  537. puts $tempwrite "$chan $get_nick $mask [expr $curr_lines + [lindex $get_lines 0]] [expr $curr_lines + [lindex $get_lines 1]] [expr $curr_lines + [lindex $get_lines 2]] [expr $curr_words + [lindex $get_words 0]] [expr $curr_words + [lindex $get_words 1]] [expr $curr_words + [lindex $get_words 2]] [expr $curr_chars + [lindex $get_chars 0]] [expr $curr_chars + [lindex $get_chars 1]] [expr $curr_chars + [lindex $get_chars 2]] [expr $curr_actions + [lindex $get_actions 0]] [expr $curr_actions + [lindex $get_actions 1]] [expr $curr_actions + [lindex $get_actions 2]] [expr $curr_smiles + [lindex $get_smiles 0]] [expr $curr_smiles + [lindex $get_smiles 1]] [expr $curr_smiles + [lindex $get_smiles 2]] [expr $curr_ques + [lindex $get_ques 0]] [expr $curr_ques + [lindex $get_ques 1]] [expr $curr_ques + [lindex $get_ques 2]]"
  538. }
  539. close $file
  540. close $tempwrite
  541. file rename -force $temp $files
  542. if {[info exists black(topwords:$chan:$mask)]} {
  543. unset black(topwords:$chan:$mask)
  544. }
  545. set place [lsearch -exact -nocase $black(topwords:$chan:list) $mask]
  546. if {$place > 0} {
  547. set black(topwords:$chan:list) [lreplace $black(topwords:$chan:list) $place $place]
  548. }
  549. }
  550. }
  551. set counter [expr $position + 1]
  552. if {[lindex $list $counter] != ""} {
  553. topwords:remove_it $files $chan $list $counter
  554. }
  555. }
  556. proc topwords:module:me {nick host hand chan keyword arg} {
  557. global black
  558. if {[string equal -nocase $keyword "ACTION"]} {
  559. topwords:module $nick $host "ACTION" $chan $arg
  560. }
  561. }
  562. proc topwords:reset {chan} {
  563. global black username
  564. set found_entry 0
  565. if {[file exists "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"]} {
  566. set found_entry 1
  567. set file [open "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt" w]
  568. close $file
  569. }
  570. return $found_entry
  571. }
  572. proc topwords:delete {chan} {
  573. global black username
  574. if {$black(chanremove_all) == "0"} {
  575. return
  576. }
  577. if {[file exists "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"]} {
  578. file delete "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  579. }
  580. }
  581. proc topwords:day:reset {minute hour day month year} {
  582. global black username
  583. set week_reset 0
  584. if {[clock format [clock seconds] -format "%w"] == 0} {
  585. set week_reset 1
  586. }
  587. foreach chan [channels] {
  588. set tpfile "$black(backdir)/BlackTools/FILES/TOPWORDS/$username.$chan.txt"
  589. if {[setting:get $chan topwords]} {
  590. if {![file exists $tpfile]} {
  591. continue
  592. }
  593. set file [open $tpfile r]
  594. set size [file size $tpfile]
  595. set data [split [read $file $size] \n]
  596. close $file
  597. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  598. set temp "$black(tempdir)/topwords_temp.$timestamp"
  599. set tempwrite [open $temp w]
  600. foreach line $data {
  601. if {$line != ""} {
  602. set get_chan [lindex [split $line] 0]
  603. set get_nick [lindex [split $line] 1]
  604. set get_host [lindex [split $line] 2]
  605. set curr_lines [lrange [split $line] 3 5]
  606. set curr_words [lrange [split $line] 6 8]
  607. set curr_chars [lrange [split $line] 9 11]
  608. set curr_actions [lrange [split $line] 12 14]
  609. set curr_smiles [lrange [split $line] 15 17]
  610. set curr_ques [lrange [split $line] 18 20]
  611. if {$week_reset == "1"} {
  612. puts $tempwrite "$get_chan $get_nick $get_host [lindex $curr_lines 0] 0 0 [lindex $curr_words 0] 0 0 [lindex $curr_chars 0] 0 0 [lindex $curr_actions 0] 0 0 [lindex $curr_smiles 0] 0 0 [lindex $curr_ques 0] 0 0"
  613. } else {
  614. puts $tempwrite "$get_chan $get_nick $get_host [lindex $curr_lines 0] [lindex $curr_lines 1] 0 [lindex $curr_words 0] [lindex $curr_words 1] 0 [lindex $curr_chars 0] [lindex $curr_chars 1] 0 [lindex $curr_actions 0] [lindex $curr_actions 1] 0 [lindex $curr_smiles 0] [lindex $curr_smiles 1] 0 [lindex $curr_ques 0] [lindex $curr_ques 1] 0"
  615. }
  616. }
  617. }
  618. close $tempwrite
  619. file rename -force $temp $tpfile
  620. }
  621. }
  622. }
  623. proc topwords:smile {text} {
  624. global black
  625. set found_it [regexp -inline {(:|8|;)(-|o)?(>|D|\)|\]|\})} $text]
  626. if {$found_it != ""} {
  627. return 1
  628. } else {
  629. return -1
  630. }
  631. }
  632. ##############
  633. #########################################################################
  634. ## END ##
  635. #########################################################################