-(define (msg<-toks nick toks)
- (define tm_rfc3339 (list-ref toks 0))
- (define tok_text (list-ref toks 1))
- (define t (string->rfc3339-record tm_rfc3339))
- ; TODO handle tz offset
- (define tm_epoch (find-seconds [rfc3339-record:second t]
- [rfc3339-record:minute t]
- [rfc3339-record:hour t]
- [rfc3339-record:mday t]
- [rfc3339-record:month t]
- [rfc3339-record:year t]))
- (msg tm_epoch tm_rfc3339 nick tok_text))
+(define (msg-print odd m)
+ (printf "~a \033[1;37m<~a>\033[0m \033[0;~am~a\033[0m~n"
+ (date->string (seconds->date [msg-tm_epoch m]) #t)
+ [msg-nick m]
+ [if odd 36 33]
+ [msg-text m]))
+
+(define re-msg-begin
+ ; TODO Zulu offset. Maybe in several formats. Which ones?
+ (pregexp "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}"))
+
+(define (str->msg nick str)
+ (if (not (regexp-match? re-msg-begin str))
+ (begin
+ (log-debug "Non-msg line from nick:~a, line:~a" nick str)
+ #f)
+ (let ([toks (string-split str (regexp "\t+"))])
+ (if (not (= 2 (length toks)))
+ (begin
+ (log-warning "Invalid msg line from nick:~a, msg:~a" nick str)
+ #f)
+ (let*
+ ([tm_rfc3339 (list-ref toks 0)]
+ [tok_text (list-ref toks 1)]
+ [t (string->rfc3339-record tm_rfc3339)]
+ ; TODO handle tz offset
+ [tm_epoch (find-seconds [rfc3339-record:second t]
+ [rfc3339-record:minute t]
+ [rfc3339-record:hour t]
+ [rfc3339-record:mday t]
+ [rfc3339-record:month t]
+ [rfc3339-record:year t])])
+ (msg tm_epoch tm_rfc3339 nick tok_text))))))
+
+(define (str->lines str)
+ (string-split str (regexp "[\r\n]+")))
+
+(define (str->msgs nick str)
+ (filter-map (λ (line) (str->msg nick line)) (str->lines str)))