BT.Seen.tcl 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. ## Online Help : irc://irc.undernet.org/tcl-help ##
  11. ## #TCL-HELP / UnderNet ##
  12. ## You can ask in english or romanian ##
  13. ## ##
  14. #########################################################################
  15. proc seen:get_lastmessage {nick host hand chan arg} {
  16. global black username
  17. set seen_lastmessage_dir $black(seen_details)
  18. set host "*!$host"
  19. set time [unixtime]
  20. set no_staytime 0
  21. set arg [join [split $arg]]
  22. set type "LASTMSG"
  23. set found_entry 0
  24. set lin 0
  25. set found_entry 0
  26. if {![validchan $chan]} { return }
  27. if {![setting:get $chan seen] && ![setting:get $chan seenlastmsg]} {
  28. return
  29. }
  30. if {![file exists $seen_lastmessage_dir]} {
  31. set file [open $seen_lastmessage_dir w]
  32. close $file
  33. }
  34. set file [open $seen_lastmessage_dir "r"]
  35. set database [read -nonewline $file]
  36. close $file
  37. set data [split $database "\n"]
  38. foreach line $data {
  39. set lin [expr $lin +1]
  40. set hostentry [lindex [split $line] 3]
  41. set chanentry [lindex [split $line] 1]
  42. if {[string equal -nocase $host $hostentry] && [string match -nocase $chanentry $chan]} {
  43. set userentry [lindex [split $line] 2]
  44. set found_entry 1
  45. set who "LASTMSG $chanentry $userentry $hostentry $time $arg"
  46. if {$line != ""} {
  47. set num [expr $lin - 1]
  48. set delete [lreplace $data $num $num]
  49. set files [open $seen_lastmessage_dir "w"]
  50. puts $files [join $delete "\n"]
  51. close $files
  52. }
  53. }
  54. }
  55. if {$found_entry == "1"} {
  56. set file [open $seen_lastmessage_dir "r"]
  57. set data [read -nonewline $file]
  58. close $file
  59. if {$data == ""} {
  60. set files [open $seen_lastmessage_dir "w"]
  61. close $files
  62. }
  63. set file [open $seen_lastmessage_dir "a"]
  64. puts $file $who
  65. close $file
  66. } else {
  67. set who "LASTMSG $chan $nick $host $time $arg"
  68. set file [open $seen_lastmessage_dir "a"]
  69. puts $file $who
  70. close $file
  71. }
  72. }
  73. proc seen:save:2 {nick chan host type time staytimer reason} {
  74. global black
  75. set seendir $black(seen_file)
  76. set lin 0
  77. set j 0
  78. set who "$type $chan $nick $host $time $staytimer $reason"
  79. set details ""
  80. set file [open $seendir "r"]
  81. set database [read -nonewline $file]
  82. close $file
  83. set data [split $database "\n"]
  84. foreach line $data {
  85. set lin [expr $lin +1]
  86. set userentry [lindex [split $line] 2]
  87. set chanentry [lindex [split $line] 1]
  88. if {[string equal -nocase $userentry $nick] && [string match -nocase $chanentry $chan]} {
  89. set joined [lindex [split $line] 0]
  90. if {$joined == "JOIN"} {
  91. set j [lindex [split $line] 4]
  92. if {![regexp {^[0-9]} $j] || ($j == "")} {
  93. set j 0
  94. }
  95. }
  96. set who "$type $chan $nick $host $time $j $reason"
  97. if {$line != ""} {
  98. set num [expr $lin - 1]
  99. set delete [lreplace $data $num $num]
  100. set files [open $seendir "w"]
  101. puts $files [join $delete "\n"]
  102. close $files
  103. }
  104. }
  105. }
  106. set file [open $seendir "r"]
  107. set data [read -nonewline $file]
  108. close $file
  109. if {$data == ""} {
  110. set files [open $seendir "w"]
  111. close $files
  112. }
  113. set file [open $seendir "a"]
  114. puts $file "$who"
  115. close $file
  116. }
  117. proc seen:save:1 {nick chan host type time staytimer} {
  118. global black
  119. set seendir $black(seen_file)
  120. set lin 0
  121. set who "$type $chan $nick $host $time $staytimer NONE"
  122. set file [open $seendir "r"]
  123. set database [read -nonewline $file]
  124. close $file
  125. set data [split $database "\n"]
  126. foreach line $data {
  127. set lin [expr $lin +1]
  128. set userentry [lindex [split $line] 2]
  129. set chanentry [lindex [split $line] 1]
  130. if {[string equal -nocase $userentry $nick] && [string match -nocase $chanentry $chan]} {
  131. if {$line != ""} {
  132. set num [expr $lin - 1]
  133. set delete [lreplace $data $num $num]
  134. set files [open $seendir "w"]
  135. puts $files [join $delete "\n"]
  136. close $files
  137. }
  138. }
  139. }
  140. set file [open $seendir "r"]
  141. set data [read -nonewline $file]
  142. close $file
  143. if {$data == ""} {
  144. set files [open $seendir "w"]
  145. close $files
  146. }
  147. set file [open $seendir "a"]
  148. puts $file "$who"
  149. close $file
  150. }
  151. proc seen:join {nick host hand chan} {
  152. global botnick black
  153. set seendir $black(seen_file)
  154. if {![file exists $seendir]} {
  155. set file [open $seendir w]
  156. close $file
  157. }
  158. if {![validchan $chan]} { return }
  159. if {![setting:get $chan seen]} {
  160. return
  161. }
  162. if {[setting:get $chan seenreply]} {
  163. seen:reply:src $nick $host $chan
  164. }
  165. if {[isbotnick $nick]} { return }
  166. set time [unixtime]
  167. set host "*!$host"
  168. set type "JOIN"
  169. set staytimer "0"
  170. seen:save:1 $nick $chan $host $type $time $staytimer
  171. }
  172. proc seen:part {nick host hand chan arg} {
  173. global botnick black
  174. set seendir $black(seen_file)
  175. if {![file exists $seendir]} {
  176. set file [open $seendir w]
  177. close $file
  178. }
  179. if {![validchan $chan]} { return }
  180. if {![setting:get $chan seen]} {
  181. return
  182. }
  183. set time [unixtime]
  184. set staytimer "0"
  185. set type "PART"
  186. set reason [join [lrange [split $arg] 0 end]]
  187. if {$reason == ""} { set reason "N/A" }
  188. set host "*!$host"
  189. if {[isbotnick $nick]} { return }
  190. seen:save:2 $nick $chan $host $type $time $staytimer $reason
  191. }
  192. proc seen:sign {nick host hand chan arg} {
  193. global botnick black
  194. set seendir $black(seen_file)
  195. if {![file exists $seendir]} {
  196. set file [open $seendir w]
  197. close $file
  198. }
  199. if {![validchan $chan]} { return }
  200. if {![setting:get $chan seen]} {
  201. return 0
  202. }
  203. set time [unixtime]
  204. set staytimer "0"
  205. set type "SIGN"
  206. set host "*!$host"
  207. set reason [join [lrange [split $arg] 0 end]]
  208. if {$reason == ""} { set reason "N/A" }
  209. if {[isbotnick $nick]} { return }
  210. seen:save:2 $nick $chan $host $type $time $staytimer $reason
  211. }
  212. proc seen:kick {nick host hand chan kicked reason} {
  213. global botnick black
  214. set seendir $black(seen_file)
  215. if {![file exists $seendir]} {
  216. set file [open $seendir w]
  217. close $file
  218. }
  219. if {![validchan $chan]} { return }
  220. if {![setting:get $chan seen]} {
  221. return
  222. }
  223. set lin 0
  224. set j 0
  225. set time [unixtime]
  226. set hosted [getchanhost $kicked $chan]
  227. set hosted "*!$hosted"
  228. set reason [join [lrange [split $reason] 1 end]]
  229. if {$reason == ""} { set reason "No Reason" }
  230. if {[isbotnick $kicked]} { return }
  231. set who "KICK $chan $kicked $hosted $time 0 $reason"
  232. set file [open $seendir "r"]
  233. set database [read -nonewline $file]
  234. close $file
  235. set data [split $database "\n"]
  236. foreach line $data {
  237. set lin [expr $lin +1]
  238. set userentry [lindex [split $line] 2]
  239. set chanentry [lindex [split $line] 1]
  240. if {[string equal -nocase $kicked $userentry] && [string match -nocase $chanentry $chan]} {
  241. set joined [lindex [split $line] 0]
  242. if {$joined == "JOIN"} {
  243. set j [lindex [split $line] 4]
  244. if {![regexp {^[0-9]} $j] || ($j == "")} {
  245. set j 0
  246. }
  247. }
  248. set who "KICK $chan $kicked $hosted $time $j $reason"
  249. if {$line != ""} {
  250. set num [expr $lin - 1]
  251. set delete [lreplace $data $num $num]
  252. set files [open $seendir "w"]
  253. puts $files [join $delete "\n"]
  254. close $files
  255. }
  256. }
  257. }
  258. set file [open $seendir "r"]
  259. set data [read -nonewline $file]
  260. close $file
  261. if {$data == ""} {
  262. set files [open $seendir "w"]
  263. close $files
  264. }
  265. set file [open $seendir "a"]
  266. puts $file "$who"
  267. close $file
  268. }
  269. proc seen:split {nick host hand chan args} {
  270. global botnick black
  271. set seendir $black(seen_file)
  272. if {![file exists $seendir]} {
  273. set file [open $seendir w]
  274. close $file
  275. }
  276. if {![validchan $chan]} { return }
  277. if {![setting:get $chan seen]} {
  278. return
  279. }
  280. set time [unixtime]
  281. set staytimer "0"
  282. set type "SPLIT"
  283. set host "*!$host"
  284. set reason [join [lrange [split $args] 0 end]]
  285. if {[isbotnick $nick]} { return }
  286. seen:save:2 $nick $chan $host $type $time $staytimer $reason
  287. }
  288. proc seen:changenick {nick host hand chan newnick} {
  289. global botnick black
  290. set seendir $black(seen_file)
  291. if {![file exists $seendir]} {
  292. set file [open $seendir w]
  293. close $file
  294. }
  295. if {![validchan $chan]} { return }
  296. if {![setting:get $chan seen]} {
  297. return
  298. }
  299. set time [unixtime]
  300. set host "*!$host"
  301. set staytimer "0"
  302. set type "NICKCHANGE"
  303. if {[isbotnick $nick]} { return }
  304. seen:save:2 $nick $chan $host $type $time $staytimer $newnick
  305. }
  306. proc seenpublic {nick host hand chan arg} {
  307. global black lastbind
  308. set type 0
  309. set chan1 "$chan"
  310. set isbackchan ""
  311. set what [lindex [split $arg] 0]
  312. if {[regexp {^[&#]} $what] && [matchattr $hand nmo|MAOV $chan]} {
  313. set chan1 "$chan"
  314. set chan "$what"
  315. set what [lindex [split $arg] 1]
  316. }
  317. set return [blacktools:mychar $lastbind $hand]
  318. if {$return == "0"} {
  319. return
  320. }
  321. foreach c [channels] {
  322. set backchan [join [setting:get $c backchan]]
  323. if {[string equal -nocase $backchan $chan]} {
  324. set isbackchan $c
  325. set chan1 $chan
  326. }
  327. }
  328. if {$isbackchan != ""} {
  329. seen:process $nick $host $hand $isbackchan $chan1 $what $type
  330. } else {
  331. seen:process $nick $host $hand $chan $chan1 $what $type
  332. }
  333. }
  334. proc seen:process {nick host hand chan chan1 what type} {
  335. global black botnick
  336. set cmd_status [btcmd:status $chan $hand "seen" 0]
  337. if {$cmd_status == "1"} {
  338. return
  339. }
  340. set seendir $black(seen_file)
  341. set test ""
  342. set test_host ""
  343. set show_nick $nick
  344. if {![matchattr $hand nmo]} {
  345. if {![validchan $chan]} {
  346. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  347. return
  348. }
  349. }
  350. if {![setting:get $chan seen]} {
  351. return
  352. }
  353. if {[string match -nocase "*prv*" $host]} {
  354. set split_host [split $host ":"]
  355. set the_host [lindex $split_host 0]
  356. set host [lindex $split_host 1]
  357. } else {
  358. set the_host $host
  359. }
  360. set number [scan $black(seenflood) %\[^:\]]
  361. set timer [scan $black(seenflood) %*\[^:\]:%s]
  362. set i 0
  363. if {$what == ""} {
  364. switch $type {
  365. 0 {
  366. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "seen"
  367. }
  368. 1 {
  369. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "seen"
  370. }
  371. 2 {
  372. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "seen"
  373. }
  374. }
  375. return
  376. }
  377. if {![validchan $chan]} {
  378. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  379. return
  380. }
  381. if {![matchattr $hand nmo]} {
  382. foreach tmr [utimers] {
  383. if {[string match "*remove:seenflood:host $the_host $chan*" [join [lindex $tmr 1]]]} {
  384. killutimer [lindex $tmr 2]
  385. }
  386. }
  387. if {![info exists black(flood:$the_host:$chan)]} {
  388. set black(flood:$the_host:$chan) 0
  389. }
  390. incr black(flood:$the_host:$chan)
  391. utimer $timer [list remove:seenflood:host $the_host $chan]
  392. if {$black(flood:$the_host:$chan) >= "$number"} {
  393. blacktools:tell $nick $host $hand $chan $chan1 seen.5 none
  394. return
  395. }
  396. if {[string equal -nocase $what $nick] && ($chan1 == $chan)} { blacktools:tell $nick $host $hand $chan $chan1 seen.6 $nick
  397. return
  398. }
  399. }
  400. if {[string equal -nocase $what $botnick]} {
  401. blacktools:tell $nick $host $hand $chan $chan1 seen.4 $show_nick
  402. return
  403. }
  404. if {[onchan $what $chan]} {
  405. blacktools:tell $nick $host $hand $chan $chan1 seen.7 $what
  406. if {[setting:get $chan seenreply]} {
  407. set read_time [clock format [unixtime] -format %D-%H:%M:%S]
  408. blacktools:tell $what "prv" "" $chan $chan1 seen.39 "$what $show_nick!$host $read_time"
  409. }
  410. return
  411. }
  412. set file [open $seendir "r"]
  413. set database [read -nonewline $file]
  414. close $file
  415. set data [split $database "\n"]
  416. set what [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $what]
  417. if {[matchattr $hand nmo]} {
  418. if {[regexp {\!} $what]} {
  419. set test_host [lsearch -all [string tolower $data] [string tolower "* *#* * $what *"]]
  420. } else {
  421. if {[regexp -- {^[a-zA-Z\|\[\]`^\{\}][a-zA-Z0-9\-_\|\[\]`^\{\}\\]*$} $what]} {
  422. seen:add_whosearch $nick $host $what $chan
  423. }
  424. set test [lsearch -all [string tolower $data] [string tolower "* *#* $what *"]]
  425. }
  426. } else {
  427. if {[regexp {\!} $what]} {
  428. set test_host [lsearch -all [string tolower $data] [string tolower "* $chan * $what *"]]
  429. } else {
  430. if {[regexp -- {^[a-zA-Z\|\[\]`^\{\}][a-zA-Z0-9\-_\|\[\]`^\{\}\\]*$} $what]} {
  431. seen:add_whosearch $nick $host $what $chan
  432. }
  433. set test [lsearch -all [string tolower $data] [string tolower "* $chan $what *"]]
  434. }
  435. }
  436. if {[string length $test] > 0} {
  437. foreach i $test {
  438. set line [lindex $data $i]
  439. if {$line != ""} {
  440. set userentry [lindex [split $line] 2]
  441. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  442. set chanentry [lindex [split $line] 1]
  443. if {[info exists entry]} {
  444. if {[lsearch -exact [string tolower "$i:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  445. lappend entry "$i:$userentry:$readhost"
  446. }
  447. } else { lappend entry "$i:$userentry:$readhost" }
  448. }
  449. }
  450. }
  451. if {[string length $test_host] > 0 && [string length $test] == 0} {
  452. foreach j $test_host {
  453. set line [lindex $data $j]
  454. if {$line != ""} {
  455. set userentry [lindex [split $line] 2]
  456. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  457. set chanentry [lindex [split $line] 1]
  458. if {[info exists entry]} {
  459. if {[lsearch -exact [string tolower "$j:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  460. lappend entry "$j:$userentry:$readhost"
  461. }
  462. } else { lappend entry "$j:$userentry:$readhost" }
  463. }
  464. }
  465. }
  466. if {[info exists entry]} {
  467. set split_entry [split $entry ":"]
  468. set get_host [lindex [split $split_entry] 2]
  469. set get_line [lindex [split $split_entry] 0]
  470. set get_nick [lindex [split $split_entry] 1]
  471. }
  472. #checking other entries
  473. if {[info exists get_host]} {
  474. if {[string length $test_host] < 1} {
  475. if {[matchattr $hand nmo]} {
  476. set test [lsearch -all [string tolower $data] [string tolower "* *#* * $get_host *"]]
  477. } else {
  478. set test [lsearch -all [string tolower $data] [string tolower "* $chan * $get_host *"]]
  479. }
  480. foreach k $test {
  481. if {$k != $get_line} {
  482. set line [lindex $data $k]
  483. set userentry [lindex [split $line] 2]
  484. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  485. if {[info exists entry]} {
  486. if {[lsearch -exact [string tolower "$k:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  487. lappend entry "$k:$userentry:$readhost"
  488. }
  489. } else { lappend entry "$k:$userentry:$readhost" }
  490. }
  491. }
  492. }
  493. }
  494. #
  495. if {[info exists entry]} {
  496. seen:reply $entry $nick $hand $chan $chan1 $data "1" $host
  497. } else {
  498. blacktools:tell $nick $host $hand $chan $chan1 seen.18 $what
  499. }
  500. }
  501. proc seen:add_whosearch {who host searched chan} {
  502. global black
  503. set search_time [unixtime]
  504. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  505. set temp "$black(tempdir)/seen_temp.$timestamp"
  506. set addline "LASTSRC $chan $who $host $search_time $searched"
  507. set file [open $black(seen_details) "r"]
  508. set tempwrite [open $temp w]
  509. while {[gets $file line] != -1} {
  510. set read_type [lindex [split $line] 0]
  511. set read_chan [lindex [split $line] 1]
  512. set enc_chan [encoding convertfrom utf-8 $read_chan]
  513. set read_who [lindex [split $line] 3]
  514. set read_src [lindex [split $line] 5]
  515. if {[string equal -nocase $read_type "LASTSRC"] && [string equal -nocase $chan $enc_chan] && [string equal -nocase $host $read_who] && [string equal -nocase $searched $read_src]} {
  516. continue
  517. } else {
  518. puts $tempwrite $line
  519. }
  520. }
  521. puts $tempwrite $addline
  522. close $tempwrite
  523. close $file
  524. file rename -force $temp $black(seen_details)
  525. }
  526. proc seen:reply:src {nick host chan} {
  527. global black
  528. set chan1 $chan
  529. set file [open $black(seen_details) "r"]
  530. while {[gets $file line] != -1} {
  531. set read_type [lindex [split $line] 0]
  532. set read_chan [lindex [split $line] 1]
  533. set enc_chan [encoding convertfrom utf-8 $read_chan]
  534. set read_src [lindex [split $line] 5]
  535. if {[string equal -nocase $read_type "LASTSRC"] && [string equal -nocase $chan $enc_chan] && [string equal -nocase $read_src $nick]} {
  536. set read_who [lindex [split $line] 2]
  537. set read_who_h [lindex [split $line] 3]
  538. set read_time [lindex [split $line] 4]
  539. set read_time [clock format $read_time -format %D-%H:%M:%S]
  540. blacktools:tell $nick "prv" "" $chan $chan1 seen.39 "$read_who $read_who_h $read_time"
  541. seen:reply:remove $read_src $chan
  542. }
  543. }
  544. close $file
  545. }
  546. proc seen:reply:remove {nick chan} {
  547. global black
  548. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  549. set temp "$black(tempdir)/seen_temp.$timestamp"
  550. set file [open $black(seen_details) "r"]
  551. set tempwrite [open $temp w]
  552. while {[gets $file line] != -1} {
  553. set read_type [lindex [split $line] 0]
  554. set read_chan [lindex [split $line] 1]
  555. set enc_chan [encoding convertfrom utf-8 $read_chan]
  556. set read_src [lindex [split $line] 5]
  557. if {[string equal -nocase $read_type "LASTSRC"] && [string equal -nocase $chan $enc_chan] && [string equal -nocase $nick $read_src]} {
  558. continue
  559. } else {
  560. puts $tempwrite $line
  561. }
  562. }
  563. close $tempwrite
  564. close $file
  565. file rename -force $temp $black(seen_details)
  566. }
  567. proc seen:getlastmsg {what chan nick host hand chan1} {
  568. global black username
  569. set seendirlastmsg $black(seen_details)
  570. set test_lastmsg_host ""
  571. set test_lastmsg_nick ""
  572. set file [open $seendirlastmsg "r"]
  573. set database [read -nonewline $file]
  574. close $file
  575. set data [split $database "\n"]
  576. if {$database != ""} {
  577. set test_lastmsg_nick [lsearch -all [string tolower $data] [string tolower "* *#* $what *"]]
  578. if {[regexp {\!} $what]} {
  579. set test_lastmsg_host [lsearch -all [string tolower $data] [string tolower "* *#* * $what *"]]
  580. }
  581. } else { return 0 }
  582. if {[llength $test_lastmsg_nick] < 1 && [llength $test_lastmsg_host] < 1} {
  583. return 0
  584. }
  585. foreach i $test_lastmsg_nick {
  586. set line [lindex $data $i]
  587. if {$line != ""} {
  588. set userentry [lindex [split $line] 2]
  589. set readhost [lindex [split $line] 3]
  590. if {[info exists entry]} {
  591. if {[lsearch -exact [string tolower "$i:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  592. lappend entry "$i:$userentry:$readhost"
  593. }
  594. } else { lappend entry "$i:$userentry:$readhost" }
  595. }
  596. }
  597. if {[string length $test_lastmsg_host] > 0 && [string length $test_lastmsg_nick] == 0} {
  598. foreach j $test_lastmsg_host {
  599. set line [lindex $data $j]
  600. if {$line != ""} {
  601. set userentry [lindex [split $line] 2]
  602. set readhost [lindex [split $line] 3]
  603. if {[info exists entry]} {
  604. if {[lsearch -exact [string tolower "$j:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  605. lappend entry "$j:$userentry:$readhost"
  606. }
  607. } else { lappend entry "$j:$userentry:$readhost" }
  608. }
  609. }
  610. }
  611. if {[info exists entry]} {
  612. set split_entry [split $entry ":"]
  613. set get_host [lindex [split $split_entry] 2]
  614. set get_line [lindex [split $split_entry] 0]
  615. set get_nick [lindex [split $split_entry] 1]
  616. } else { return 0 }
  617. #checking other entries
  618. if {[string length $test_lastmsg_host] < 1} {
  619. if {[string length $test_lastmsg_nick] == 1} {
  620. set test [lsearch -all [string tolower $data] [string tolower "* * * $get_host *"]]
  621. foreach k $test {
  622. if {$k != $get_line} {
  623. set line [lindex $data $k]
  624. set userentry [lindex [split $line] 2]
  625. set readhost [lindex [split $line] 3]
  626. if {[info exists entry]} {
  627. if {[lsearch -exact [string tolower "$k:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  628. lappend entry "$k:$userentry:$readhost"
  629. }
  630. } else { lappend entry "$k:$userentry:$readhost" }
  631. }
  632. }
  633. }
  634. }
  635. seen:reply $entry $nick $hand $chan $data "1" $host
  636. }
  637. proc seen:reply {entry nick hand chan chan1 data lastmsg prv} {
  638. global black
  639. array set seensort [list]
  640. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  641. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  642. set other_entry ""
  643. set split_entry [join [split $entry " "]]
  644. foreach n $split_entry {
  645. if {$n != ""} {
  646. set split_entry [split $n ":"]
  647. set line_num [lindex $split_entry 0]
  648. set data_line [lindex $data $line_num]
  649. set tm [lindex [split $data_line] 4]
  650. set seensort($tm) $line_num
  651. }
  652. }
  653. foreach line [lsort -integer -decreasing -unique [array names seensort]] {
  654. lappend top_seenlist $seensort($line)
  655. }
  656. set split_seenlist [split $top_seenlist " "]
  657. set first_entry_num [lindex $split_seenlist 0]
  658. set first_entry [lindex $data $first_entry_num]
  659. set first_entry [lindex [split $first_entry] 2]
  660. set chanentry [lindex [split $data_line] 1]
  661. set host [lindex [split $data_line] 3]
  662. set jointime [lindex [split $data_line] 5]
  663. set newnick [lindex [split $data_line] 6]
  664. set reason [join [lrange [split $data_line] 6 end]]
  665. set uhost $host
  666. set host [string trim $host "*!~"]
  667. set tm [lindex [split $data_line] 4]
  668. set type [lindex [split $data_line] 0]
  669. set lmsg [join [lrange [split $data_line] 5 end]]
  670. if {[llength $entry] > 1} {
  671. set other_entries [lrange $split_seenlist 1 end]
  672. foreach n $other_entries {
  673. if {$n != ""} {
  674. set other_entry_line [lindex $data $n]
  675. set other_entry_line [lindex [split $other_entry_line] 2]
  676. lappend other_entry $other_entry_line
  677. }
  678. }
  679. set all_entries "$first_entry [join $other_entry]"
  680. } else {
  681. set all_entries "$first_entry"
  682. }
  683. set all_entries [concat [join [lsort -unique [split $all_entries]]]]
  684. set entry_count [llength [concat [split $all_entries]]]
  685. if {!([regexp {^[0-9]} $jointime]) || ($jointime == "")} {
  686. set jointime 0
  687. set reason [join [lrange [split $line] 5 end]]
  688. }
  689. if {$reason == ""} { set reason "N/A" }
  690. if {$entry_count >= 10} {
  691. set all_entries "$first_entry"
  692. }
  693. set output [return_time $getlang [expr [unixtime] - $tm]]
  694. set staytime [expr [unixtime] - $jointime]
  695. set staytime [return_time $getlang [expr $tm - $jointime]]
  696. set time [clock format $tm -format %D-%H:%M:%S]
  697. set replace(%latest%) $first_entry
  698. set replace(%num%) $entry_count
  699. set replace(%entry%) "$all_entries"
  700. set replace(%host%) "$host"
  701. set replace(%output%) "$output"
  702. set replace(%date%) "($time)"
  703. set replace(%newnick%) "$newnick"
  704. set replace(%userentry%) "$first_entry"
  705. set replace(%chan%) "$chanentry"
  706. set replace(%reason%) "$reason"
  707. set replace(%staytime%) "$staytime"
  708. set replace(%lastmsg%) "$lmsg"
  709. if {$jointime == "0"} { set staymsg "[string map [array get replace] $black(say.$getlang.seen.8)]"
  710. set replace(%staymsg%) "$staymsg"
  711. } else {
  712. set staymsg "[string map [array get replace] $black(say.$getlang.seen.9)]"
  713. set replace(%staymsg%) "$staymsg"
  714. }
  715. if {$lastmsg == "1"} {
  716. if {$entry_count > 1} {
  717. set reply "[string map [array get replace] $black(say.$getlang.seen.30)]"
  718. } else {
  719. set reply "[string map [array get replace] $black(say.$getlang.seen.29)]"
  720. }
  721. }
  722. if {$entry_count > 1} {
  723. set found_many 1
  724. if {$type == "PART"} {
  725. if {$entry_count >= 10} {
  726. set reply "[string map [array get replace] $black(say.$getlang.seen.33)]"
  727. } else {
  728. set reply "[string map [array get replace] $black(say.$getlang.seen.21)]"
  729. }
  730. }
  731. if {$type == "SIGN"} {
  732. if {$entry_count >= 10} {
  733. set reply "[string map [array get replace] $black(say.$getlang.seen.34)]"
  734. } else {
  735. set reply "[string map [array get replace] $black(say.$getlang.seen.22)]"
  736. }
  737. }
  738. if {$type == "JOIN"} {
  739. if {[onchan $first_entry $chanentry]} {
  740. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  741. set replace(%nowon%) "$nowon"
  742. } else {
  743. set nowon "[string map [array get replace] $black(say.$getlang.seen.20)]"
  744. set replace(%nowon%) "$nowon"
  745. }
  746. if {$entry_count >= 10} {
  747. set reply "[string map [array get replace] $black(say.$getlang.seen.35)]"
  748. } else {
  749. set reply "[string map [array get replace] $black(say.$getlang.seen.23)]"
  750. }
  751. }
  752. if {$type == "SPLIT"} {
  753. if {$entry_count >= 10} {
  754. set reply "[string map [array get replace] $black(say.$getlang.seen.36)]"
  755. } else {
  756. set reply "[string map [array get replace] $black(say.$getlang.seen.24)]"
  757. }
  758. }
  759. if {$type == "KICK"} {
  760. if {$entry_count >= 10} {
  761. set reply "[string map [array get replace] $black(say.$getlang.seen.37)]"
  762. } else {
  763. set reply "[string map [array get replace] $black(say.$getlang.seen.25)]"
  764. }
  765. }
  766. if {$type == "NICKCHANGE"} {
  767. if {[onchan $newnick $chanentry]} {
  768. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  769. set replace(%nowon%) "$nowon"
  770. } else {
  771. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  772. set replace(%nowon%) "$nowon"
  773. }
  774. if {$entry_count >= 10} {
  775. set reply "[string map [array get replace] $black(say.$getlang.seen.38)]"
  776. } else {
  777. set reply "[string map [array get replace] $black(say.$getlang.seen.26)]"
  778. }
  779. }
  780. } else {
  781. if {$type == "PART"} {
  782. set reply "[string map [array get replace] $black(say.$getlang.seen.12)]"
  783. }
  784. if {$type == "SIGN"} {
  785. set reply "[string map [array get replace] $black(say.$getlang.seen.13)]"
  786. }
  787. if {$type == "JOIN"} {
  788. if {[onchan $first_entry $chanentry]} {
  789. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  790. set replace(%nowon%) "$nowon"
  791. } else {
  792. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  793. set replace(%nowon%) "$nowon"
  794. }
  795. set reply "[string map [array get replace] $black(say.$getlang.seen.14)]"
  796. }
  797. if {$type == "SPLIT"} {
  798. set reply "[string map [array get replace] $black(say.$getlang.seen.15)]"
  799. }
  800. if {$type == "KICK"} {
  801. set reply "[string map [array get replace] $black(say.$getlang.seen.16)]"
  802. }
  803. if {$type == "NICKCHANGE"} {
  804. if {[onchan $newnick $chanentry]} {
  805. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  806. set replace(%nowon%) "$nowon"
  807. } else {
  808. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  809. set replace(%nowon%) "$nowon"
  810. }
  811. set reply "[string map [array get replace] $black(say.$getlang.seen.17)]"
  812. }
  813. }
  814. if {[string equal -nocase $prv "prv"]} {
  815. blacktools:tell $nick "prv" $hand $chan $nick seen.27 $reply
  816. seenreply:all $nick $uhost $hand $chan $nick $chanentry $first_entry "prv"
  817. } else {
  818. blacktools:tell $nick $host $hand $chan $chan1 seen.27 $reply
  819. seenreply:all $nick $uhost $hand $chan $chan1 $chanentry $first_entry ""
  820. }
  821. }
  822. proc seenreply:all {nick host hand chan chan1 chanentry first_entry prv} {
  823. global black username
  824. set first_entry [join [split $first_entry]]
  825. set seendirlastmsg $black(seen_details)
  826. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  827. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  828. if {[setting:get $chanentry seenlastmsg]} {
  829. set file [open $seendirlastmsg "r"]
  830. set database [read -nonewline $file]
  831. close $file
  832. set data [split $database "\n"]
  833. if {$database != ""} {
  834. set test_reply [lsearch -all [string tolower $data] [string tolower "* $chanentry * $host *"]]
  835. if {[llength $test_reply] > 0} {
  836. set line [lindex $data $test_reply]
  837. set userentry [lindex [split $line] 2]
  838. set gettime [lindex [split $line] 4]
  839. set output [return_time $getlang [expr [unixtime] - $gettime]]
  840. set replace(%output%) "$output"
  841. set replace(%userentry%) "$userentry"
  842. set replace(%chan%) "$chanentry"
  843. set replace(%host%) "$host"
  844. set replace(%lastmsg%) [join [lrange [split $line] 5 end]]
  845. set reply "[string map [array get replace] $black(say.$getlang.seen.32)]"
  846. if {[string equal -nocase $prv "prv"]} {
  847. set host "$prv"
  848. }
  849. blacktools:tell $nick $host $hand $chan $chan1 seen.27 $reply
  850. } else {
  851. blacktools:tell $nick $host $hand $chan $chan1 seen.31 [split $first_entry]
  852. }
  853. }
  854. }
  855. }
  856. ##############
  857. #########################################################################
  858. ## END ##
  859. #########################################################################