diff options
author | Boutade <thegoofist@protonmail.com> | 2019-09-26 20:35:11 -0500 |
---|---|---|
committer | Boutade <thegoofist@protonmail.com> | 2019-09-26 20:35:11 -0500 |
commit | db1d26d76fc1946512469774afdce1d8e4ee28d5 (patch) | |
tree | b01633f4af7c3faf6c5b9c9465cd2098a9a04a38 | |
parent | 2bef1cf67a681cc34748b6e71df9fa813cee7a20 (diff) |
send-text-message given format args, contact query utils added
-rw-r--r-- | granolin.lisp | 9 | ||||
-rw-r--r-- | utility-apps.lisp | 17 |
2 files changed, 23 insertions, 3 deletions
diff --git a/granolin.lisp b/granolin.lisp index cff0970..8ff860a 100644 --- a/granolin.lisp +++ b/granolin.lisp @@ -412,6 +412,7 @@ (setf (room-state-event-data *state-event*) ob) (handle-event client room-id *state-event*)))) + (defun process-invited-room-events (client) (let ((invite-event (make-invitation-event :data nil))) (loop :for (room-id room . ignore) :on (invited-rooms *response-object*) :by #'cddr :do @@ -421,11 +422,12 @@ (handle-event client room-id invite-event))))) -(defun send-text-message (client room-id message) - "Sends the MESSAGE (a string) to the room with id ROOM-ID." +(defun send-text-message (client room-id message &rest args) + "Sends the MESSAGE (a string) to the room with id ROOM-ID. MESSAGE can also be + a format string, and ARGS is " (let ((url (format nil +text-message-path+ room-id (txn-id client))) (body (list :|msgtype| "m.text" - :|body| message))) + :|body| (apply #'format (list* nil message args))))) (send (client url body :wrap make-basic-json) t))) @@ -440,6 +442,7 @@ *response-status* (flexi-streams:octets-to-string *response-body*))))) + ;;; bot loop (defun start (client) diff --git a/utility-apps.lisp b/utility-apps.lisp index c9789bf..ec52773 100644 --- a/utility-apps.lisp +++ b/utility-apps.lisp @@ -115,6 +115,23 @@ (and like (search name (room-name room) :test #'string-equal))) :collect (if full room (room-id room))))) +(defun client-contacts (client) + "Returns a list of all users this client knows about." + (let (contacts) + (loop :for room :being :the :hash-values :of (directory-table client) :do + (dolist (user (room-members room)) + (pushnew user contacts :test #'equal))) + contacts)) + +(defun find-contact (client name &key like) + "Finds a specific matrix ID by name. If LIKE is NIL, returns a string equal to + NAME if this client has a contact with that NAME, or NIL otherwise. If LIKE + is not NIL returns the first matrix ID found that contains NAME as a + substring, or NIL if no such matrix ID is found." + (find-if (lambda (contact) + (or (equal name contact) + (and like (search name contact :test #'string-equal)))) + (client-contacts client))) ;;; Basic Joiner Bot |