BT.Seen.tcl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ############################# SEEN 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. proc seen:process {nick host hand chan chan1 what type gl} {
  17. global black botnick
  18. set cmd_status [btcmd:status $chan $hand "seen" 0]
  19. set number [scan $black(seenflood) %\[^:\]]
  20. set timer [scan $black(seenflood) %*\[^:\]:%s]
  21. set i 0
  22. set host_search 0
  23. set find_host ""
  24. set isonchan 0
  25. if {$cmd_status == "1"} {
  26. return
  27. }
  28. set split_host [split $host ":"]
  29. set the_host [lindex $split_host 1]
  30. set host [lindex $split_host 0]
  31. if {$the_host == ""} {
  32. set the_host $host
  33. }
  34. if {![validchan $chan] && $gl == "0"} {
  35. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  36. return
  37. }
  38. if {$host != "prv" && $gl == "0"} {
  39. if {![setting:get $chan seen]} {
  40. return
  41. }
  42. }
  43. set first_host ""
  44. set seenlist_all ""
  45. if {$what == ""} {
  46. switch $type {
  47. 0 {
  48. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "seen"
  49. }
  50. 1 {
  51. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "seen"
  52. }
  53. 2 {
  54. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "seen"
  55. }
  56. }
  57. return
  58. }
  59. if {![matchattr $hand nmo]} {
  60. foreach tmr [utimers] {
  61. if {[string match "*remove:seenflood:host $the_host $chan*" [join [lindex $tmr 1]]]} {
  62. killutimer [lindex $tmr 2]
  63. }
  64. }
  65. if {![info exists black(flood:$the_host:$chan)]} {
  66. set black(flood:$the_host:$chan) 0
  67. }
  68. incr black(flood:$the_host:$chan)
  69. utimer $timer [list remove:seenflood:host $the_host $chan]
  70. if {$black(flood:$the_host:$chan) >= "$number"} {
  71. blacktools:tell $nick $host $hand $chan $chan1 seen.5 none
  72. return
  73. }
  74. if {[string equal -nocase $what $nick] && ($chan1 == $chan)} { blacktools:tell $nick $host $hand $chan $chan1 seen.6 $nick
  75. return
  76. }
  77. }
  78. if {[string equal -nocase $what $botnick]} {
  79. blacktools:tell $nick $host $hand $chan $chan1 seen.4 $show_nick
  80. return
  81. }
  82. if {$gl == "0"} {
  83. if {[onchan $what $chan]} {
  84. if {[setting:get $chan seenreply]} {
  85. set isonchan 1
  86. set read_time [clock format [unixtime] -format %D-%H:%M:%S]
  87. blacktools:tell $what "prv" "" $chan $chan1 seen.39 "$what $nick $read_time"
  88. }
  89. }
  90. }
  91. set file [open $black(seen_file) r]
  92. set size [file size $black(seen_file)]
  93. set data [split [read $file $size] \n]
  94. close $file
  95. set what [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $what]
  96. if {[regexp {\!} $what]} {
  97. set first_host $what
  98. set host_search 1
  99. } else {
  100. set addsearch [join [split $what]]
  101. if {[regexp -- {^[a-zA-Z\|\[\]`^\{\}][a-zA-Z0-9\-_\|\[\]`^\{\}\\]*$} $addsearch]} {
  102. if {$gl == "0"} {
  103. if {[setting:get $chan seenreply]} {
  104. if {$isonchan == "0"} {
  105. seen:add_whosearch $nick $the_host $what $chan
  106. }
  107. }
  108. }
  109. }
  110. if {$gl == "1"} {
  111. set find [lsearch -all [string tolower $data] [string tolower "* *#* $what *"]]
  112. } else {
  113. set find [lsearch -all [string tolower $data] [string tolower "* $chan $what *"]]
  114. }
  115. if {[llength $find] > 99} {
  116. blacktools:tell $nick $host $hand $chan $chan1 seen.41 none
  117. return
  118. }
  119. if {[llength $find] > 0} {
  120. foreach i $find {
  121. set line [lindex $data $i]
  122. if {$line != ""} {
  123. set userentry [lindex [split $line] 2]
  124. set readhost [lindex [split $line] 3]
  125. set chanentry [lindex [split $line] 1]
  126. set time [lindex [split $line] 4]
  127. if {[string tolower $chanentry] != [string tolower $chan]} {
  128. set chanmode [getchanmode $chanentry]
  129. if {[string match -nocase "*p*" $chanmode] || [string match -nocase "*s*" $chanmode]} {
  130. blacktools:tell $nick $host $hand $chan $chan1 seen.18 "$what"
  131. return
  132. }
  133. }
  134. if {[info exists entry]} {
  135. if {[lsearch -exact [string tolower "$i%$userentry%$readhost%$time"] [string tolower $entry]] == "-1"} {
  136. lappend entry "$i%$userentry%$readhost%$time"
  137. }
  138. } else { lappend entry "$i%$userentry%$readhost%$time" }
  139. }
  140. }
  141. }
  142. array set seensort [list]
  143. array set seennick [list]
  144. if {![info exists entry]} {
  145. blacktools:tell $nick $host $hand $chan $chan1 seen.18 "$what"
  146. return
  147. }
  148. foreach e $entry {
  149. set split_e [split $e "%"]
  150. set read_time [lindex $split_e 3]
  151. set read_host [lindex $split_e 2]
  152. set read_pos [lindex $split_e 0]
  153. set seensort($read_time) "$read_host $read_pos"
  154. }
  155. foreach line [lsort -integer -decreasing -unique [array names seensort]] {
  156. lappend seenlist $seensort($line)
  157. }
  158. set first_entry [lindex $seenlist 0]
  159. set first_host [lindex $first_entry 0]
  160. set first_pos [lindex $first_entry 1]
  161. }
  162. if {$gl == "1"} {
  163. set find_other [lsearch -all [string tolower $data] [string tolower "* *#* * $first_host *"]]
  164. } else {
  165. set find_other [lsearch -all [string tolower $data] [string tolower "* $chan * $first_host *"]]
  166. }
  167. if {[llength $find_other] > 99} {
  168. blacktools:tell $nick $host $hand $chan $chan1 seen.41 none
  169. return
  170. }
  171. foreach k $find_other {
  172. set line [lindex $data $k]
  173. set userentry [lindex [split $line] 2]
  174. set time [lindex [split $line] 4]
  175. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  176. if {[info exists entry]} {
  177. if {[lsearch -exact [string tolower "$k%$userentry%$readhost%$time"] [string tolower $entry]] == "-1"} {
  178. lappend entry "$k%$userentry%$readhost%$time"
  179. }
  180. } else { lappend entry "$k%$userentry%$readhost%$time" }
  181. }
  182. if {![info exists entry] && $host_search == "1"} {
  183. blacktools:tell $nick $host $hand $chan $chan1 seen.18 "$what"
  184. return
  185. }
  186. if {$find_other != ""} {
  187. foreach e $entry {
  188. set split_e [split $e "%"]
  189. set read_time [lindex $split_e 3]
  190. set read_host [lindex $split_e 2]
  191. set read_pos [lindex $split_e 0]
  192. set seennick($read_time) $read_pos
  193. }
  194. foreach line [lsort -integer -decreasing -unique [array names seennick]] {
  195. lappend seenlist_all $seennick($line)
  196. }
  197. }
  198. seen:reply $seenlist_all $nick $host $hand $chan $chan1 $data
  199. }
  200. proc seen:add_whosearch {nick host what chan} {
  201. global black
  202. set time [unixtime]
  203. if {![info exists black(seen:searched:$chan)]} {
  204. set black(seen:searched:$chan) "$what%$nick%$host%$time"
  205. } elseif {$black(seen:searched:$chan) == ""} {
  206. set black(seen:searched:$chan) "$what%$nick%$host%$time"
  207. } else {
  208. set search_it [lsearch -nocase $black(seen:searched:$chan) "$what%*"]
  209. if {$search_it < 0} {
  210. lappend black(seen:searched:$chan) [join "$what%$nick%$host%$time"]
  211. }
  212. }
  213. }
  214. proc seen:reply:src {nick host chan} {
  215. global black
  216. if {![info exists black(seen:searched:$chan)]} {
  217. return
  218. }
  219. if {$black(seen:searched:$chan) == ""} { return }
  220. set search_it [lsearch -nocase $black(seen:searched:$chan) "$nick%*"]
  221. if {$search_it == "-1"} { return }
  222. set line [lindex $black(seen:searched:$chan) $search_it]
  223. set split_line [split $line "%"]
  224. set who [lindex $split_line 0]
  225. set bywho [lindex $split_line 1]
  226. set thehost [lindex [split $split_line] 2]
  227. set time [lindex [split $split_line] 3]
  228. set read_time [clock format $time -format %D-%H:%M:%S]
  229. blacktools:tell $nick "prv" "" $chan $chan seen.39 "$who $bywho!$thehost $read_time"
  230. set black(seen:searched:$chan) [lreplace $black(seen:searched:$chan) $search_it $search_it]
  231. }
  232. proc seen:reply {entry nick thehost hand chan chan1 data} {
  233. global black
  234. set results ""
  235. set onchan ""
  236. set nojointime 0
  237. set more_entry 0
  238. set lastmessage 0
  239. set isonchan 0
  240. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  241. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  242. set first_entry [lindex $entry 0]
  243. set line [lindex $data $first_entry]
  244. foreach e $entry {
  245. set getline [lindex $data $e]
  246. set getnick [lindex [split $getline] 2]
  247. lappend results $getnick
  248. }
  249. set results [lsort -unique $results]
  250. set latest_entry [lindex [split $line] 2]
  251. set num_results [llength $results]
  252. set type [lindex [split $line] 0]
  253. set chanentry [lindex [split $line] 1]
  254. set jointime [lindex [split $line] 5]
  255. set newnick [lindex [split $line] 6]
  256. set split_newnick [wsplit $newnick "%MSG%"]
  257. set newnick [concat [lindex $split_newnick 0]]
  258. set extra [join [lrange [split $line] 6 end]]
  259. set host [lindex [split $line] 3]
  260. set host [string trim $host "*!~"]
  261. set tm [lindex [split $line] 4]
  262. set split_it [wsplit $extra "%MSG%"]
  263. set message [concat [lindex $split_it 1]]
  264. set extra [concat [lindex $split_it 0]]
  265. set output [return_time $getlang [expr [unixtime] - $tm]]
  266. if {[regexp {[0-9]} $jointime]} {
  267. set staytime [expr [unixtime] - $jointime]
  268. set staytime [return_time $getlang [expr $tm - $jointime]]
  269. } else { set staytime 0 }
  270. set time [clock format $tm -format %D-%H:%M:%S]
  271. set replace(%latest%) $latest_entry
  272. set replace(%num%) $num_results
  273. set replace(%entry%) "[join $results]"
  274. set replace(%host%) "$host"
  275. set replace(%output%) "$output"
  276. set replace(%date%) "($time)"
  277. set replace(%newnick%) "$newnick"
  278. set replace(%userentry%) "$latest_entry"
  279. set replace(%chan%) "$chanentry"
  280. set replace(%reason%) "$extra"
  281. set replace(%staytime%) "$staytime"
  282. if {$jointime == "0"} { set staymsg "[string map [array get replace] $black(say.$getlang.seen.8)]"
  283. set replace(%staymsg%) "$staymsg"
  284. } else {
  285. set staymsg "[string map [array get replace] $black(say.$getlang.seen.9)]"
  286. set replace(%staymsg%) "$staymsg"
  287. }
  288. if {$staytime == "0"} { set nojointime 1 }
  289. if {$num_results > 1} { set more_entry 1 }
  290. if {$message != ""} { set lastmessage 1 }
  291. if {[onchan $latest_entry $chanentry]} { set isonchan 1 }
  292. if {$type == "NICKCHANGE"} {
  293. if {[onchan $newnick $chanentry]} { set isonchan 1 }
  294. }
  295. if {$more_entry == "1"} {
  296. switch $type {
  297. JOIN {
  298. if {$isonchan == "1"} {
  299. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  300. set replace(%nowon%) "$nowon"
  301. } else {
  302. set nowon "[string map [array get replace] $black(say.$getlang.seen.20)]"
  303. set replace(%nowon%) "$nowon"
  304. }
  305. if {$num_results >= 10} {
  306. set reply "[string map [array get replace] $black(say.$getlang.seen.35)]"
  307. } else {
  308. set reply "[string map [array get replace] $black(say.$getlang.seen.23)]"
  309. }
  310. }
  311. SPLIT {
  312. if {$num_results >= 10} {
  313. set reply "[string map [array get replace] $black(say.$getlang.seen.36)]"
  314. } else {
  315. set reply "[string map [array get replace] $black(say.$getlang.seen.24)]"
  316. }
  317. }
  318. PART {
  319. if {$num_results >= 10} {
  320. set reply "[string map [array get replace] $black(say.$getlang.seen.33)]"
  321. } else {
  322. set reply "[string map [array get replace] $black(say.$getlang.seen.21)]"
  323. }
  324. }
  325. KICK {
  326. if {$num_results >= 10} {
  327. set reply "[string map [array get replace] $black(say.$getlang.seen.37)]"
  328. } else {
  329. set reply "[string map [array get replace] $black(say.$getlang.seen.25)]"
  330. }
  331. }
  332. SIGN {
  333. if {$num_results >= 10} {
  334. set reply "[string map [array get replace] $black(say.$getlang.seen.34)]"
  335. } else {
  336. set reply "[string map [array get replace] $black(say.$getlang.seen.22)]"
  337. }
  338. }
  339. NICKCHANGE {
  340. if {$isonchan == "1"} {
  341. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  342. set replace(%nowon%) "$nowon"
  343. } else {
  344. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  345. set replace(%nowon%) "$nowon"
  346. }
  347. if {$num_results >= 10} {
  348. set reply "[string map [array get replace] $black(say.$getlang.seen.38)]"
  349. } else {
  350. set reply "[string map [array get replace] $black(say.$getlang.seen.26)]"
  351. }
  352. }
  353. LASTMSG {
  354. if {$isonchan == "1"} {
  355. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  356. set replace(%nowon%) "$nowon"
  357. } else {
  358. set nowon "[string map [array get replace] $black(say.$getlang.seen.20)]"
  359. set replace(%nowon%) "$nowon"
  360. }
  361. if {$num_results >= 10} {
  362. set reply "[string map [array get replace] $black(say.$getlang.seen.40)]"
  363. } else {
  364. set reply "[string map [array get replace] $black(say.$getlang.seen.30)]"
  365. }
  366. }
  367. }
  368. } else {
  369. switch $type {
  370. JOIN {
  371. if {$isonchan == "1"} {
  372. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  373. set replace(%nowon%) "$nowon"
  374. } else {
  375. set nowon "[string map [array get replace] $black(say.$getlang.seen.20)]"
  376. set replace(%nowon%) "$nowon"
  377. }
  378. set reply "[string map [array get replace] $black(say.$getlang.seen.14)]"
  379. }
  380. SPLIT {
  381. set reply "[string map [array get replace] $black(say.$getlang.seen.15)]"
  382. }
  383. PART {
  384. set reply "[string map [array get replace] $black(say.$getlang.seen.12)]"
  385. }
  386. SIGN {
  387. set reply "[string map [array get replace] $black(say.$getlang.seen.13)]"
  388. }
  389. KICK {
  390. set reply "[string map [array get replace] $black(say.$getlang.seen.16)]"
  391. }
  392. NICKCHANGE {
  393. if {$isonchan == "1"} {
  394. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  395. set replace(%nowon%) "$nowon"
  396. } else {
  397. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  398. set replace(%nowon%) "$nowon"
  399. }
  400. set reply "[string map [array get replace] $black(say.$getlang.seen.17)]"
  401. }
  402. LASTMSG {
  403. if {$isonchan == "1"} {
  404. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  405. set replace(%nowon%) "$nowon"
  406. } else {
  407. set nowon "[string map [array get replace] $black(say.$getlang.seen.20)]"
  408. set replace(%nowon%) "$nowon"
  409. }
  410. set reply "[string map [array get replace] $black(say.$getlang.seen.29)]"
  411. }
  412. }
  413. }
  414. set text [black:color:set "" $reply]
  415. blacktools:tell $nick $thehost $hand $chan $chan1 seen.27 $text
  416. if {$lastmessage == "1"} {
  417. set replace(%lastmsg%) $message
  418. set lastmsg "[string map [array get replace] $black(say.$getlang.seen.32)]"
  419. } else {
  420. set lastmsg "[string map [array get replace] $black(say.$getlang.seen.31)]"
  421. }
  422. set lastmsg [black:color:set "" $lastmsg]
  423. blacktools:tell $nick $thehost $hand $chan $chan1 seen.27 $lastmsg
  424. }
  425. proc seen:join {nick host hand chan} {
  426. global botnick black
  427. if {![validchan $chan]} { return }
  428. if {![setting:get $chan seen]} {
  429. return
  430. }
  431. if {[isbotnick $nick]} { return }
  432. if {[setting:get $chan seenreply]} {
  433. seen:reply:src $nick $host $chan
  434. }
  435. set time [unixtime]
  436. set host "*!$host"
  437. set type "JOIN"
  438. seen:save $nick $chan $host $type $time "NONE"
  439. }
  440. proc seen:part {nick host hand chan arg} {
  441. global botnick black
  442. if {![validchan $chan]} { return }
  443. if {![setting:get $chan seen]} {
  444. return
  445. }
  446. set time [unixtime]
  447. set staytimer "0"
  448. set type "PART"
  449. set reason [join [lrange [split $arg] 0 end]]
  450. if {$reason == ""} { set reason "N/A" }
  451. set host "*!$host"
  452. if {[isbotnick $nick]} { return }
  453. seen:save $nick $chan $host $type $time $reason
  454. }
  455. proc seen:sign {nick host hand chan arg} {
  456. global botnick black
  457. if {![validchan $chan]} { return }
  458. if {![setting:get $chan seen]} {
  459. return 0
  460. }
  461. set time [unixtime]
  462. set staytimer "0"
  463. set type "SIGN"
  464. set host "*!$host"
  465. set reason [join [lrange [split $arg] 0 end]]
  466. if {$reason == ""} { set reason "N/A" }
  467. if {[isbotnick $nick]} { return }
  468. seen:save $nick $chan $host $type $time $reason
  469. }
  470. proc seen:kick {nick host hand chan kicked reason} {
  471. global botnick black
  472. if {![validchan $chan]} { return }
  473. if {![setting:get $chan seen]} {
  474. return
  475. }
  476. set time [unixtime]
  477. set host [getchanhost $kicked $chan]
  478. set host "*!$host"
  479. set reason [join [lrange [split $reason] 1 end]]
  480. if {$reason == ""} { set reason "N/A" }
  481. if {[isbotnick $kicked]} { return }
  482. set type "KICK"
  483. seen:save $kicked $chan $host $type $time $reason
  484. }
  485. proc seen:split {nick host hand chan args} {
  486. global botnick black
  487. if {![validchan $chan]} { return }
  488. if {![setting:get $chan seen]} {
  489. return
  490. }
  491. set time [unixtime]
  492. set type "SPLIT"
  493. set host "*!$host"
  494. set reason [join [lrange [split $args] 0 end]]
  495. if {[isbotnick $nick]} { return }
  496. seen:save $nick $chan $host $type $time "NONE"
  497. }
  498. proc seen:changenick {nick host hand chan newnick} {
  499. global botnick black
  500. if {![validchan $chan]} { return }
  501. if {![setting:get $chan seen]} {
  502. return
  503. }
  504. set time [unixtime]
  505. set host "*!$host"
  506. set type "NICKCHANGE"
  507. if {[isbotnick $nick]} { return }
  508. seen:save $nick $chan $host $type $time $newnick
  509. }
  510. proc seen:lastmsg {nick host hand chan arg} {
  511. global black
  512. if {![validchan $chan]} { return }
  513. if {![setting:get $chan seen]} {
  514. return
  515. }
  516. set time [unixtime]
  517. set text [join [lrange [split $arg] 0 end]]
  518. set host "*!$host"
  519. set type "LASTMSG"
  520. if {[isbotnick $nick]} { return }
  521. seen:save $nick $chan $host $type $time $text
  522. }
  523. proc seen:save {nick chan host type time extra} {
  524. global black
  525. set staytimer 0
  526. if {$type != "JOIN" && $type != "LASTMSG"} {
  527. if {[info exists black(seen:entry:$nick:$chan)]} {
  528. set getextra [join [lrange [split $black(seen:entry:$nick:$chan)] 4 end]]
  529. set split_it [wsplit $getextra "%MSG%"]
  530. set message [concat [lindex $split_it 1]]
  531. if {$message != ""} {
  532. set extra [concat [lindex $split_it 0]]
  533. set extra "$extra%MSG%$message"
  534. }
  535. set get_type [lindex [split $black(seen:entry:$nick:$chan)] 0]
  536. if {$get_type == "JOIN"} {
  537. set staytimer [lindex [split $black(seen:entry:$nick:$chan)] 2]
  538. if {[regexp {[0-9]} $staytimer]} {
  539. set black(seen:entry:$nick:$chan) "$type $host $time $staytimer $extra"
  540. } else {
  541. set black(seen:entry:$nick:$chan) "$type $host $time 0 $extra"
  542. }
  543. } else {
  544. set black(seen:entry:$nick:$chan) "$type $host $time 0 $extra"
  545. }
  546. } else {
  547. set black(seen:entry:$nick:$chan) "$type $host $time 0 $extra"
  548. }
  549. } elseif {$type == "LASTMSG"} {
  550. if {[info exists black(seen:entry:$nick:$chan)]} {
  551. set staytimer [lindex [split $black(seen:entry:$nick:$chan)] 3]
  552. set jointime [lindex [split $black(seen:entry:$nick:$chan)] 2]
  553. set gettype [lindex [split $black(seen:entry:$nick:$chan)] 0]
  554. if {$gettype == "JOIN"} {
  555. set staytimer $jointime
  556. }
  557. if {[regexp {[0-9]} $staytimer]} {
  558. set black(seen:entry:$nick:$chan) "$type $host $time $staytimer NONE%MSG%$extra"
  559. } else {
  560. set black(seen:entry:$nick:$chan) "$type $host $time 0 NONE%MSG%$extra"
  561. }
  562. } else {
  563. set black(seen:entry:$nick:$chan) "$type $host $time $time NONE%MSG%$extra"
  564. }
  565. } else {
  566. if {[info exists black(seen:entry:$nick:$chan)]} {
  567. set getextra [join [lrange [split $black(seen:entry:$nick:$chan)] 4 end]]
  568. set split_it [wsplit $getextra "%MSG%"]
  569. set message [concat [lindex $split_it 1]]
  570. if {$message != ""} {
  571. set extra [concat [lindex $split_it 0]]
  572. set extra "$extra%MSG%$message"
  573. }
  574. }
  575. set black(seen:entry:$nick:$chan) "$type $host $time 0 $extra"
  576. }
  577. if {[info exists black(seen_list:$chan)]} {
  578. if {$black(seen_list:$chan) != ""} {
  579. set find_entry [lsearch -exact -nocase [split $black(seen_list:$chan)] $nick]
  580. if {$find_entry > -1} {
  581. return
  582. }
  583. set black(seen_list:$chan) "$black(seen_list:$chan) $nick"
  584. } else {
  585. set black(seen_list:$chan) $nick
  586. }
  587. } else {
  588. set black(seen_list:$chan) $nick
  589. }
  590. }
  591. proc seen:save_file {min hour day mon year} {
  592. global black
  593. set channels ""
  594. if {![file exists $black(seen_file)]} {return}
  595. foreach chan [channels] {
  596. if {[setting:get $chan seen]} {
  597. if {[info exists black(seen_list:$chan)]} {
  598. if {$black(seen_list:$chan) != ""} {
  599. lappend channels $chan
  600. }
  601. }
  602. }
  603. }
  604. if {$channels != ""} {
  605. seen:save_chan $channels 0
  606. }
  607. }
  608. proc seen:save_remove {entry chan} {
  609. global black
  610. set staytime 0
  611. set message ""
  612. set jointime 0
  613. set action ""
  614. set host [lindex [split $black(seen:entry:$entry:$chan)] 1]
  615. set type [lindex [split $black(seen:entry:$entry:$chan)] 0]
  616. set time [lindex [split $black(seen:entry:$entry:$chan)] 2]
  617. set thestay [lindex [split $black(seen:entry:$entry:$chan)] 3]
  618. set extra [join [lrange [split $black(seen:entry:$entry:$chan)] 4 end]]
  619. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  620. set temp "$black(tempdir)/seen_temp.$timestamp"
  621. set file [open $black(seen_file) "r"]
  622. set tempwrite [open $temp w]
  623. while {[gets $file line] != -1} {
  624. set read_type [lindex [split $line] 0]
  625. set read_chan [lindex [split $line] 1]
  626. set read_nick [lindex [split $line] 2]
  627. set enc_chan [encoding convertfrom utf-8 $read_chan]
  628. if {[string equal -nocase $chan $enc_chan] && [string equal -nocase $entry $read_nick]} {
  629. set staytime [lindex [split $line] 5]
  630. set readmsg [join [lrange [split $line] 6 end]]
  631. set jointime [lindex [split $line] 4]
  632. set action [lindex [split $line] 0]
  633. set split_it [wsplit $readmsg "%MSG%"]
  634. set message [concat [lindex $split_it 1]]
  635. if {[string match -nocase "*%MSG*" $extra]} {
  636. set message ""
  637. }
  638. continue
  639. } else {
  640. puts $tempwrite $line
  641. }
  642. }
  643. close $file
  644. if {$type != "JOIN"} {
  645. if {$action == "JOIN"} {
  646. if {$message != ""} {
  647. puts $tempwrite "$type $chan $entry $host $time $jointime $extra%MSG%$message"
  648. } else {
  649. puts $tempwrite "$type $chan $entry $host $time $jointime $extra"
  650. }
  651. } else {
  652. if {$message != ""} {
  653. puts $tempwrite "$type $chan $entry $host $time $staytime $extra%MSG%$message"
  654. } else {
  655. puts $tempwrite "$type $chan $entry $host $time $staytime $extra"
  656. }
  657. }
  658. } else {
  659. if {$message != ""} {
  660. puts $tempwrite "$type $chan $entry $host $time 0 $extra%MSG%$message"
  661. } else {
  662. puts $tempwrite "$type $chan $entry $host $time 0 $extra"
  663. }
  664. }
  665. close $tempwrite
  666. file rename -force $temp $black(seen_file)
  667. if {[info exists black(seen:entry:$entry:$chan)]} {
  668. unset black(seen:entry:$entry:$chan)
  669. }
  670. }
  671. proc seen:save_chan {channels num} {
  672. global black
  673. set chan [lindex $channels $num]
  674. set x 0
  675. if {[info exists black(seen_list:$chan)]} {
  676. while {$x <= [llength [split $black(seen_list:$chan)]]} {
  677. set entry [lindex [split $black(seen_list:$chan)] $x]
  678. if {[info exists black(seen:entry:$entry:$chan)]} {
  679. seen:save_remove $entry $chan
  680. }
  681. set x [expr $x + 1]
  682. }
  683. }
  684. if {[info exists black(seen_list:$chan)]} {
  685. unset black(seen_list:$chan)
  686. }
  687. set c [expr $num + 1]
  688. if {[lindex $channels $c] != ""} {
  689. seen:save_chan $channels $c
  690. }
  691. }
  692. proc seen:entry:delete {minute hour day month year} {
  693. global black username
  694. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  695. set temp "$black(tempdir)/seen_temp.$timestamp"
  696. set file [open $black(seen_file) "r"]
  697. set tempwrite [open $temp w]
  698. set counter 0
  699. while {[gets $file line] != -1} {
  700. set tm [lindex [split $line] 4]
  701. if {![regexp {[0-9]} $tm]} {
  702. continue
  703. }
  704. set read_days [expr [expr [expr [expr [unixtime] - $tm] / 60]] / 1440]
  705. if {$read_days >= $black(seen:expire:time)} {
  706. set counter [expr $counter + 1]
  707. continue
  708. } else {
  709. puts $tempwrite $line
  710. }
  711. }
  712. close $tempwrite
  713. close $file
  714. file rename -force $temp $black(seen_file)
  715. foreach chan [channels] {
  716. if {![info exists black(seen:searched:$chan)]} { continue }
  717. if {$black(seen:searched:$chan) == ""} {
  718. unset black(seen:searched:$chan)
  719. continue
  720. }
  721. foreach entry $black(seen:searched:$chan) {
  722. set split_entry [split $entry "%"]
  723. set time [lindex $split_entry 3]
  724. set read_days [expr [expr [expr [expr [unixtime] - $time] / 60]] / 1440]
  725. if {$read_days >= $black(seen:expire:seenreply)} {
  726. set search_it [lsearch -all [split $black(seen:searched:$chan)] $entry]
  727. if {$search_it > -1} {
  728. set black(seen:searched:$chan) [lreplace $black(seen:searched:$chan) $search_it $search_it]
  729. }
  730. }
  731. }
  732. }
  733. }