;; DONE: direct message ;; `ggxx hi ;; Guest [to ggxx]: hi ;; DONE: whisper ;; whisper "hi" to ggxx ;; Guest whispers, "hi" ;; DONE: Emily special message ;; Emily says to ggxx, "Please give the kitchen a few moments to prepare your order." ;; DONE: page ;; page ggxx with "text" ;; You sense that Guest is looking for you in Sushi Paradise. ;; It pages, "text" ;; (this one comes in two successive lines) ;; To handle this, I would want a stateful agent off to the side that receives messages. ;; However, for now, I'll ignore the text. ;; TODO: generic mention ;; Any line of text that matches a string of interest. (require 'notifications) ;; This is usually just your own username. (defvar my/rmoo-users '("ggxx") "List of users to look for to trigger notifications.") (defvar my/rmoo-valid-user '(*? (or alphanumeric "_")) "This is a pattern that matches lambdamoo user names.") (defvar my/rmoo-notify-patterns `((;;Direct Message ,(rx (group (eval my/rmoo-valid-user)) " [to " (group (eval my/rmoo-valid-user)) "]: ") . ,(lambda (line) (if-let* ((from (match-string 1 line)) (to (match-string 2 line)) (msg (string-replace (match-string 0 line) "" line)) (_ (member to my/rmoo-users))) (notifications-notify :app-name "rmoo.el" :title (match-string 0 line) :body (string-replace (match-string 0 line) "" line))))) (;;Whisper ,(rx (group (eval my/rmoo-valid-user)) " whispers, " (group (* anychar) line-end)) . ,(lambda (line) (if-let* ((from (match-string 1 line)) (msg (match-string 2 line))) (notifications-notify :app-name "rmoo.el" :title (format "(%s whispers...)" from) :body msg)) )) (;;Page ,(rx "You sense that " (group (eval my/rmoo-valid-user)) " is looking for you in " (group (* anychar) line-end)) . ,(lambda (line) (notifications-notify :app-name "rmoo.el" :title "Paging..." :body line))) (;;Emily ,(rx "Emily says to " (group (eval my/rmoo-valid-user)) ", " (group (* anychar) line-end)) . ,(lambda (line) (if-let* ((to (match-string 1 line)) (msg (match-string 2 line)) (_ (member to my/rmoo-users))) (notifications-notify :app-name "rmoo.el" :title "Emily says," :body msg))))) "This is an alist where the keys are regexps and values are lambdas.") (defun my/rmoo-notify () "Match patterns and perform actions." (if-let* ((raw-line (thing-at-point 'line t)) (line (string-replace "\n" "" line))) (cl-loop for p in my/rmoo-notify-patterns do (let* ((pattern (car p)) (handler (cdr p))) (if (string-match pattern line) (funcall handler line)))))) ;; Usage: ;; (load "rmoo-notifications.v2.el" t) ;; (setq my/rmoo-users '("ggxx")) ;; (add-hook 'rmoo-handle-text-hooks #'my/rmoo-notify)