summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/shell-echo-bot.lisp10
-rw-r--r--granolin.asd3
-rw-r--r--granolin.lisp27
-rw-r--r--package.lisp7
-rw-r--r--utility-apps.lisp17
5 files changed, 49 insertions, 15 deletions
diff --git a/examples/shell-echo-bot.lisp b/examples/shell-echo-bot.lisp
new file mode 100644
index 0000000..f7bca56
--- /dev/null
+++ b/examples/shell-echo-bot.lisp
@@ -0,0 +1,10 @@
+
+(defclass shell-echo-bot (granolin:client granolin::message-log) ())
+
+(defvar *bot* (make-instance 'shell-echo-bot
+ :homeserver "https://matrix.hrlo.world"
+ :output *standard-output*))
+
+
+
+
diff --git a/granolin.asd b/granolin.asd
index bdeac36..5e24104 100644
--- a/granolin.asd
+++ b/granolin.asd
@@ -8,4 +8,5 @@
:serial t
:depends-on (#:drakma #:jonathan)
:components ((:file "package")
- (:file "granolin")))
+ (:file "granolin")
+ (:file "utility-apps")))
diff --git a/granolin.lisp b/granolin.lisp
index 74afa7a..f486e43 100644
--- a/granolin.lisp
+++ b/granolin.lisp
@@ -22,6 +22,9 @@
:initarg :homeserver
:initform (error "HOMESERVER is required.")
:type string)
+ (running-p
+ :accessor running-p
+ :initform t)
(timeout
:accessor timeout
:initarg :timeout
@@ -172,15 +175,15 @@
`(multiple-value-bind
(*response-body* *response-status* *response-headers*)
- (drakma:http-request (make-matrix-url ,client ,path)
+ (drakma:http-request (make-matrix-path ,client ,path)
:additional-headers (add-auth-header ,client ,headers)
:method ,method
- :body (jonathan:to-json ,body)
+ :content (jonathan:to-json ,body)
:content-type "application/json")
(if (= 200 *response-status*)
(let ((*response-object*
(,wrap
- :data (jonathan:parse *response-body*))))
+ :data (jonathan:parse (flexi-streams:octets-to-string *response-body*)))))
,on-ok)
,otherwise)))
@@ -199,14 +202,14 @@
run."
`(multiple-value-bind
(*response-body* *response-status* *response-headers*)
- (drakma:http-request (make-matrix-url ,client ,path)
+ (drakma:http-request (make-matrix-path ,client ,path)
:additional-headers (add-auth-header ,client ,headers)
:parameters ,params
:method :get)
(if (= 200 *response-status*)
(let ((*response-object*
(,wrap
- :data (jonathan:parse *response-body*))))
+ :data (jonathan:parse (flexi-streams:octets-to-string *response-body*)))))
,on-ok)
,otherwise)))
@@ -249,13 +252,13 @@
"
(let (params)
(push (cons "full_state" full-state) params)
- (push (cons "timeout" (timeout client)) params)
+ (push (cons "timeout" (format nil "~a" (timeout client))) params)
(when (next-batch client)
(push (cons "since" (next-batch client)) params))
(fetch (client +sync-path+ :params params :wrap make-sync-response)
(handle-sync-response client)
- (error "Matrix returned ~a from ~a~"
+ (error "Matrix returned ~a from ~a"
*response-status* +sync-path+))))
(defun handle-sync-response (client)
@@ -285,3 +288,13 @@
(handle-invitation-event client room-id invite-event)))))
+;;; bot loop
+
+(defun start (client)
+ (setf (running-p client) t)
+ (loop :while (running-p client)
+ :do (sync client)))
+
+(defun stop (client)
+ (setf (running-p client) nil))
+
diff --git a/package.lisp b/package.lisp
index 7872d84..634fc57 100644
--- a/package.lisp
+++ b/package.lisp
@@ -26,11 +26,4 @@
#:login
#:sync
-
-
-
-
-
-
-
))
diff --git a/utility-apps.lisp b/utility-apps.lisp
new file mode 100644
index 0000000..4f4b2db
--- /dev/null
+++ b/utility-apps.lisp
@@ -0,0 +1,17 @@
+(in-package :granolin)
+
+(defclass message-log ()
+ ((output
+ :accessor output
+ :initarg :output
+ :initform (error "Message Log requires an output stream")
+ :type stream
+ :documentation "An output stream to which messages are logged."
+ )))
+
+(defmethod handle-timeline-event :after ((log message-log) room (event timeline-event))
+ (format (output log) "~a in ~a: ~a~%"
+ (sender event)
+ room
+ (msg-body event)))
+