diff options
author | Boutade <thegoofist@protonmail.com> | 2019-09-25 10:25:22 -0500 |
---|---|---|
committer | Boutade <thegoofist@protonmail.com> | 2019-09-25 10:25:22 -0500 |
commit | 53b2725935447b3a57e0c3381155f5a0fbf395f8 (patch) | |
tree | f3b32bc23974bbf3c2a76aa4f9b29a094f954b66 /granolin.lisp | |
parent | 6618943207bfad3947e0029637e5fe71d7cbd3d8 (diff) |
added basic logging example
Diffstat (limited to 'granolin.lisp')
-rw-r--r-- | granolin.lisp | 27 |
1 files changed, 20 insertions, 7 deletions
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)) + |