- speaker message channel-name)))
-
-(define default-handle-privmsg echo-back-message)
-
-(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 socket my-username username
- channel-name message is-action))))
- (_
- (display line)
- (newline)))))
- handle-line)
-
-(define (make-basic-irc-handler handle-line username)
- (let ((buffer '()))
- (define (reset-buffer)
- (set! buffer '()))
- (define (should-read-char socket)
- (and (not (port-closed? socket))
- (char-ready? socket)
- (not (eof-object? (peek-char socket)))))
- (define (irc-handler socket)
- (while (should-read-char socket)
- (set! buffer (cons (read-char socket) buffer))
- (match buffer
- ((#\newline #\return (? char? line-chars) ...)
- (let ((ready-line (list->string (reverse line-chars))))
- ;; reset buffer
- (set! buffer '())
- ;; run it
- (%8sync-run (handle-line
- socket
- ready-line
- username))))
- (_ #f)))
- ;; I need to shut things down on EOF object
- (cond
- ((port-closed? socket)
- (display "port closed time\n")
- (port-remove-request socket))
- ((and (char-ready? socket)
- (eof-object? (peek-char socket)))
- (display "port eof time\n")
- (close socket)
- (port-remove-request socket))))
- irc-handler))
-
-(define default-line-handler (make-handle-line))
-
-(define* (queue-and-start-irc-agenda! agenda socket #:key
- (username "syncbot")
- (inet-port default-irc-port)
- (line-handler default-line-handler)
- (channels '()))
- (dynamic-wind
- (lambda () #f)
- (lambda ()
- (enq! (agenda-queue agenda)
- (wrap (install-socket
- socket
- (make-basic-irc-handler
- line-handler
- username))))
- (enq! (agenda-queue agenda) (wrap (handle-login socket username
- #:channels channels)))
- (start-agenda agenda))
- (lambda ()
- (display "Cleaning up...\n")
- (close socket))))
-