BT.Seen.tcl 22 KB

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