Add irc-send-message and fix a buffering error
authorChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 24 Nov 2015 22:01:49 +0000 (16:01 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 24 Nov 2015 22:01:49 +0000 (16:01 -0600)
We should always set the buffer *before* running the command, in case
something goofy happens...

eightsync/systems/irc.scm

index 0907bcdd21e36594b5197c599af12b8e381e5250..da39b5a8033f98a59ae81b3cad1ee7f9becfe8a8 100755 (executable)
@@ -30,7 +30,7 @@
   #:use-module (ice-9 match)
   #:export (;; The only things you definitely need if writing a bot
             make-irc-bot-cli            
-            irc-format irc-display
+            irc-format irc-display irc-send-message irc-send-formatted
             
             ;; Useful things if you're making something more complicated
             irc-line
       (display (irc-line line) dest)
       (display (irc-line dest))))
 
+(define (irc-send-message socket channel message)
+  (irc-format socket "PRIVMSG ~a :~a" channel message))
+
+(define-syntax-rule (irc-send-formatted socket channel format-string
+                                        args ...)
+  (irc-format socket "PRIVMSG ~a :~a" channel
+              (format #f format-string args ...)))
+
 (define* (handle-login socket username
                        #:key
                        (hostname "*")
         (set! buffer (cons (read-char socket) buffer))
         (match buffer
           ((#\newline #\return (? char? line-chars) ...)
-           (%8sync (%run (handle-line
-                         socket
-                         (list->string (reverse line-chars))
-                         username)))
-           ;; reset buffer
-           (set! buffer '()))
+           (let ((ready-line (list->string (reverse line-chars))))
+             ;; reset buffer
+             (set! buffer '())
+             ;; run it
+             ;; @@: does this need to be %8sync?
+             (%8sync (%run (handle-line
+                            socket
+                            ready-line
+                            username)))))
           (_ #f))))
     irc-handler))