Give a bot access to its own name. Also respond to pings.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 23 Nov 2015 02:44:20 +0000 (20:44 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Mon, 23 Nov 2015 02:44:20 +0000 (20:44 -0600)
demos/irc.scm

index 2ff8c8cfda8360003f7dc90cc2ec6e521f8b3053..cbd3848378f8d8adb3748e0abe66b18e50921507 100755 (executable)
      (irc-format socket "JOIN ~a" channel))
    channels))
 
-(define (handle-line socket line)
-  (display line)
-  (newline))
-
-(define (make-simple-irc-handler handle-line)
+(define (handle-line socket line my-username)
+  (match (string-split line #\space)
+    (("PING" rest ...)
+     (irc-display "PONG" socket)
+     (display "PONG'ed back ;)\n"))
+    (_
+     (display line)
+     (newline))))
+
+(define (make-simple-irc-handler handle-line username)
   (let ((buffer '()))
     (define (reset-buffer)
       (set! buffer '()))
           ((#\newline #\return (? char? line-chars) ...)
            (%sync (%run (handle-line
                          socket
-                         (list->string (reverse line-chars)))))
+                         (list->string (reverse line-chars))
+                         username)))
            ;; reset buffer
            (set! buffer '()))
           (_ #f))))
 (define* (queue-and-start-irc-agenda! agenda socket #:key
                                       (username "syncbot")
                                       (inet-port default-irc-port)
-                                      (handler (make-simple-irc-handler handle-line))
+                                      (handler (make-simple-irc-handler
+                                                (lambda args
+                                                  (apply handle-line args))
+                                                username))
                                       (channels '()))
   (dynamic-wind
     (lambda () #f)
      (irc-socket-setup hostname port)
      #:inet-port port
      #:username username
-     #:handler (make-simple-irc-handler handle-line)
      #:channels (string-split channels #\space))))