From 77ac93255544d74b0217e75de4f8a23361397f28 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 22 Nov 2015 20:18:28 -0600 Subject: [PATCH 01/16] Oops, left a stray (pk) --- eightsync/agenda.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eightsync/agenda.scm b/eightsync/agenda.scm index b26d93b..adbd0c6 100644 --- a/eightsync/agenda.scm +++ b/eightsync/agenda.scm @@ -561,7 +561,7 @@ return the wrong thing via (8sync) and trip themselves up." (hash-keys (agenda-except-port-map agenda)) sec usec)) (lambda (key . rest-args) - (match (pk 'rest-args rest-args) + (match rest-args ((_ _ _ (EINTR)) '(() () ())) (_ (error "Unhandled error in select!" key rest-args)))))))) -- 2.31.1 From acafaeee5bba662ce9bb37744ee75e0c461c628d Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 22 Nov 2015 20:44:20 -0600 Subject: [PATCH 02/16] Give a bot access to its own name. Also respond to pings. --- demos/irc.scm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/demos/irc.scm b/demos/irc.scm index 2ff8c8c..cbd3848 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -78,11 +78,16 @@ (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 '())) @@ -95,7 +100,8 @@ ((#\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)))) @@ -104,7 +110,10 @@ (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) @@ -152,5 +161,4 @@ (irc-socket-setup hostname port) #:inet-port port #:username username - #:handler (make-simple-irc-handler handle-line) #:channels (string-split channels #\space)))) -- 2.31.1 From 9c8d37765bca38ffe643434ca154999f8e602a6a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 22 Nov 2015 21:50:03 -0600 Subject: [PATCH 03/16] add parse-line procedure --- demos/irc.scm | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/demos/irc.scm b/demos/irc.scm index cbd3848..a5e9ba4 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -78,6 +78,47 @@ (irc-format socket "JOIN ~a" channel)) channels)) +(define (startswith-colon? str) + (and (> (string-length str) 0) + (eq? (string-ref str 0) + #\:))) + +(define (parse-line line) + (define (parse-params pre-params) + ;; This is stupid and imperative but I can't wrap my brain around + ;; the right way to do it in a functional way :\ + (let ((param-list '()) + (currently-building '())) + (for-each + (lambda (param-item) + (cond + ((startswith-colon? param-item) + (if (not (eq? currently-building '())) + (set! param-list + (cons + (reverse currently-building) + param-list))) + (set! currently-building (list param-item))) + (else + (set! currently-building (cons param-item currently-building))))) + pre-params) + ;; We're still building something, so tack that on there + (if (not (eq? currently-building '())) + (set! param-list + (cons (reverse currently-building) param-list))) + ;; return the reverse of the param list + (reverse param-list))) + + (match (string-split line #\space) + (((? startswith-colon? prefix) + command + pre-params ...) + (list prefix command + (parse-params2 pre-params))) + ((command pre-params ...) + (list #f command (parse-params2 pre-params))))) + + (define (handle-line socket line my-username) (match (string-split line #\space) (("PING" rest ...) -- 2.31.1 From dc1207c53397653cb606c21638d0ad871431ea3a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 22 Nov 2015 22:06:23 -0600 Subject: [PATCH 04/16] add irc-line type, switch to (match) for handle-line --- demos/irc.scm | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/demos/irc.scm b/demos/irc.scm index a5e9ba4..b6a992c 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -21,6 +21,7 @@ (use-modules (eightsync repl) (eightsync agenda) + (srfi srfi-9) (ice-9 getopt-long) (ice-9 format) (ice-9 q) @@ -83,6 +84,14 @@ (eq? (string-ref str 0) #\:))) +(define-record-type + (make-irc-line prefix command params) + irc-line? + (prefix irc-line-prefix) + (command irc-line-command) + (params irc-line-params)) + + (define (parse-line line) (define (parse-params pre-params) ;; This is stupid and imperative but I can't wrap my brain around @@ -113,20 +122,27 @@ (((? startswith-colon? prefix) command pre-params ...) - (list prefix command - (parse-params2 pre-params))) + (make-irc-line prefix command + (parse-params pre-params))) ((command pre-params ...) - (list #f command (parse-params2 pre-params))))) + (make-irc-line #f command + (parse-params pre-params))))) (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)))) + (let ((parsed-line (parse-line line))) + (match (irc-line-command parsed-line) + ("PING" + (irc-display "PONG" socket)) + ("PRIVMSG" + (display "hey we got a PRIVMSG up in here!\n") + (display parsed-line) + (newline) + (display line) + (newline)) + (_ + (display line) + (newline))))) (define (make-simple-irc-handler handle-line username) (let ((buffer '())) -- 2.31.1 From 1ff1b8f96db972ad48e877111814cce45c829e37 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 13:44:21 -0600 Subject: [PATCH 05/16] 30 checks-per-second for the coop server handler is a lot less demanding on the CPU --- eightsync/repl.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eightsync/repl.scm b/eightsync/repl.scm index 6180d04..196b02d 100644 --- a/eightsync/repl.scm +++ b/eightsync/repl.scm @@ -26,7 +26,7 @@ (define (run-self) (poll-coop-repl-server coop-server) ;; queue ourselves again - (run-delay (run-self) (/ 1 60))) + (run-delay (run-self) (/ 1 30))) run-self) (define* (spawn-and-queue-repl-server! agenda #:optional port) -- 2.31.1 From 4ad4b7841eae2e9a29e98d308229c8da895635f1 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 14:48:08 -0600 Subject: [PATCH 06/16] A lot more stuff to handle PRIVMSG messages --- demos/irc.scm | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/demos/irc.scm b/demos/irc.scm index b6a992c..04b297a 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -24,6 +24,7 @@ (srfi srfi-9) (ice-9 getopt-long) (ice-9 format) + (ice-9 receive) (ice-9 q) (ice-9 match)) @@ -128,6 +129,38 @@ (make-irc-line #f command (parse-params pre-params))))) +(define (strip-colon-if-necessary string) + (if (and (> (string-length string) 0) + (string-ref string 0)) + (substring/copy string 1) + string)) + +;; @@: Not sure if this works in all cases, like what about in a non-privmsg one? +(define (irc-line-username irc-line) + (let* ((prefix-name (strip-colon-if-necessary (irc-line-prefix irc-line))) + (exclaim-index (string-index prefix-name #\!))) + (if exclaim-index + (substring/copy prefix-name 0 exclaim-index) + prefix-name))) + +(define (condense-privmsg-line line) + "Condense message line and do multiple value return of + (channel message is-action)" + (define (strip-last-char string) + (substring/copy string 0 (- (string-length string) 1))) + (let* ((channel-name (caar line)) + (rest-params (apply append (cdr line)))) + (match rest-params + (((or "\x01ACTION" ":\x01ACTION") middle-words ... (= strip-last-char last-word)) + (values channel-name + (string-join + (append middle-words (list last-word)) + " ") + #t)) + (((= strip-colon-if-necessary first-word) rest-message ...) + (values channel-name + (string-join (cons first-word rest-message) " ") + #f))))) (define (handle-line socket line my-username) (let ((parsed-line (parse-line line))) @@ -135,11 +168,14 @@ ("PING" (irc-display "PONG" socket)) ("PRIVMSG" - (display "hey we got a PRIVMSG up in here!\n") - (display parsed-line) - (newline) - (display line) - (newline)) + (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))))) -- 2.31.1 From da78b24ca8b7be9085e7f78e4f50fa631a893a7b Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 15:16:43 -0600 Subject: [PATCH 07/16] break handling private messages out into its own function --- demos/irc.scm | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/demos/irc.scm b/demos/irc.scm index 04b297a..ab6c7c7 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -162,23 +162,29 @@ (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 '())) @@ -205,7 +211,7 @@ (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 -- 2.31.1 From d86e4ab5d19c62bd585239dd600aa2645b337c74 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 15:20:26 -0600 Subject: [PATCH 08/16] refactoring args to default-handle-privmsg --- demos/irc.scm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/demos/irc.scm b/demos/irc.scm index ab6c7c7..eabc31d 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -162,12 +162,13 @@ (string-join (cons first-word rest-message) " ") #f))))) -(define (default-handle-privmsg irc-line username channel-name message is-action) +(define (default-handle-privmsg my-name speaker + channel-name message is-action) (if is-action (format #t "~a emoted ~s in channel ~a\n" - username message channel-name) + speaker message channel-name) (format #t "~a said ~s in channel ~a\n" - username message channel-name))) + speaker message channel-name))) (define* (make-handle-line #:key (handle-privmsg default-handle-privmsg)) @@ -180,7 +181,7 @@ (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)))) + (handle-privmsg my-username username channel-name message is-action)))) (_ (display line) (newline))))) -- 2.31.1 From 260a9a10fd060573da725c129d2e54ef33ff61a3 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 15:26:39 -0600 Subject: [PATCH 09/16] echo back message stuff --- demos/irc.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demos/irc.scm b/demos/irc.scm index eabc31d..37e4e01 100755 --- a/demos/irc.scm +++ b/demos/irc.scm @@ -162,14 +162,16 @@ (string-join (cons first-word rest-message) " ") #f))))) -(define (default-handle-privmsg my-name speaker - channel-name message is-action) +(define (echo-back-message my-name speaker + channel-name message is-action) (if is-action (format #t "~a emoted ~s in channel ~a\n" speaker message channel-name) (format #t "~a said ~s in channel ~a\n" 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) -- 2.31.1 From 8f71a1c0f6ddc9e295d929480503222c6baf9e4e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 16:01:36 -0600 Subject: [PATCH 10/16] Moving the irc bot demo to systems --- Makefile.am | 3 +- demos/ircbot.scm | 33 ++++++++++ {demos => eightsync/systems}/irc.scm | 91 +++++++++++++++++++--------- 3 files changed, 96 insertions(+), 31 deletions(-) create mode 100755 demos/ircbot.scm rename {demos => eightsync/systems}/irc.scm (79%) diff --git a/Makefile.am b/Makefile.am index c57bf73..0317500 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,8 @@ moddir=$(prefix)/share/guile/site/2.0 godir=$(libdir)/guile/2.0/ccache SOURCES = \ - eightsync/agenda.scm + eightsync/agenda.scm \ + eightsync/systems/irc.scm TESTS = \ diff --git a/demos/ircbot.scm b/demos/ircbot.scm new file mode 100755 index 0000000..eec40fa --- /dev/null +++ b/demos/ircbot.scm @@ -0,0 +1,33 @@ +#!/usr/bin/guile \ +-e main -s +!# + +;; Copyright (C) 2015 Christopher Allan Webber + +;; This library is free software; you can redistribute it and/or +;; modify it under the terms of the GNU Lesser General Public +;; License as published by the Free Software Foundation; either +;; version 3 of the License, or (at your option) any later version. +;; +;; This library is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; Lesser General Public License for more details. +;; +;; You should have received a copy of the GNU Lesser General Public +;; License along with this library; if not, write to the Free Software +;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +;; 02110-1301 USA + +(use-modules (eightsync systems irc)) + +(define (handle-message socket my-name speaker + channel-name message is-action) + (if is-action + (format #t "~a emoted ~s in channel ~a\n" + speaker message channel-name) + (format #t "~a said ~s in channel ~a\n" + speaker message channel-name))) + +(define main + (make-irc-bot-cli)) diff --git a/demos/irc.scm b/eightsync/systems/irc.scm similarity index 79% rename from demos/irc.scm rename to eightsync/systems/irc.scm index 37e4e01..a802167 100755 --- a/demos/irc.scm +++ b/eightsync/systems/irc.scm @@ -19,14 +19,39 @@ ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ;; 02110-1301 USA -(use-modules (eightsync repl) - (eightsync agenda) - (srfi srfi-9) - (ice-9 getopt-long) - (ice-9 format) - (ice-9 receive) - (ice-9 q) - (ice-9 match)) +(define-module (eightsync systems irc) + #:use-module (eightsync repl) + #:use-module (eightsync agenda) + #:use-module (srfi srfi-9) + #:use-module (ice-9 getopt-long) + #:use-module (ice-9 format) + #:use-module (ice-9 receive) + #:use-module (ice-9 q) + #:use-module (ice-9 match) + #:export (;; The only things you definitely need if writing a bot + make-irc-bot-cli + irc-format irc-display + + ;; Useful things if you're making something more complicated + irc-line + irc-eol + + default-irc-port + + startswith-colon? + + + make-irc-line irc-line? + irc-line-prefix irc-line-command irc-line-params + + parse-line + irc-line-username + + condense-privmsg-line + echo-back-message + + make-handle-line make-basic-irc-handler + queue-and-start-irc-agenda!)) ;;; Network stuff @@ -189,7 +214,7 @@ (newline))))) handle-line) -(define (make-simple-irc-handler handle-line username) +(define (make-basic-irc-handler handle-line username) (let ((buffer '())) (define (reset-buffer) (set! buffer '())) @@ -209,10 +234,11 @@ (_ #f)))) irc-handler)) + (define* (queue-and-start-irc-agenda! agenda socket #:key (username "syncbot") (inet-port default-irc-port) - (handler (make-simple-irc-handler + (handler (make-basic-irc-handler (lambda args (apply (make-handle-line) args)) username)) @@ -244,23 +270,28 @@ (channels (value #t)) (listen))) -(define (main args) - (let* ((options (getopt-long args option-spec)) - (hostname (option-ref options 'server #f)) - (port (or (option-ref options 'port #f) - default-irc-port)) - (username (option-ref options 'username #f)) - (listen (option-ref options 'listen #f)) - (channels (option-ref options 'channels "")) - (agenda (make-agenda))) - (display `((server ,hostname) (port ,port) (username ,username) - (listen ,listen) (channels-split ,(string-split channels #\space)))) - (newline) - (if listen - (spawn-and-queue-repl-server! agenda)) - (queue-and-start-irc-agenda! - agenda - (irc-socket-setup hostname port) - #:inet-port port - #:username username - #:channels (string-split channels #\space)))) +(define* (make-irc-bot-cli) + (define (main args) + (let* ((options (getopt-long args option-spec)) + (hostname (option-ref options 'server #f)) + (port (or (option-ref options 'port #f) + default-irc-port)) + (username (option-ref options 'username #f)) + (listen (option-ref options 'listen #f)) + (channels (option-ref options 'channels "")) + (agenda (make-agenda))) + (display `((server ,hostname) (port ,port) (username ,username) + (listen ,listen) (channels-split ,(string-split channels #\space)))) + (newline) + (if listen + (spawn-and-queue-repl-server! agenda)) + (queue-and-start-irc-agenda! + agenda + (irc-socket-setup hostname port) + #:inet-port port + #:username username + #:channels (string-split channels #\space)))) + main) + +(define main (make-irc-bot-cli)) + -- 2.31.1 From 075e98771e55ff073873ffb5e7ca3b2d158ac25a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 16:10:54 -0600 Subject: [PATCH 11/16] easier passing in of line handler things --- eightsync/systems/irc.scm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/eightsync/systems/irc.scm b/eightsync/systems/irc.scm index a802167..bf450b9 100755 --- a/eightsync/systems/irc.scm +++ b/eightsync/systems/irc.scm @@ -234,19 +234,22 @@ (_ #f)))) 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) - (handler (make-basic-irc-handler - (lambda args - (apply (make-handle-line) args)) - username)) + (line-handler default-line-handler) (channels '())) (dynamic-wind (lambda () #f) (lambda () - (enq! (agenda-queue agenda) (wrap (install-socket socket handler))) + (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)) @@ -270,7 +273,7 @@ (channels (value #t)) (listen))) -(define* (make-irc-bot-cli) +(define* (make-irc-bot-cli #:optional (line-handler default-line-handler)) (define (main args) (let* ((options (getopt-long args option-spec)) (hostname (option-ref options 'server #f)) @@ -290,7 +293,8 @@ (irc-socket-setup hostname port) #:inet-port port #:username username - #:channels (string-split channels #\space)))) + #:channels (string-split channels #\space) + #:line-handler line-handler))) main) (define main (make-irc-bot-cli)) -- 2.31.1 From 555743be477968b12562c5b6c92000ecfe9556f2 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 16:14:08 -0600 Subject: [PATCH 12/16] Provide another indirection procedure with wrap-apply --- eightsync/agenda.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/eightsync/agenda.scm b/eightsync/agenda.scm index adbd0c6..1bfc0a3 100644 --- a/eightsync/agenda.scm +++ b/eightsync/agenda.scm @@ -61,7 +61,7 @@ port-request-port port-request-read port-request-write port-request-except - run-it wrap run run-at run-delay + run-it wrap wrap-apply run run-at run-delay %port-request %run %run-at %run-delay 8port-request 8run 8run-at 8run-delay @@ -382,6 +382,12 @@ Will produce (0 . 0) instead of a negative number, if needed." (lambda () body ...)) +(define-syntax-rule (wrap-apply body) + "Wrap possibly multi-value function in a procedure, applies all arguments" + (lambda args + (apply body args))) + + ;; @@: Do we really want `body ...' here? ;; what about just `body'? (define-syntax-rule (run body ...) -- 2.31.1 From 39fce509440e467188270625bf728b1c57ef9e26 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 16:45:36 -0600 Subject: [PATCH 13/16] Make IRC bot easier to add commands to --- demos/ircbot.scm | 34 ++++++++++++++++++++++++++-------- eightsync/systems/irc.scm | 5 +++-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/demos/ircbot.scm b/demos/ircbot.scm index eec40fa..0aef0d5 100755 --- a/demos/ircbot.scm +++ b/demos/ircbot.scm @@ -19,15 +19,33 @@ ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA ;; 02110-1301 USA -(use-modules (eightsync systems irc)) +(use-modules (eightsync systems irc) + (eightsync agenda) + (ice-9 match)) (define (handle-message socket my-name speaker - channel-name message is-action) - (if is-action - (format #t "~a emoted ~s in channel ~a\n" - speaker message channel-name) - (format #t "~a said ~s in channel ~a\n" - speaker message channel-name))) + channel message is-action) + (define (looks-like-me? str) + (or (equal? str my-name) + (equal? str (string-concatenate (list my-name ":"))))) + (match (string-split message #\space) + (((? looks-like-me? _) action action-args ...) + (match action + ("botsnack" + (irc-format socket "PRIVMSG ~a :Yippie! *does a dance!*" channel)) + ;; Add yours here + (_ + (irc-format socket "PRIVMSG ~a :*stupid puppy look*" channel)))) + (_ + (cond + (is-action + (format #t "~a emoted ~s in channel ~a\n" + speaker message channel)) + (else + (format #t "~a said ~s in channel ~a\n" + speaker message channel)))))) (define main - (make-irc-bot-cli)) + (make-irc-bot-cli (make-handle-line + #:handle-privmsg (wrap-apply handle-message)))) + diff --git a/eightsync/systems/irc.scm b/eightsync/systems/irc.scm index bf450b9..ac9c4e6 100755 --- a/eightsync/systems/irc.scm +++ b/eightsync/systems/irc.scm @@ -187,7 +187,7 @@ (string-join (cons first-word rest-message) " ") #f))))) -(define (echo-back-message my-name speaker +(define (echo-back-message socket my-name speaker channel-name message is-action) (if is-action (format #t "~a emoted ~s in channel ~a\n" @@ -208,7 +208,8 @@ (receive (channel-name message is-action) (condense-privmsg-line (irc-line-params parsed-line)) (let ((username (irc-line-username parsed-line))) - (handle-privmsg my-username username channel-name message is-action)))) + (handle-privmsg socket my-username username + channel-name message is-action)))) (_ (display line) (newline))))) -- 2.31.1 From eb3a40ba452273bd48a356c9b2f4a7de87274309 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 16:45:53 -0600 Subject: [PATCH 14/16] ignore install-sh --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c266424..8ec6974 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ Makefile.in /pre-inst-env /missing test-driver -tests/*.trs \ No newline at end of file +tests/*.trs +install-sh -- 2.31.1 From 4e0dd1c6881754498c144f50db4158d4bff4b782 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 17:03:41 -0600 Subject: [PATCH 15/16] removing whitespace --- demos/ircbot.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demos/ircbot.scm b/demos/ircbot.scm index 0aef0d5..202c18c 100755 --- a/demos/ircbot.scm +++ b/demos/ircbot.scm @@ -36,8 +36,8 @@ ;; Add yours here (_ (irc-format socket "PRIVMSG ~a :*stupid puppy look*" channel)))) - (_ - (cond + (_ + (cond (is-action (format #t "~a emoted ~s in channel ~a\n" speaker message channel)) -- 2.31.1 From c40bd9445cac7467b3844b5cdc03f1b14feb99cd Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Tue, 24 Nov 2015 10:14:42 -0600 Subject: [PATCH 16/16] Ah right, add repl.scm --- Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.am b/Makefile.am index 0317500..f1ccbc3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,6 +46,7 @@ godir=$(libdir)/guile/2.0/ccache SOURCES = \ eightsync/agenda.scm \ + eightsync/repl.scm \ eightsync/systems/irc.scm -- 2.31.1