X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=logger.lisp;h=64d94c3feb7fa6c98536c7640f88f766285702e7;hb=3161d0d5e88c7c9e9a29fac9dca67c082f807651;hp=26c78f55ac2350e51b524c6bf5bff87b36382a8e;hpb=a1b6f3f3d596070417ced73efe363830d9b13007;p=irc-logger.git diff --git a/logger.lisp b/logger.lisp index 26c78f5..64d94c3 100644 --- a/logger.lisp +++ b/logger.lisp @@ -246,23 +246,34 @@ (format stream "~S~%" (string-right-trim '(#\return) (raw-message-string msg))))) +(defconstant +posix-epoch+ + (encode-universal-time 0 0 0 1 1 1970 0)) + +(defun posix-time-to-utime (time) + (+ time +posix-epoch+)) + (defun last-sexp-field (type msg) (cond ((null msg) nil) ((eq type :kick) (trailing-argument msg)) + ((eq type :rpl_topicwhotime) + (when (stringp (car (last (arguments msg)))) + (let ((secs (parse-integer (car (last (arguments msg))) :junk-allowed t))) + (when secs + (posix-time-to-utime secs))))) ((need-user-address? type) (user-address msg)))) (defmethod %output-event ((format (eql :sexp)) stream utime type channel source text msg unichannel) - (let ((*print-circle* nil) - (*print-pretty* nil)) - (if unichannel - (format stream "(~S ~S ~S ~S ~S)~%" utime type source text (last-sexp-field type msg)) - (format stream "(~S ~S ~S ~S ~S ~S)~%" utime type source channel text - (last-sexp-field type msg))))) + (with-standard-io-syntax + (let ((cl:*print-case* :downcase)) + (if unichannel + (format stream "(~S ~S ~S ~S ~S)~%" utime type source text (last-sexp-field type msg)) + (format stream "(~S ~S ~S ~S ~S ~S)~%" utime type source channel text + (last-sexp-field type msg)))))) (defmethod %output-event ((format (eql :text)) stream utime type channel source text msg unichannel) @@ -356,10 +367,14 @@ (output-event-for-a-stream msg type channel text logger i)))))))) (defun get-private-log-stream (logger) - (or (private-log-stream logger) *standard-output*)) + (if (and logger (private-log-stream logger)) + (private-log-stream logger) + *standard-output*)) (defun get-unknown-log-stream (logger) - (or (unknown-log-stream logger) *standard-output*)) + (if (and logger (unknown-log-stream logger)) + (unknown-log-stream logger) + *standard-output*)) (defun privmsg-hook (msg) (let ((logger (find-logger-with-connection (connection msg))) @@ -469,6 +484,12 @@ (output-event msg :rpl_topic (format nil "~{~A~^ ~}" (arguments msg)) (trailing-argument msg))) +(defun rpl_topicwhotime-hook (msg) + (output-event msg :rpl_topicwhotime + (second (arguments msg)) + (third (arguments msg)))) + + (defun invite-hook (msg) (let ((logger (find-logger-with-connection (connection msg)))) (format @@ -522,6 +543,7 @@ (add-hook conn 'irc::irc-rpl_topic-message 'rpl_topic-hook) (add-hook conn 'irc::irc-rpl_namreply-message 'rpl_namreply-hook) (add-hook conn 'irc::irc-rpl_endofnames-message 'rpl_endofnames-hook) + (add-hook conn 'irc::irc-rpl_topicwhotime-message 'rpl_topicwhotime-hook) conn)) (defmethod cl-irc::irc-message-event :around ((msg cl-irc::irc-message)) @@ -534,7 +556,9 @@ irc::irc-pong-message irc::irc-kill-message irc::irc-invite-message irc::irc-rpl_killdone-message irc::irc-rpl_closing-message irc::irc-rpl_topic-message irc::irc-rpl_namreply-message - irc::irc-rpl_endofnames-message) + irc::irc-rpl_endofnames-message irc::irc-rpl_topicwhotime-message + irc::irc-rpl_motd-message irc::irc-rpl_motdstart-message + irc::irc-rpl_endofmotd-message) ;; nothing to do ) (t @@ -626,7 +650,7 @@ (defun add-logger (nick server &key channels output (password "") realname username private-log unknown-log (logging-stream t) (async t) - (formats '(:text))) + (formats '(:sexp))) (when (find-logger-with-nick nick) (format (get-private-log-stream (find-logger-with-nick nick))