From: Christopher Allan Webber Date: Tue, 24 Nov 2015 22:01:49 +0000 (-0600) Subject: Add irc-send-message and fix a buffering error X-Git-Tag: v0.1.0~70 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=3ee18e4426de00fd9f654b37f5214388eafabf78;p=8sync.git Add irc-send-message and fix a buffering error We should always set the buffer *before* running the command, in case something goofy happens... --- diff --git a/eightsync/systems/irc.scm b/eightsync/systems/irc.scm index 0907bcd..da39b5a 100755 --- a/eightsync/systems/irc.scm +++ b/eightsync/systems/irc.scm @@ -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 @@ -91,6 +91,14 @@ (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 "*") @@ -226,12 +234,15 @@ (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))