break handling private messages out into its own function
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 23 Nov 2015 21:16:43 +0000 (15:16 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 23 Nov 2015 21:16:43 +0000 (15:16 -0600)
demos/irc.scm

index 04b297ad5bad53d19a0f26bc29e13d53c82cf037..ab6c7c7195876b5843abd9f41ff7df6bb79d1b20 100755 (executable)
                (string-join (cons first-word rest-message) " ")
                #f)))))
 
-(define (handle-line socket line my-username)
-  (let ((parsed-line (parse-line line)))
-    (match (irc-line-command parsed-line)
-      ("PING"
-       (irc-display "PONG" socket))
-      ("PRIVMSG"
-       (receive (channel-name message is-action)
-           (condense-privmsg-line (irc-line-params parsed-line))
-         (let ((username (irc-line-username parsed-line)))
-           (if is-action
-               (format #t "~a emoted ~s in channel ~a\n"
-                       username message channel-name)
-               (format #t "~a said ~s in channel ~a\n"
-                       username message channel-name)))))
-      (_
-       (display line)
-       (newline)))))
+(define (default-handle-privmsg irc-line username channel-name message is-action)
+  (if is-action
+      (format #t "~a emoted ~s in channel ~a\n"
+              username message channel-name)
+      (format #t "~a said ~s in channel ~a\n"
+              username message channel-name)))
+
+(define* (make-handle-line #:key
+                           (handle-privmsg default-handle-privmsg))
+  (define (handle-line socket line my-username)
+    (let ((parsed-line (parse-line line)))
+      (match (irc-line-command parsed-line)
+        ("PING"
+         (irc-display "PONG" socket))
+        ("PRIVMSG"
+         (receive (channel-name message is-action)
+             (condense-privmsg-line (irc-line-params parsed-line))
+           (let ((username (irc-line-username parsed-line)))
+             (handle-privmsg parsed-line username channel-name message is-action))))
+        (_
+         (display line)
+         (newline)))))
+  handle-line)
 
 (define (make-simple-irc-handler handle-line username)
   (let ((buffer '()))
                                       (inet-port default-irc-port)
                                       (handler (make-simple-irc-handler
                                                 (lambda args
-                                                  (apply handle-line args))
+                                                  (apply (make-handle-line) args))
                                                 username))
                                       (channels '()))
   (dynamic-wind