Posted to tcl by sebres at Tue Feb 02 20:18:43 GMT 2021view raw

  1.  
  2. interp create -safe chatint
  3. chatint eval {
  4.  
  5. proc m {tm nick msg} {
  6. upvar _last_date ld _last_known lk;
  7. if {[info exists lk] && $tm < $lk} return;
  8. set lk $tm
  9. set tm [clock scan $tm -format "%Y-%m-%dT%H:%M:%S%Z"];
  10. set d [clock format $tm -format %x];
  11. if {![info exists ld] || $ld ne $d} {puts "\n== $d [string repeat = 20]\n"; set ld $d};
  12. if {$nick eq "" && [regexp {^\S+ has (?:left|become available)$} $msg]} return;
  13. if {[regexp {^i.chain$} $nick]} {
  14. if {[regexp {^\*{3} \S+ (?:joins|leaves)$} $msg]} return;
  15. regexp {^<([^>]+)> (.*)$} $msg _ nick msg
  16. }
  17. set pref "[clock format $tm -format %X] | [format %15s $nick]"
  18. set pre2 "\n[string repeat " " [string length $pref]] | "
  19. regsub -all {\n} $msg $pre2 msg
  20. puts "$pref | $msg"
  21. }
  22.  
  23. }
  24.  
  25. interp alias chatint puts {} puts
  26.  
  27. proc chat fn {
  28. interp invokehidden chatint source $fn
  29. }
  30.  
  31. # usage:
  32. # chat {2021-01-26.tcl}
  33.