From 8f71a1c0f6ddc9e295d929480503222c6baf9e4e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 23 Nov 2015 16:01:36 -0600 Subject: [PATCH 1/1] 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