1
0
Fork 0

Compare commits

...

8 Commits

10 changed files with 145 additions and 191 deletions

3
.gitignore vendored
View File

@ -27,6 +27,7 @@
/build-aux/texinfo.tex
/config.status
/configure
/configure.ac
/doc/*.1
/doc/.dirstamp
/doc/contributing.*.texi
@ -50,6 +51,7 @@
/doc/version-*.texi
/m4/*
/pre-inst-env
/pre-inst-env.in
/test-env
/test-tmp
/tests/*.trs
@ -57,6 +59,7 @@ GPATH
GRTAGS
GTAGS
Makefile
Makefile.am
Makefile.in
config.cache
stamp-h[0-9]

View File

@ -1,93 +0,0 @@
bin_SCRIPTS = scripts/listen \
scripts/say \
scripts/listen
nodist_noinst_SCRIPTS = pre-inst-env
GOBJECTS = $(SOURCES:%.scm=%.go)
moddir=$(prefix)/share/guile/site/$(GUILE_EFFECTIVE_VERSION)
godir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache
ccachedir=$(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache
nobase_dist_mod_DATA = $(SOURCES) $(NOCOMP_SOURCES)
nobase_go_DATA = $(GOBJECTS)
# Make sure source files are installed first, so that the mtime of
# installed compiled files is greater than that of installed source
# files. See
# <http://lists.gnu.org/archive/html/guile-devel/2010-07/msg00125.html>
# for details.
guile_install_go_files = install-nobase_goDATA
$(guile_install_go_files): install-nobase_dist_modDATA
GUILE_WARNINGS = -Wunbound-variable -Warity-mismatch -Wformat
SUFFIXES = .scm .go
.scm.go:
$(AM_V_GEN)$(top_builddir)/pre-inst-env $(GUILE_TOOLS) compile $(GUILE_TARGET) $(GUILE_WARNINGS) -o "$@" "$<"
SOURCES = bugafriend.scm \
bugafriend/utils/registry.go \
bugafriend/utils/registry.scm \
bugafriend/hconfig.scm \
bugafriend/hconfig.go \
bugafriend/listener.go \
bugafriend/listener.scm \
bugafriend/ui.go \
bugafriend/ui.scm
TESTS =
TEST_EXTENSIONS = .scm
SCM_LOG_DRIVER = \
$(top_builddir)/pre-inst-env \
$(GUILE) --no-auto-compile -e main \
$(top_srcdir)/build-aux/test-driver.scm
# Tell 'build-aux/test-driver.scm' to display only source file names,
# not indivdual test names.
AM_SCM_LOG_DRIVER_FLAGS = --brief=yes
AM_SCM_LOG_FLAGS = --no-auto-compile -L "$(top_srcdir)"
AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)"
info_TEXINFOS = doc/version.texi \
doc/bugafriend.texi
EXTRA_DIST = README.org \
README \
HACKING \
COPYING \
doc/.dirstamp \
doc/stamp-vti \
doc/bugafriend.info \
NEWS \
AUTHORS \
ChangeLog \
guix.scm \
.gitignore \
hall.scm \
build-aux/texinfo.tex \
build-aux/test-driver.scm \
build-aux/missing \
build-aux/install-sh \
build-aux/mdate-sh \
configure.ac \
Makefile.am \
pre-inst-env.in \
build-aux/test-driver.scm \
$(TESTS)
ACLOCAL_AMFLAGS = -I m4
AM_DISTCHECK_DVI_TARGET = info # Disable DVI as part of distcheck
clean-go:
-$(RM) $(GOBJECTS)
.PHONY: clean-go
CLEANFILES = \
$(BUILT_SOURCES) \
$(GOBJECTS) \
$(TESTS:tests/%.scm=%.log)

33
bugafriend/room.scm Normal file
View File

@ -0,0 +1,33 @@
(define-module (bugafriend room)
#:use-module (goblins)
#:use-module (goblins actor-lib pubsub)
#:use-module (goblins actor-lib methods)
#:export (^room ^room-presence))
(define (^room bcom creator-presence)
"The creator owns the canonical room which publishes to subscribers."
(define pubsub (spawn ^pubsub creator-presence))
(methods
[(add-user presence)
($ pubsub 'subscribe presence)
($ pubsub 'publish 'join presence)]
[(kick-user presence)
($ pubsub 'unsubscribe presence)
($ pubsub 'publish 'leave presence)]
[(say presence message)
($ pubsub 'publish 'say presence message)]
[(me presence message)
($ pubsub 'publish 'me presence message)]))
(define (^room-presence bcom name)
"Each user has a presence in the room"
(methods
[(name) name]
[(join user)
(format #t "~a joined." user)]
[(leave user)
(format #t "~a left." user)]
[(say user message)
(format #t "~a: ~a\n" user message)]
[(me user message)
(format #t "* ~a ~a\n" user message)]))

View File

@ -1,5 +1,7 @@
(define-module (bugafriend ui)
#:use-module (bugafriend utils registry)
#:use-module (bugafriend user)
#:use-module (bugafriend room)
#:use-module (goblins)
#:use-module (goblins vat)
#:use-module (goblins ocapn ids)
@ -15,15 +17,15 @@
#:use-module (ice-9 suspendable-ports)
#:export (say))
;; ;; https://www.gnu.org/software/guile/manual/guile.html#Non_002dBlocking-I_002fO
;; (let* ((input (current-input-port))
;; (flags (fcntl input F_GETFL)))
;; (fcntl input F_SETFL (logior O_NONBLOCK flags)))
;; (install-suspendable-ports!)
;; https://www.gnu.org/software/guile/manual/guile.html#Non_002dBlocking-I_002fO
(let* ((input (current-input-port))
(flags (fcntl input F_GETFL)))
(fcntl input F_SETFL (logior O_NONBLOCK flags)))
(install-suspendable-ports!)
(define ocapn-registry #f)
(define listener-actor #f)
(define user-actor #f)
(define (is-command? str)
(and (> (string-length str) 0) (eq? (string-ref str 0) #\/)))
@ -35,6 +37,9 @@
(help console-command-help)
(thunk console-command-thunk))
(define (get-a-room)
($ user-actor 'room-data))
(define commands
(list
(make-console-command
@ -47,25 +52,39 @@
(λ (args)
(print-help)
(loop! #t)))
(make-console-command
"/create"
"- Create a new chat and join it."
(λ (args)
($ user-actor 'make-room)
(loop! #t)))
(make-console-command
"/me"
"<text> - Me command, you like roleplay or whatever"
(λ (args)
(let* ((room-data (get-a-room))
(room (room-data-room room-data))
(presence (room-data-presence room-data)))
;; eww, maybe fix mangling the input by joining
(<- room 'me presence (string-join args " "))
(loop! #t))))
(make-console-command
"/join"
"<listener-id> - Switch chats to another listener"
"<room-id> - Switch chats to another room"
(λ (args)
(unless (eq? 2 (length args))
(error "Need one argument, the listener sturdyref!"))
(error "Need one argument, the room sturdyref!"))
(let* ((listener-id (list-ref args 1))
(listener-sref (string->ocapn-id listener-id)))
(unless listener-sref
(let* ((room-id (list-ref args 1))
(room-sref (string->ocapn-id room-id)))
(unless room-sref
(error "Badly formatted sturdyref!"))
(unless ocapn-registry
(error "Relay not yet connected."))
(format #t "Connecting...\n")
(on (<- ocapn-registry 'enliven listener-sref)
(λ (l)
(set! listener-actor l)
(format #t "Joined chat.\n")
(on (<- ocapn-registry 'enliven room-sref)
(λ (r)
($ user-actor 'join-room r)
(loop! #t))
#:catch
(λ (e)
@ -103,24 +122,32 @@
((eq? 0 (string-length line)) (loop! #t))
((is-command? line)
(%eval-command line))
(else (if listener-actor
(on (<- listener-actor line) (λ (val) (loop! val)))
(begin
(format #t "Not connected to anyone yet. Use /join <sturdyref>!\n")
(loop! #t))))))))
(else
(let ((room-data (get-a-room)))
(if room-data
(let ((room (room-data-room room-data))
(presence (room-data-presence room-data)))
(format #t "Presence: ~s\n" presence)
(on (<- room 'say presence line)
(λ (val) (loop! val))))
(begin
(format #t "Not connected to anyone yet. Use /join <sturdyref>!\n")
(loop! #t)))))))))
#:unwind? #t))
(define (say setup-sref)
(define (say setup-sref name)
(define vat (spawn-vat #:name "Speaker Vat"))
(set-readline-prompt! " 🐞 > ")
(with-vat vat
(with-vat
vat
(format #t "Connecting to relay...\n")
(on (prelay-sref->mycapn-registry setup-sref)
(λ (r)
(set! ocapn-registry r)
(format #t "Connected.\n")
(format #t "Connected. Creating user actor.\n")
(set! user-actor (spawn ^user name ocapn-registry #f))
(loop! #t))
#:catch
(λ (e)

49
bugafriend/user.scm Normal file
View File

@ -0,0 +1,49 @@
(define-module (bugafriend user)
#:use-module (bugafriend utils registry)
#:use-module (bugafriend room)
#:use-module (goblins)
#:use-module (goblins ocapn ids)
#:use-module (goblins actor-lib methods)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:export (^user
make-room-data
room-data?
room-data-room
room-data-presence))
(define-record-type <room-data>
(make-room-data room presence)
room-data?
(room room-data-room)
(presence room-data-presence))
(define (^user bcom name registry joined-room-data)
(methods
[(room-data) joined-room-data]
[(make-room)
(let* ((my-presence (spawn ^room-presence name))
(room (spawn ^room my-presence))
(room-data (make-room-data room my-presence)))
(on (<- registry 'register room)
(λ (id)
(format #t "New room ID: ~a\n" (ocapn-id->string id))))
(bcom (^user bcom name registry room-data)))]
[(join-room room)
(format #t "Connecting...\n")
(let ((my-presence (spawn ^room-presence name)))
(when joined-room-data
(<-np (room-data-room joined-room-data) 'kick-user (room-data-presence joined-room-data)))
(on (<- room 'add-user my-presence)
(λ (_)
(format #t "Joined room.\n")))
(define room-data (make-room-data room my-presence))
(bcom (^user bcom name registry room-data)))]
[(leave-room room)
(when (eq? room (room-data-room joined-room-data))
(<-np room 'kick-user (room-data-presence joined-room-data))
(bcom (^user bcom name registry #f)))]))

View File

@ -1,41 +0,0 @@
dnl -*- Autoconf -*-
AC_INIT(bugafriend, 0.1)
AC_SUBST(HVERSION, "\"0.1\"")
AC_SUBST(AUTHOR, "\"Vivi Langdon\"")
AC_SUBST(COPYRIGHT, "'(2024)")
AC_SUBST(LICENSE, gpl3+)
AC_CONFIG_SRCDIR(bugafriend.scm)
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([1.12 gnu silent-rules subdir-objects color-tests parallel-tests -Woverride -Wno-portability])
AM_SILENT_RULES([yes])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env])
AC_CONFIG_FILES([scripts/say],[chmod +x scripts/say])
AC_CONFIG_FILES([scripts/listen],[chmod +x scripts/listen])
dnl Search for 'guile' and 'guild'. This macro defines
dnl 'GUILE_EFFECTIVE_VERSION'.
GUILE_PKG([3.0 2.2 2.0])
GUILE_PROGS
GUILE_SITE_DIR
if test "x$GUILD" = "x"; then
AC_MSG_ERROR(['guild' binary not found; please check your guile-2.x installation.])
fi
if test "$cross_compiling" != no; then
GUILE_TARGET="--target=$host_alias"
AC_SUBST([GUILE_TARGET])
fi
dnl Hall auto-generated guile-module dependencies
GUILE_MODULE_REQUIRED([goblins])
GUILE_MODULE_REQUIRED([ncurses curses])
dnl Installation directories for .scm and .go files.
guilemoduledir="${datarootdir}/guile/site/$GUILE_EFFECTIVE_VERSION"
guileobjectdir="${libdir}/guile/$GUILE_EFFECTIVE_VERSION/site-ccache"
AC_SUBST([guilemoduledir])
AC_SUBST([guileobjectdir])
AC_OUTPUT

View File

@ -12,7 +12,6 @@
(dependencies
`(("guile-goblins" (goblins) ,guile-goblins)
("guile-ncurses" (ncurses curses) ,guile-ncurses)))
(skip ())
(features
((guix #f)
(use-guix-specs-for-dependencies #f)
@ -24,19 +23,18 @@
"bugafriend"
((directory
"utils"
((compiled-scheme-file "registry")
(scheme-file "registry")))
((scheme-file "registry")))
(scheme-file "user")
(scheme-file "room")
(scheme-file "hconfig")
(compiled-scheme-file "hconfig")
(compiled-scheme-file "listener")
(scheme-file "listener")
(compiled-scheme-file "ui")
(scheme-file "ui")))))
(tests ((directory "tests" ())))
(programs
((directory
"scripts"
((text-file "listen")
((text-file "say")
(text-file "listen")
(in-file "say")
(in-file "listen")))))
(documentation
@ -50,6 +48,7 @@
(text-file ".dirstamp")
(text-file "stamp-vti")
(info-file "bugafriend")
(info-file "version")
(texi-file "bugafriend")))
(text-file "NEWS")
(text-file "AUTHORS")
@ -57,14 +56,4 @@
(infrastructure
((scheme-file "guix")
(text-file ".gitignore")
(scheme-file "hall")
(directory
"build-aux"
((tex-file "texinfo")
(scheme-file "test-driver")
(text-file "missing")
(text-file "install-sh")
(text-file "mdate-sh")))
(autoconf-file "configure")
(automake-file "Makefile")
(in-file "pre-inst-env")))))
(scheme-file "hall")))))

View File

@ -1,13 +0,0 @@
#!/bin/sh
abs_top_srcdir="`cd "@abs_top_srcdir@" > /dev/null; pwd`"
abs_top_builddir="`cd "@abs_top_builddir@" > /dev/null; pwd`"
GUILE_LOAD_COMPILED_PATH="$abs_top_builddir${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH"
GUILE_LOAD_PATH="$abs_top_builddir:$abs_top_srcdir${GUILE_LOAD_PATH:+:}:$GUILE_LOAD_PATH"
export GUILE_LOAD_COMPILED_PATH GUILE_LOAD_PATH
PATH="$abs_top_builddir/scripts:$PATH"
export PATH
exec "$@"

View File

@ -8,4 +8,4 @@
(fibers conditions)
(bugafriend ui))
(say (string->ocapn-id (list-ref (command-line) 1)))
(say (string->ocapn-id (list-ref (command-line) 1)) (list-ref (command-line) 2))

View File

@ -8,4 +8,4 @@
(fibers conditions)
(bugafriend ui))
(say (string->ocapn-id (list-ref (command-line) 1)))
(say (string->ocapn-id (list-ref (command-line) 1)) (list-ref (command-line) 2))