BT.Seen.tcl 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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 seen:process {nick host hand chan chan1 what type} {
  307. global black botnick
  308. set cmd_status [btcmd:status $chan $hand "seen" 0]
  309. if {$cmd_status == "1"} {
  310. return
  311. }
  312. set seendir $black(seen_file)
  313. set test ""
  314. set test_host ""
  315. set show_nick $nick
  316. if {![matchattr $hand nmo]} {
  317. if {![validchan $chan]} {
  318. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  319. return
  320. }
  321. }
  322. if {![setting:get $chan seen]} {
  323. return
  324. }
  325. if {[string match -nocase "*prv*" $host]} {
  326. set split_host [split $host ":"]
  327. set the_host [lindex $split_host 0]
  328. set host [lindex $split_host 1]
  329. } else {
  330. set the_host $host
  331. }
  332. set number [scan $black(seenflood) %\[^:\]]
  333. set timer [scan $black(seenflood) %*\[^:\]:%s]
  334. set i 0
  335. if {$what == ""} {
  336. switch $type {
  337. 0 {
  338. blacktools:tell $nick $host $hand $chan $chan1 gl.instr "seen"
  339. }
  340. 1 {
  341. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_nick "seen"
  342. }
  343. 2 {
  344. blacktools:tell $nick $host $hand $chan $chan1 gl.instr_priv "seen"
  345. }
  346. }
  347. return
  348. }
  349. if {![validchan $chan]} {
  350. blacktools:tell $nick $host $hand $chan $chan1 gl.novalidchan none
  351. return
  352. }
  353. if {![matchattr $hand nmo]} {
  354. foreach tmr [utimers] {
  355. if {[string match "*remove:seenflood:host $the_host $chan*" [join [lindex $tmr 1]]]} {
  356. killutimer [lindex $tmr 2]
  357. }
  358. }
  359. if {![info exists black(flood:$the_host:$chan)]} {
  360. set black(flood:$the_host:$chan) 0
  361. }
  362. incr black(flood:$the_host:$chan)
  363. utimer $timer [list remove:seenflood:host $the_host $chan]
  364. if {$black(flood:$the_host:$chan) >= "$number"} {
  365. blacktools:tell $nick $host $hand $chan $chan1 seen.5 none
  366. return
  367. }
  368. if {[string equal -nocase $what $nick] && ($chan1 == $chan)} { blacktools:tell $nick $host $hand $chan $chan1 seen.6 $nick
  369. return
  370. }
  371. }
  372. if {[string equal -nocase $what $botnick]} {
  373. blacktools:tell $nick $host $hand $chan $chan1 seen.4 $show_nick
  374. return
  375. }
  376. if {[onchan $what $chan]} {
  377. blacktools:tell $nick $host $hand $chan $chan1 seen.7 $what
  378. if {[setting:get $chan seenreply]} {
  379. set read_time [clock format [unixtime] -format %D-%H:%M:%S]
  380. blacktools:tell $what "prv" "" $chan $chan1 seen.39 "$what $show_nick $read_time"
  381. }
  382. return
  383. }
  384. set file [open $seendir "r"]
  385. set database [read -nonewline $file]
  386. close $file
  387. set data [split $database "\n"]
  388. set what [string map [list \[ {\[} \] {\]} \? {\?} \\ {\\}] $what]
  389. if {[matchattr $hand nmo]} {
  390. if {[regexp {\!} $what]} {
  391. set test_host [lsearch -all [string tolower $data] [string tolower "* *#* * $what *"]]
  392. } else {
  393. if {[regexp -- {^[a-zA-Z\|\[\]`^\{\}][a-zA-Z0-9\-_\|\[\]`^\{\}\\]*$} $what]} {
  394. seen:add_whosearch $nick $host $what $chan
  395. }
  396. set test [lsearch -all [string tolower $data] [string tolower "* *#* $what *"]]
  397. }
  398. } else {
  399. if {[regexp {\!} $what]} {
  400. set test_host [lsearch -all [string tolower $data] [string tolower "* $chan * $what *"]]
  401. } else {
  402. if {[regexp -- {^[a-zA-Z\|\[\]`^\{\}][a-zA-Z0-9\-_\|\[\]`^\{\}\\]*$} $what]} {
  403. seen:add_whosearch $nick $host $what $chan
  404. }
  405. set test [lsearch -all [string tolower $data] [string tolower "* $chan $what *"]]
  406. }
  407. }
  408. if {[string length $test] > 0} {
  409. foreach i $test {
  410. set line [lindex $data $i]
  411. if {$line != ""} {
  412. set userentry [lindex [split $line] 2]
  413. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  414. set chanentry [lindex [split $line] 1]
  415. if {[info exists entry]} {
  416. if {[lsearch -exact [string tolower "$i:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  417. lappend entry "$i:$userentry:$readhost"
  418. }
  419. } else { lappend entry "$i:$userentry:$readhost" }
  420. }
  421. }
  422. }
  423. if {[string length $test_host] > 0 && [string length $test] == 0} {
  424. foreach j $test_host {
  425. set line [lindex $data $j]
  426. if {$line != ""} {
  427. set userentry [lindex [split $line] 2]
  428. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  429. set chanentry [lindex [split $line] 1]
  430. if {[info exists entry]} {
  431. if {[lsearch -exact [string tolower "$j:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  432. lappend entry "$j:$userentry:$readhost"
  433. }
  434. } else { lappend entry "$j:$userentry:$readhost" }
  435. }
  436. }
  437. }
  438. if {[info exists entry]} {
  439. set split_entry [split $entry ":"]
  440. set get_host [lindex [split $split_entry] 2]
  441. set get_line [lindex [split $split_entry] 0]
  442. set get_nick [lindex [split $split_entry] 1]
  443. }
  444. #checking other entries
  445. if {[info exists get_host]} {
  446. if {[string length $test_host] < 1} {
  447. if {[matchattr $hand nmo]} {
  448. set test [lsearch -all [string tolower $data] [string tolower "* *#* * $get_host *"]]
  449. } else {
  450. set test [lsearch -all [string tolower $data] [string tolower "* $chan * $get_host *"]]
  451. }
  452. foreach k $test {
  453. if {$k != $get_line} {
  454. set line [lindex $data $k]
  455. set userentry [lindex [split $line] 2]
  456. set readhost [string map {"~" ""} [lindex [split $line] 3]]
  457. if {[info exists entry]} {
  458. if {[lsearch -exact [string tolower "$k:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  459. lappend entry "$k:$userentry:$readhost"
  460. }
  461. } else { lappend entry "$k:$userentry:$readhost" }
  462. }
  463. }
  464. }
  465. }
  466. #
  467. if {[info exists entry]} {
  468. seen:reply $entry $nick $hand $chan $chan1 $data "1" $host
  469. } else {
  470. blacktools:tell $nick $host $hand $chan $chan1 seen.18 $what
  471. }
  472. }
  473. proc seen:add_whosearch {who host searched chan} {
  474. global black
  475. set search_time [unixtime]
  476. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  477. set temp "$black(tempdir)/seen_temp.$timestamp"
  478. set addline "LASTSRC $chan $who $host $search_time $searched"
  479. set file [open $black(seen_details) "r"]
  480. set tempwrite [open $temp w]
  481. while {[gets $file line] != -1} {
  482. set read_type [lindex [split $line] 0]
  483. set read_chan [lindex [split $line] 1]
  484. set enc_chan [encoding convertfrom utf-8 $read_chan]
  485. set read_who [lindex [split $line] 3]
  486. set read_src [lindex [split $line] 5]
  487. 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]} {
  488. continue
  489. } else {
  490. puts $tempwrite $line
  491. }
  492. }
  493. puts $tempwrite $addline
  494. close $tempwrite
  495. close $file
  496. file rename -force $temp $black(seen_details)
  497. }
  498. proc seen:reply:src {nick host chan} {
  499. global black
  500. set chan1 $chan
  501. set file [open $black(seen_details) "r"]
  502. while {[gets $file line] != -1} {
  503. set read_type [lindex [split $line] 0]
  504. set read_chan [lindex [split $line] 1]
  505. set enc_chan [encoding convertfrom utf-8 $read_chan]
  506. set read_src [lindex [split $line] 5]
  507. if {[string equal -nocase $read_type "LASTSRC"] && [string equal -nocase $chan $enc_chan] && [string equal -nocase $read_src $nick]} {
  508. set read_who [lindex [split $line] 2]
  509. set read_who_h [lindex [split $line] 3]
  510. set read_time [lindex [split $line] 4]
  511. set read_time [clock format $read_time -format %D-%H:%M:%S]
  512. blacktools:tell $nick "prv" "" $chan $chan1 seen.39 "$read_who $read_who_h $read_time"
  513. seen:reply:remove $read_src $chan
  514. }
  515. }
  516. close $file
  517. }
  518. proc seen:reply:remove {nick chan} {
  519. global black
  520. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  521. set temp "$black(tempdir)/seen_temp.$timestamp"
  522. set file [open $black(seen_details) "r"]
  523. set tempwrite [open $temp w]
  524. while {[gets $file line] != -1} {
  525. set read_type [lindex [split $line] 0]
  526. set read_chan [lindex [split $line] 1]
  527. set enc_chan [encoding convertfrom utf-8 $read_chan]
  528. set read_src [lindex [split $line] 5]
  529. if {[string equal -nocase $read_type "LASTSRC"] && [string equal -nocase $chan $enc_chan] && [string equal -nocase $nick $read_src]} {
  530. continue
  531. } else {
  532. puts $tempwrite $line
  533. }
  534. }
  535. close $tempwrite
  536. close $file
  537. file rename -force $temp $black(seen_details)
  538. }
  539. proc seen:getlastmsg {what chan nick host hand chan1} {
  540. global black username
  541. set seendirlastmsg $black(seen_details)
  542. set test_lastmsg_host ""
  543. set test_lastmsg_nick ""
  544. set file [open $seendirlastmsg "r"]
  545. set database [read -nonewline $file]
  546. close $file
  547. set data [split $database "\n"]
  548. if {$database != ""} {
  549. set test_lastmsg_nick [lsearch -all [string tolower $data] [string tolower "* *#* $what *"]]
  550. if {[regexp {\!} $what]} {
  551. set test_lastmsg_host [lsearch -all [string tolower $data] [string tolower "* *#* * $what *"]]
  552. }
  553. } else { return 0 }
  554. if {[llength $test_lastmsg_nick] < 1 && [llength $test_lastmsg_host] < 1} {
  555. return 0
  556. }
  557. foreach i $test_lastmsg_nick {
  558. set line [lindex $data $i]
  559. if {$line != ""} {
  560. set userentry [lindex [split $line] 2]
  561. set readhost [lindex [split $line] 3]
  562. if {[info exists entry]} {
  563. if {[lsearch -exact [string tolower "$i:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  564. lappend entry "$i:$userentry:$readhost"
  565. }
  566. } else { lappend entry "$i:$userentry:$readhost" }
  567. }
  568. }
  569. if {[string length $test_lastmsg_host] > 0 && [string length $test_lastmsg_nick] == 0} {
  570. foreach j $test_lastmsg_host {
  571. set line [lindex $data $j]
  572. if {$line != ""} {
  573. set userentry [lindex [split $line] 2]
  574. set readhost [lindex [split $line] 3]
  575. if {[info exists entry]} {
  576. if {[lsearch -exact [string tolower "$j:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  577. lappend entry "$j:$userentry:$readhost"
  578. }
  579. } else { lappend entry "$j:$userentry:$readhost" }
  580. }
  581. }
  582. }
  583. if {[info exists entry]} {
  584. set split_entry [split $entry ":"]
  585. set get_host [lindex [split $split_entry] 2]
  586. set get_line [lindex [split $split_entry] 0]
  587. set get_nick [lindex [split $split_entry] 1]
  588. } else { return 0 }
  589. #checking other entries
  590. if {[string length $test_lastmsg_host] < 1} {
  591. if {[string length $test_lastmsg_nick] == 1} {
  592. set test [lsearch -all [string tolower $data] [string tolower "* * * $get_host *"]]
  593. foreach k $test {
  594. if {$k != $get_line} {
  595. set line [lindex $data $k]
  596. set userentry [lindex [split $line] 2]
  597. set readhost [lindex [split $line] 3]
  598. if {[info exists entry]} {
  599. if {[lsearch -exact [string tolower "$k:$userentry:$readhost"] [string tolower $entry]] == "-1"} {
  600. lappend entry "$k:$userentry:$readhost"
  601. }
  602. } else { lappend entry "$k:$userentry:$readhost" }
  603. }
  604. }
  605. }
  606. }
  607. seen:reply $entry $nick $hand $chan $data "1" $host
  608. }
  609. proc seen:reply {entry nick hand chan chan1 data lastmsg prv} {
  610. global black
  611. array set seensort [list]
  612. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  613. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  614. set other_entry ""
  615. set split_entry [join [split $entry " "]]
  616. foreach n $split_entry {
  617. if {$n != ""} {
  618. set split_entry [split $n ":"]
  619. set line_num [lindex $split_entry 0]
  620. set data_line [lindex $data $line_num]
  621. set tm [lindex [split $data_line] 4]
  622. set seensort($tm) $line_num
  623. }
  624. }
  625. foreach line [lsort -integer -decreasing -unique [array names seensort]] {
  626. lappend top_seenlist $seensort($line)
  627. }
  628. set split_seenlist [split $top_seenlist " "]
  629. set first_entry_num [lindex $split_seenlist 0]
  630. set first_entry [lindex $data $first_entry_num]
  631. set first_entry [lindex [split $first_entry] 2]
  632. set chanentry [lindex [split $data_line] 1]
  633. set host [lindex [split $data_line] 3]
  634. set jointime [lindex [split $data_line] 5]
  635. set newnick [lindex [split $data_line] 6]
  636. set reason [join [lrange [split $data_line] 6 end]]
  637. set uhost $host
  638. set host [string trim $host "*!~"]
  639. set tm [lindex [split $data_line] 4]
  640. set type [lindex [split $data_line] 0]
  641. set lmsg [join [lrange [split $data_line] 5 end]]
  642. if {[llength $entry] > 1} {
  643. set other_entries [lrange $split_seenlist 1 end]
  644. foreach n $other_entries {
  645. if {$n != ""} {
  646. set other_entry_line [lindex $data $n]
  647. set other_entry_line [lindex [split $other_entry_line] 2]
  648. lappend other_entry $other_entry_line
  649. }
  650. }
  651. set all_entries "$first_entry [join $other_entry]"
  652. } else {
  653. set all_entries "$first_entry"
  654. }
  655. set all_entries [concat [join [lsort -unique [split $all_entries]]]]
  656. set entry_count [llength [concat [split $all_entries]]]
  657. if {!([regexp {^[0-9]} $jointime]) || ($jointime == "")} {
  658. set jointime 0
  659. set reason [join [lrange [split $line] 5 end]]
  660. }
  661. if {$reason == ""} { set reason "N/A" }
  662. if {$entry_count >= 10} {
  663. set all_entries "$first_entry"
  664. }
  665. set output [return_time $getlang [expr [unixtime] - $tm]]
  666. set staytime [expr [unixtime] - $jointime]
  667. set staytime [return_time $getlang [expr $tm - $jointime]]
  668. set time [clock format $tm -format %D-%H:%M:%S]
  669. set replace(%latest%) $first_entry
  670. set replace(%num%) $entry_count
  671. set replace(%entry%) "$all_entries"
  672. set replace(%host%) "$host"
  673. set replace(%output%) "$output"
  674. set replace(%date%) "($time)"
  675. set replace(%newnick%) "$newnick"
  676. set replace(%userentry%) "$first_entry"
  677. set replace(%chan%) "$chanentry"
  678. set replace(%reason%) "$reason"
  679. set replace(%staytime%) "$staytime"
  680. set replace(%lastmsg%) "$lmsg"
  681. if {$jointime == "0"} { set staymsg "[string map [array get replace] $black(say.$getlang.seen.8)]"
  682. set replace(%staymsg%) "$staymsg"
  683. } else {
  684. set staymsg "[string map [array get replace] $black(say.$getlang.seen.9)]"
  685. set replace(%staymsg%) "$staymsg"
  686. }
  687. if {$lastmsg == "1"} {
  688. if {$entry_count > 1} {
  689. set reply "[string map [array get replace] $black(say.$getlang.seen.30)]"
  690. } else {
  691. set reply "[string map [array get replace] $black(say.$getlang.seen.29)]"
  692. }
  693. }
  694. if {$entry_count > 1} {
  695. set found_many 1
  696. if {$type == "PART"} {
  697. if {$entry_count >= 10} {
  698. set reply "[string map [array get replace] $black(say.$getlang.seen.33)]"
  699. } else {
  700. set reply "[string map [array get replace] $black(say.$getlang.seen.21)]"
  701. }
  702. }
  703. if {$type == "SIGN"} {
  704. if {$entry_count >= 10} {
  705. set reply "[string map [array get replace] $black(say.$getlang.seen.34)]"
  706. } else {
  707. set reply "[string map [array get replace] $black(say.$getlang.seen.22)]"
  708. }
  709. }
  710. if {$type == "JOIN"} {
  711. if {[onchan $first_entry $chanentry]} {
  712. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  713. set replace(%nowon%) "$nowon"
  714. } else {
  715. set nowon "[string map [array get replace] $black(say.$getlang.seen.20)]"
  716. set replace(%nowon%) "$nowon"
  717. }
  718. if {$entry_count >= 10} {
  719. set reply "[string map [array get replace] $black(say.$getlang.seen.35)]"
  720. } else {
  721. set reply "[string map [array get replace] $black(say.$getlang.seen.23)]"
  722. }
  723. }
  724. if {$type == "SPLIT"} {
  725. if {$entry_count >= 10} {
  726. set reply "[string map [array get replace] $black(say.$getlang.seen.36)]"
  727. } else {
  728. set reply "[string map [array get replace] $black(say.$getlang.seen.24)]"
  729. }
  730. }
  731. if {$type == "KICK"} {
  732. if {$entry_count >= 10} {
  733. set reply "[string map [array get replace] $black(say.$getlang.seen.37)]"
  734. } else {
  735. set reply "[string map [array get replace] $black(say.$getlang.seen.25)]"
  736. }
  737. }
  738. if {$type == "NICKCHANGE"} {
  739. if {[onchan $newnick $chanentry]} {
  740. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  741. set replace(%nowon%) "$nowon"
  742. set replace(%chan%) "$chanentry"
  743. } else {
  744. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  745. set replace(%nowon%) "$nowon"
  746. }
  747. if {$entry_count >= 10} {
  748. set reply "[string map [array get replace] $black(say.$getlang.seen.38)]"
  749. } else {
  750. set reply "[string map [array get replace] $black(say.$getlang.seen.26)]"
  751. }
  752. }
  753. } else {
  754. if {$type == "PART"} {
  755. set reply "[string map [array get replace] $black(say.$getlang.seen.12)]"
  756. }
  757. if {$type == "SIGN"} {
  758. set reply "[string map [array get replace] $black(say.$getlang.seen.13)]"
  759. }
  760. if {$type == "JOIN"} {
  761. if {[onchan $first_entry $chanentry]} {
  762. set nowon "[string map [array get replace] $black(say.$getlang.seen.19)]"
  763. set replace(%nowon%) "$nowon"
  764. set replace(%chan%) "$chanentry"
  765. } else {
  766. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  767. set replace(%nowon%) "$nowon"
  768. }
  769. set reply "[string map [array get replace] $black(say.$getlang.seen.14)]"
  770. }
  771. if {$type == "SPLIT"} {
  772. set reply "[string map [array get replace] $black(say.$getlang.seen.15)]"
  773. }
  774. if {$type == "KICK"} {
  775. set reply "[string map [array get replace] $black(say.$getlang.seen.16)]"
  776. }
  777. if {$type == "NICKCHANGE"} {
  778. if {[onchan $newnick $chanentry]} {
  779. set nowon "[string map [array get replace] $black(say.$getlang.seen.10)]"
  780. set replace(%nowon%) "$nowon"
  781. } else {
  782. set nowon "[string map [array get replace] $black(say.$getlang.seen.11)]"
  783. set replace(%nowon%) "$nowon"
  784. }
  785. set reply "[string map [array get replace] $black(say.$getlang.seen.17)]"
  786. }
  787. }
  788. if {[string equal -nocase $prv "prv"]} {
  789. set text [black:color:set "" $reply]
  790. blacktools:tell $nick "prv" $hand $chan $nick seen.27 $text
  791. seenreply:all $nick $uhost $hand $chan $nick $chanentry $first_entry "prv"
  792. } else {
  793. set text [black:color:set "" $reply]
  794. blacktools:tell $nick $host $hand $chan $chan1 seen.27 $text
  795. seenreply:all $nick $uhost $hand $chan $chan1 $chanentry $first_entry ""
  796. }
  797. }
  798. proc seenreply:all {nick host hand chan chan1 chanentry first_entry prv} {
  799. global black username
  800. set first_entry [join [split $first_entry]]
  801. set seendirlastmsg $black(seen_details)
  802. set getlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  803. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  804. if {[setting:get $chanentry seenlastmsg]} {
  805. set file [open $seendirlastmsg "r"]
  806. set database [read -nonewline $file]
  807. close $file
  808. set data [split $database "\n"]
  809. if {$database != ""} {
  810. set test_reply [lsearch -all [string tolower $data] [string tolower "* $chanentry * $host *"]]
  811. if {[llength $test_reply] > 0} {
  812. set line [lindex $data $test_reply]
  813. set userentry [lindex [split $line] 2]
  814. set gettime [lindex [split $line] 4]
  815. set output [return_time $getlang [expr [unixtime] - $gettime]]
  816. set replace(%output%) "$output"
  817. set replace(%userentry%) "$userentry"
  818. set replace(%chan%) "$chanentry"
  819. set replace(%host%) "$host"
  820. set replace(%lastmsg%) [join [lrange [split $line] 5 end]]
  821. set reply "[string map [array get replace] $black(say.$getlang.seen.32)]"
  822. if {[string equal -nocase $prv "prv"]} {
  823. set host "$prv"
  824. }
  825. set text [black:color:set "" $reply]
  826. blacktools:tell $nick $host $hand $chan $chan1 seen.27 $text
  827. } else {
  828. set text2 [black:color:set "" [split $first_entry]]
  829. blacktools:tell $nick $host $hand $chan $chan1 seen.31 $text2
  830. }
  831. }
  832. }
  833. }
  834. ##############
  835. #########################################################################
  836. ## END ##
  837. #########################################################################