BT.TopWords.tcl 21 KB

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